What is the range of an address on stack and memory?

On computer memory, say IA32, what is the range of stack in general? I know an address like 0xffff1234 is probably on the stack. Is it possible for the stack to grow to 0x0800abcd, for example? How about the heap? I know the heap address is always lower than the stack address, but what is normally its range? Also what is the area below heap?

The stack - The memory the program uses to actually run the program. This contains local variables, call-back data (for example when you call a function, the stack stores the state and place you were in the code before you entered the new function), and some other little things of that nature. You usually don't control the stack directly, the variables and data are destroyed, created when you move in and out function scopes.

The heap - The "dynamic" memory of the program. Each time you create a new object or variable dynamically, it is stored on the heap. This memory is controlled by the programmer directly, you are supposed to take care of the creation AND deletion of the objects there.

Thanks a lot!


Stack: You can define the size of your stack in linking time. As I know, windows app default stack size is 2MB. You can change the size of stack in your project setting. But when App is built, stack size is fixed. And OS would set guard page for stack overflow. If any operation try to access the guard page would trigger EXCEPTION.

Heap: Default heap size i guess also can be changed in project settings. Because in your App, you can create your own heap, or use CRT heap, Win32 heap. So there should be lots of heaps. When your try to allocate memory, Heap Manager based on algorithm to allocate memory. If there's not enough memory, Heap Manager would apply for memory from Virtual Memory Manager. Until there's not enough memory in User Address Space, throw exception: Out of Memory. There's several definitions: HeapNode, HeapSegment, LFH, LEA, BEA. And you can use Windbg: !heap -s, !heap -a, these commands to check the structure of Windows Heap.

链接地址: http://www.djcxy.com/p/79836.html

上一篇: 为什么使用alloca()不被认为是好的做法?

下一篇: 堆栈和内存上的地址范围是什么?