Question About Memory | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Question About Memory

Will a block of code that is multiple lines but syntactically the same as a block of code with less lines, take up more memory? Are you using whitespace when moving to a new line? I'm guessing if there is a difference in memory, it is probably negligible. I am genuinely curious about this and would like to learn more about computer memory. Could anyone suggest some good resources? Thank you.

10th May 2020, 12:21 AM
Ian Stewart
Ian Stewart - avatar
9 Answers
+ 8
In c++, and many other langs, whitespaces and new lines mainly serve for aesthetic purposes and won't have any memory impact at runtime (are ignored during compiling time). Whitespaces are usually removed from Javascript files before delivering to decrease their size. It's due to the fact that .js files are plain text files that occupy space on user storage(and to decrease download time), it has nothing to do with the memory used by the program itself at runtime. Always use withespaces/tabs/newlines to increase code readability and make it easier to debug.
10th May 2020, 1:29 AM
Kevin ★
+ 5
This may help you in your studies Ian Stewart though you will want to Google and read further on the subject. Thanks and happy coding https://www.tutorialspoint.com/computer_fundamentals/computer_memory.htm
10th May 2020, 12:39 AM
BroFar
BroFar - avatar
+ 3
Thank you, BroFar and Kevin Star!
10th May 2020, 11:47 PM
Ian Stewart
Ian Stewart - avatar
+ 3
use the @ and a name window opens then click on desired name Ian Stewart
10th May 2020, 11:50 PM
BroFar
BroFar - avatar
+ 2
Awesome! Thank you BroFar!
10th May 2020, 11:51 PM
Ian Stewart
Ian Stewart - avatar
+ 2
Interesting question. Fortunately, compilers aren't that gullible. They compile they same assembly code, regardless of the whitespace, because the syntax remains the same. It will probably compile a microsecond or so slower, but the executable file will be identical, so it will run at the same speed.
11th May 2020, 5:02 AM
SapphireBlue
SapphireBlue - avatar
+ 1
welcome Ian Stewart
10th May 2020, 11:48 PM
BroFar
BroFar - avatar
+ 1
How do I mention you?
10th May 2020, 11:49 PM
Ian Stewart
Ian Stewart - avatar
+ 1
Makes sense, Raphi Spoerri . Thanks!
25th May 2020, 6:05 AM
Ian Stewart
Ian Stewart - avatar