05-23-06 06:17 AM
>It only works on systems with a hardware memory manager that keeps
>track of the memory allocated to a process. On old DOS systems without
>a MMU, a bad program will crash the system.
It also works on Unix(-like) systems without an MMU, e.g. MINIX on 8086
(version1 and version2)
On most systems it works like this (even without MMU)
* A process has three segments
* TEXT for the program code (unchangable)
* DATA for initialized data
* BSS for uninitalized data
On start from an elf or a.out file, these segments are allocated as
needed.
The BSS segment can be growed and shrinked by the sbrk(2) system call.
Library functions like malloc use this call if they need more memory.
Some implementations never shrink the BSS (free keeps a list of
previously allocated memory, subsequent mallocs first consider if
memory in this list can be used, otherwise allocate a big chunk of
additional BSS space)
The OS keeps track of the segments. If a program exits or crashes, it
knows exactly the place and size of these segments and reclaims this
memory.
Hubble.
[ Post a follow-up to this message ]
|