0

I came cross these sentences today:

When you write your code, you might end up with a chunk of code that is no longer used but still part of the program. Watch out for cases like these: remember that every line of code involves some work by the CPU and oftentimes a read or write to memory.

And I wonder what the construction "involves some work by the CPU and oftentimes a read or write to memory" means. Which of the following would you say is closer in meaning to it?

a) Every line of code involves some work by the CPU. And oftentimes, every line of code involves a read or write to memory.

b) Every line of code involves some work by the CPU. And oftentimes, the work involved is a read or write to memory.

I am confused because, theoretically, accessing memory is indeed one of the jobs of a CPU.

4
  • 1
    First of all, if the code does not get used, it does not "involve work from the CPU", or a "read/write to memory" unless you're talking about the absolutely minuscule additional effort of loading the code as part of the program.
    – Hellion
    Dec 16, 2017 at 6:25
  • 2
    To your question, however: For All lines of code, CPU work is involved, AND for "many" lines of code (a sizeable percentage), there is also a read or write to memory.
    – Hellion
    Dec 16, 2017 at 6:27
  • If your Question belongs here, you need to provide suggested solutions for each option, and ask which seems best. That might still be unacceptable but without that much, there is nothing. Dec 17, 2017 at 0:04
  • @Hellion only for script, for most compiled code much of the dead code wouldn't have been compiled at all.
    – Jon Hanna
    Feb 18, 2018 at 23:30

2 Answers 2

1

Intepretation (B) is correct from both a language and computer science perspective.

Linguistically, the sentence as quoted implies that every line of code involves some CPU work, and some of said CPU work may involve a read or write to computer memory.

While it may be confusing at first, the author's sentence implies Option (B) while being correctly succinct.

From a computer science perspective, in general the system memory for the computer is indeed managed by the CPU. It's rare for non-CPU elements of the computer to access the memory, though it can happen. Also, the reading and writing to memory may not only happen while that line of code is executed but also creates memory and other overhead when being compiled, etc.

0

Of the two options you've given, (b) is closer but not quite right. But "And oftentimes, every line of code..." doesn't really make sense. Either every line of code involves a read or write, or it doesn't.

However, a line of code that is not used will take time for the CPU to execute. It may also require reading or writing memory, but not if the CPU is using data held in cache and/or registers.

So I would propose:-

c) Every line of code involves some work by the CPU. And the work involved may require a read or write to memory.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.