could anyone please give me a "plug-in" malloc AND

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
earlz

could anyone please give me a "plug-in" malloc AND

Post by earlz »

I have tried at least 14 times to make a malloc and have looked at other code but it is very confusing

I got a page allocator so no worries there(that seems to be what everyone leads me to) just i can not figure out how to make a malloc with a free
durand
Member
Member
Posts: 193
Joined: Wed Dec 21, 2005 12:00 am
Location: South Africa
Contact:

Re:could anyone please give me a "plug-in" malloc

Post by durand »

You could always have a look at mine: http://www.djm.co.za/liballoc/

It's good enough to run firefox, openoffice, etc...and you just need to implement 4 functions and it will work in your system.
paulbarker

Re:could anyone please give me a "plug-in" malloc

Post by paulbarker »

There are hundreds of these things. For my kernel, kalloc() and kfree() are wrappers around bget. Other systems you might try are Doug Lea's malloc (dlmalloc) and the allocator in PDCLib. Take a look around, decide which one suits you best rather than jumping on the first.
earlz

Re:could anyone please give me a "plug-in" malloc

Post by earlz »

@durand
I haven't got it all implemented yet but your malloc and stuff seems to be very good thanks so much

edit:
liballoc works great! thanks again durand
plus thanks to using it i have discovered a big problem in my page allocator when allocating multiple pages >:( but anyway workign on getting that fixed now
durand
Member
Member
Posts: 193
Joined: Wed Dec 21, 2005 12:00 am
Location: South Africa
Contact:

Re:could anyone please give me a "plug-in" malloc

Post by durand »

Good! I haven't had any feedback previously about liballoc but I hope it was easy to implement, clear and stuff. I've tried to make it so...
earlz

Re:could anyone please give me a "plug-in" malloc

Post by earlz »

yes very easy to implement
Warrior

Re:could anyone please give me a "plug-in" malloc

Post by Warrior »

Wow that's a pretty looking allocator, I'll try to implement it into my OS tomorrow. I'll post results. (Although don't know what good they'll be, not like I have a firefox just lying around in my OS)
mystran

Re:could anyone please give me a "plug-in" malloc

Post by mystran »

Durand: your liballoc page says you don't know why people want 4 byte aligned allocations?

Well, they want that because it gives you 2 bits in each pointer for all kinds of h4x0ring (like dynamic typing), and because 4 byte aligned pointers are faster anyway. There are probably a few more reasons that I forgot.
durand
Member
Member
Posts: 193
Joined: Wed Dec 21, 2005 12:00 am
Location: South Africa
Contact:

Re:could anyone please give me a "plug-in" malloc

Post by durand »

Thanks, Mystran. I had to search the gtk source code to find out that it required aligned memory. It just seemed a little odd to me because running an application based on gtk then required a malloc/free implementation that knew to return aligned pointers and I wasn't aware that the standard ones generally did...
mystran

Re:could anyone please give me a "plug-in" malloc

Post by mystran »

Actually, malloc aligning to only 4 bytes can be a pain. You take hit on performance if your doubles aren't aligned to 8 bytes. But that's not even bad. You need to use special unaligned moves if you load SSE registers from unaligned locations, and the alignment requirement is 16 bytes. Guess what? The unaligned move is so slow that you actually lose most of the benefits of SSE.

Technically, I believe malloc is supposed to return "suitably aligned" pointers, and whether or not you consider performance hits to be unsuitable, is a matter of opinion.

Ofcourse most of the time one relies on certain alignment, one should use something like posix_memalign instead. But malloc() exists everywhere...
mystran

Re:could anyone please give me a "plug-in" malloc

Post by mystran »

btw, posix_memalign() manual on my Linux box says:

Code: Select all

       GNU libc malloc() always returns 8-byte aligned memory addresses, so these
       routines are only needed if you require larger alignment values.
Post Reply