Page 1 of 1
Malloc()
Posted: Mon Jun 02, 2003 11:00 pm
by pamplemouse
can anybody tell me how to rewrite malloc() free() realloc() so I can use them in a kernel?
RE:Malloc()
Posted: Tue Jun 03, 2003 11:00 pm
by ka3r
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.
RE:Malloc()
Posted: Thu Jun 12, 2003 11:00 pm
by gaffi
There are some very usefull documents on Bonafide OS development.
http://osdev.neopages.net/tutorials.php (Memory Management)
Hope this helps,
Daniel Raffler