Heap

From OSDev.wiki
Jump to navigation Jump to search
This page is a stub.
You can help the wiki by accurately adding more contents to it.

Heap

A heap is a vital component of both application programs and the kernel. It is also generally superseded by a higher level of memory management that deals with larger chunks of memory. For most operating systems memory will be allocated based on pages or other large chunks. A page on the X86 and X64 architectures is generally 4KB, but can be larger. However, for smaller allocations the entire page would be wasted. For example if you only needed 24 bytes and you allocate an entire 4KB page you will have wasted a lot of memory. So most applications and kernels will implemented a second memory management scheme that uses memory allocated in 4KB chunks (or larger) and break these strips of pages or individual pages into smaller parts as they are requested.

Standard Library, Applications, And Kernel

Applications in most operating systems have their own heap implementation as a part of the standard library and do not use the implementation that the kernel uses. So therefore not only is the heap for the kernel separate from the heap of each application, but it may very well use a different heap implementation. Also, this allows each application to use it's own implementation depending on which standard library is was built against or with. However, there is no reason why a kernel could not provide heap services directly to applications. It must be noted too that there is no way to enforce an application to use a specific heap or implementation because a clever programmer could simply use the memory allocated to supply it's own implementation.

If you are looking for information about designing a memory system in regard to paging or handing out larger chunks of memory (such as 4KB) and aligned on a large boundaries then this is not the correct page. Try looking at Memory Management.

Tutorials/Implementations/Articles

Page Brief Description
Simple Heap Implementation A simple, portable, and fairly efficient memory wise implementation.
Writing A Heap Implementation It's not that hard to implement a basic first fit MM... (continued).