kernel malloc()

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
srg

kernel malloc()

Post 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
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:kernel malloc()

Post 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 ...
Cemre

Re:kernel malloc()

Post by Cemre »

i have a better one...
doesn't use any outside resource...
Cemre

Re:kernel malloc()

Post by Cemre »

sorry... ;D
it does use an outside resource "yield()"
just replace
while ( tsl(...) ) yield()
with
while ( tsl (...) ) /* empty */ ;
Neuromancer

Re:kernel malloc()

Post 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.
srg

Re:kernel malloc()

Post 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
Neuromancer

Re:kernel malloc()

Post 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.
srg

Re:kernel malloc()

Post 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
seraph9

Re:kernel malloc()

Post 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
Post Reply