Is OS Wasting Memory? Quick Experiment Results

  • Thread starter Thread starter waht
  • Start date Start date
  • Tags Tags
    Memory Os
AI Thread Summary
A user conducted an experiment compiling a simple "Hello World" program in C++ with the gcc compiler, noting that the source code is only 100 bytes while the resulting executable is 9.6 KB. Upon examining the executable in hex format, a significant portion—almost a kilobyte—consists of zeros. The user speculates that this may indicate a delay or unused bits, suggesting that the zero-filled section could represent the data segment of the program, which typically allocates a 1K block by default. They express uncertainty about whether gcc can be configured to reduce memory usage and recommend checking the gcc documentation for potential options.
waht
Messages
1,499
Reaction score
4
I did a quick experiment. First I compiled a simple hello world program in C++ , using a gcc compiler. The source code is 100 bytes, but the executable file it 9.6 kb.

Then I dumbed the executable into hex using xxd, to check up on the 0s and 1s. It turns out there is a huge gap, almost a kilobyte long of zeros.

I'm wondering if this is some sort of delay, or just unused bits?
 
Technology news on Phys.org
I'm guessing that the section with 0s is the data segment of your program, and that unless you specify otherwise, it will allocate a 1K block for it. I don't have any experience with gcc, so don't know if you can configure it to use less memory. Check the docs for gcc.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...
Back
Top