Memory Allocation: Difference between revisions
Jump to navigation
Jump to search
[unchecked revision] | [unchecked revision] |
Content deleted Content added
information on porting an existing memory allocator |
mentioned fixed size memory allocation →A very very simple Memory Manager |
||
Line 33: | Line 33: | ||
What data structure and algorithms can be used with such lists has been discussed in [http://www.mega-tokyo.com/forum/index.php?board=1;action=display;threadid=6486 Memmaker's] started thread (as well as in many others) |
What data structure and algorithms can be used with such lists has been discussed in [http://www.mega-tokyo.com/forum/index.php?board=1;action=display;threadid=6486 Memmaker's] started thread (as well as in many others) |
||
--> |
--> |
||
==Fixed size allocation== |
|||
Allocating and deallocating fixed sized areas of memory is extremely simple. You can basically treat all free memory as a linked list of nodes. To allocate memory, you remove the front node from the linked list. To free memory, you return the front node to the linked list. This provides a constant allocation/releasing time and there is no fragmentation. |
|||
In the real world, programs like to allocate different sized chunks of memory so it's unlikely you can solely rely on this method. |
|||
However, it is theoretically possible for a microkernel to be designed so that all memory structures are exactly the same size (the Process struct, Thread struct, Message struct, etc). This would be very fast and efficient. |
|||
On this note, most Lisp implementations have a single 'box-and-pointer' base data type. A box-and-pointer type is a pair of values, usually pointer/pointer or atom/pointer (atom means a numeric value). On a 32-bit system, this structure is 8 bytes big. All other data structures (lists, trees, objects, etc) are built on top of this type. As a consequence memory allocation on a Lisp system is very fast. |
|||
==Tips to go further== |
==Tips to go further== |