Page 1 of 1

kernel malloc()

Posted: Wed May 05, 2004 9:41 am
by srg
Hi

I'm looking for a plugin malloc() to use in my kernel (rather than reinvent the wheel myself) and found the Doug Lea's malloc.

I've read through the documentation and the Comments at the start but it looks really daunting. What sort of modifications will I need to make to it to use it for my kernel?

Also, are there any other alternatives that are ok, or is the dlmalloc the best one to use?

The other things that i've noticed are that it uses stdio.h. Surely, as we have no library, this can't work, or do we have to write these routines ourselves.

Otherwise, what algorithms could I use if I have to write the malloc myself?

thanks
srg

Re:kernel malloc()

Posted: Wed May 05, 2004 10:16 am
by Pype.Clicker
according to ftp://g.oswego.edu/pub/misc/malloc.c, stdio is required only to display statistics. If you don't need those statistics, i'd say you could easily remove all those stdio things.

The code will also appear a *lot* clearer if you ask your preprocessor to wipe out all those STDC or WIN32 conditional blocks ...

Re:kernel malloc()

Posted: Wed May 05, 2004 10:34 am
by Cemre
i have a better one...
doesn't use any outside resource...

Re:kernel malloc()

Posted: Wed May 05, 2004 10:40 am
by Cemre
sorry... ;D
it does use an outside resource "yield()"
just replace
while ( tsl(...) ) yield()
with
while ( tsl (...) ) /* empty */ ;

Re:kernel malloc()

Posted: Wed May 05, 2004 11:25 am
by Neuromancer
Also, are there any other alternatives that are ok, or is the dlmalloc the best one to use?
I have ported dlmalloc to the core of my OS and it is very good, very fast and optimizes the memory usage by itself.
The porting process is very easy.

Re:kernel malloc()

Posted: Wed May 05, 2004 11:31 am
by srg
Pype.Clicker wrote:
The code will also appear a *lot* clearer if you ask your preprocessor to wipe out all those STDC or WIN32 conditional blocks ...
ooh, er, how do I do that?

srg

Re:kernel malloc()

Posted: Wed May 05, 2004 11:49 am
by Neuromancer
Here's a easy-to-port dlmalloc.

I have changed the malloc/free names to mm_alloc/mm_free but you can easily turn them to their default names.

Re:kernel malloc()

Posted: Wed May 05, 2004 12:07 pm
by srg
Neur0m'ancer wrote: Here's a easy-to-port dlmalloc.

I have changed the malloc/free names to mm_alloc/mm_free but you can easily turn them to their default names.
Thanks very much! :D

srg

Re:kernel malloc()

Posted: Wed May 05, 2004 5:17 pm
by seraph9
Here is an alternative (by Michael J. Haertel) to dlmalloc that I use,

http://www.pell.portland.or.us/~orc/Cod ... oc-930716/

All you need to do is provide certain headers for types and hook a morecore function.

Vivek