the stack

Started by
7 comments, last by Monder 17 years, 9 months ago
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?
"Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction."
Advertisement
I don't know, but I don't think you need more than 4,294,967,296 addresses :)
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?
Get Windows/Linux x64 and the pointer should be 64bits (I think).
That's what makes it a 32-bit architecture; the computer works best with 32-bit values.
2 + 2 = 5 for extremely large values of 2
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?
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.
Thanks!
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.

This topic is closed to new replies.

Advertisement