7

I'm currently attempting to write a 2D scene graph in C, and I need to decide on a way of storing the child nodes. I'm expecting very many reads and few writes, so a linked list is out of the question due to poor spatial locality of reference, and using realloc every time to add a child node would probably fragment the free list into oblivion. A pool allocator seems to be the best solution, but I can't seem to find any implementations to use. Does anyone know of an allocator that would efficiently handle random-ish allocations and deallocations of a few hundred small structs, or perhaps a better allocation scheme?

2 Answers 2

4

I'm preparing to deploy TLSF as a real-time allocator. I haven't had a chance to profile its performance yet, but it seems to work, and the license is right.

According to their docs, its operations execute "a maximum of 168 processor instructions in a x86 architecture". It comes as a single .c file, which compiled without modifications on my system.

Sign up to request clarification or add additional context in comments.

5 Comments

@CAFxX - Shame. Google finds me some alternate sites, but none seem to be official. Hopefully that will change.
Yay! Thanks for the fix, @Electro . Giving you a semi-random upvote. Chalk another win for crowd-sourced knowledge.
@T.E.D. Well, I do like to go over my own questions once in a while - can't have links rotting away :P
Thanks for the tip. In my informal benchmark, it beats glibc's malloc by 25% or more. But it is slightly slower for free. Unfortunately, it segfaults when you try to make a memory pool 2gb or larger in size.
@BjörnLindqvist - ...which immediately tells me - signed 32-bit integer being used somewhere. Hopefully its fixable. 32-bit systems are essentially obsolete now, except for specialized uses.
2

Take a look at halloc, it might be of some help.

http://swapped.cc/halloc/

1 Comment

halloc looks interesting, but it still works on top of malloc, so the fragmentation issue remains, though I guess it might prove useful as a starting point for a pool allocator.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.