Malloc()
RE:Malloc()
First of all, you must implement a kernel heap: if you reserve 256 MB for example you needn't allocate them, this is the role of the allocator.
You have several ways to code them:
- the easiest way is allocating pages on the heap for every allocation request: it is very fast, but if you allocate 2 bytes, your allocator will allocate 4096, causing a large waste of RAM.
- you can have buckets for every size of allocation (for example, 8 bytes, 16, 32, 64, 128, 256, 512, 1024, and so on) and pick the best fitting memory chunk
Also check out Doug Lea's dlmalloc, a fast and space-efficient heap allocator.
You have several ways to code them:
- the easiest way is allocating pages on the heap for every allocation request: it is very fast, but if you allocate 2 bytes, your allocator will allocate 4096, causing a large waste of RAM.
- you can have buckets for every size of allocation (for example, 8 bytes, 16, 32, 64, 128, 256, 512, 1024, and so on) and pick the best fitting memory chunk
Also check out Doug Lea's dlmalloc, a fast and space-efficient heap allocator.
RE:Malloc()
There are some very usefull documents on Bonafide OS development.
http://osdev.neopages.net/tutorials.php (Memory Management)
Hope this helps,
Daniel Raffler
http://osdev.neopages.net/tutorials.php (Memory Management)
Hope this helps,
Daniel Raffler