• Advertisement
Sign in to follow this  

the stack

This topic is 4259 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i find this a little wierd: lets say i create a pointer then assign to an address ,then i try to read the address it's always an eight digit hexadecmial value. with some math max value = 16^8 = (2x2x2x2)^8 = (2^4)^8 = 2^(4x8) = 2^32 , which implies that the size of the pointer is 32bits. my question is: can the stack only hold 2^32 addresses?

Share this post


Link to post
Share on other sites
Advertisement
Yes, in 32-bit hardware the size of pointers is usually 32 bit and they can address up to 4GB in virtual address space. Why is this weird? And what the stack has to do with it?

Share this post


Link to post
Share on other sites
Get Windows/Linux x64 and the pointer should be 64bits (I think).

Share this post


Link to post
Share on other sites
That's what makes it a 32-bit architecture; the computer works best with 32-bit values.

Share this post


Link to post
Share on other sites
Two questsions,

Does this mean that each program has a maximum of ~4gb memeory, or all programs running?

This would also include variables both on the stack, and on the heap, correct?

Share this post


Link to post
Share on other sites
Quote:
Original post by Ezbez
Two questsions,

Does this mean that each program has a maximum of ~4gb memeory, or all programs running?

It means that with a 32 bit pointer your application can address 232 differet memory addresses. It doesn not necesssarily mean that you can use that much memory. How much you can use depends on how much the operating system allows you to use.

Quote:
Original post by Ezbez
This would also include variables both on the stack, and on the heap, correct?

It addresses the memory. Stack, heap, free store, whatever, are all parts of the same memory.

Share this post


Link to post
Share on other sites
Quote:
Does this mean that each program has a maximum of ~4gb memeory, or all programs running?


It means each program has a ~4gb address space. However you can't necessarily access all of that address space, nor does it mean the maximum amount of memory you can use is 4gb (you could for example have the 1st gb of address space refer to one part of memory and then alter it so that it refers to another part of memory). How this all works and what parts of the address space you can access depend upon the OS. Reading this article on virtual memory should give you more info on how a modern OS manages all this.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement