Wiki page start changed with summary [] by Raster

This commit is contained in:
Carsten Haitzler 2015-06-17 23:03:30 -07:00 committed by apache
parent fca7b6ba65
commit b90686bce9
1 changed files with 1 additions and 1 deletions

View File

@ -495,7 +495,7 @@ Generally you allocate memory with functions such as ''malloc()'', ''calloc()'',
The memory of your process, other than memory used to store the code/instructions loaded from disk, is primarily made up of 2 elements. The [[http://en.wikipedia.org/wiki/Call_stack|stack]] and the [[http://en.wikipedia.org/wiki/Memory_management|heap]]. Your memory space will generally look something as follows, often with the stack high up in memory (at high addresses) and pieces of code from the process and libraries mapped in from disk, as well as heap space being allocated there too. Mappings not explicitly set up are inaccessible, and any access to them causes a crash (often via a SEGFAULT).
{{ memstackheap.svg?nolink |Complete memory space diagram }}
{{ memheapstack.svg?nolink |Complete memory space diagram }}
The stack is managed for you mostly by the compiler and runtime. As the application runs, every time a function is called, a new blob of memory is "pushed" at the "top" of the stack (conceptually stacks grow.. thus the top is where the newest item(s) are on the stack, but often the stack grows down in memory, so to push you subtract values from the top of the stack and to pop, you add again). This memory contains the parameters passed to each function, and will contain return values from the function as well as a return address to go back to (to read instructions from by the CPU) when this function returns. It is a very simple structure, and yet incredibly useful. Note that stack often has limited sizes (sometimes in the order of dozens of KB, maybe only a few MB, but commonly stacks are like 8MB in size). So don't abuse the stack too much. A function like ''alloca()'' can allocate extra memory on the stack (it pushes a segment of N bytes onto the stack that is cleaned up when the function in which it is allocated returns). This is handy if you need some temporary scratch space that is not too big and a fixed size is not known at compile time.