In this exercise I am using Visual Studio 2017 and the std_lib_facilities header provided by Stroustrup.
Chapter 18 // Exercise 9Consider the memory layout in section 17.4. Write a program that tells the order in which static storage, the stack, and the free store are laid out in memory. In which direction does the stack grow: upward toward higher addresses or downward toward lower addresses? In an array on the free store, are elements with higher indices allocated at higher or lower addresses?
So going off Bjarne's description of static, stack and heap I managed to print some global variables and a bunch of locals/new'd values but I'm unsure what to do with the stack? His description says "...It sets aside some memory to be used when you call functions, and they need space for their arguments and local variables". You can print the address of where the function is but I don't think you can print the size of the function? I had a look around and that generally is something that can't be done.
I also couldn't compare the addresses for different functions unless they're identical but the ones included in the program were in places near each other but didn't trend one specific way.
const char*'s and newed up char arrays always grew downwards but newed up double arrays grew upwards.
I'm not convinced I've done this exercise correctly.
No comments:
Post a Comment