5 ms·
It really depends on the application. I just use the default system allocator until it's inadequate for some task, and then I switch to an allocation scheme or
by jey 17y ago
It really depends on the application. I just use the default system allocator until it's inadequate for some task, and then I switch to an allocation scheme or heap allocator that's well-suited for that problem.
Can you tell us more about your specific problem? Then we'd be able to give suggestions and help evaluate the options.
- leif 17y agoThe current issue is that we allocate and free small structures very, very rapidly. They have very short lifespan, and there are never (in the average case) more than a few around at any one time. After profiling, we saw lots of time spent in malloc, and wrote a fixed-size-slab bitfield-based allocator which gave fantastic performance. There are some other issues with the same piece of code that need re-working, and we'll end up with a totally different approach by the end, so I don't really have a problem that needs a crowd solution; I was just curious what everyone here thinks.
- huhtenberg 17y agoIf it's a fixed-size slab, why bother with the bitfield ? It is hard to beat the performance of allocating a block from a free (double-linked) list. Start with an empty list and full slab. Try allocating from the list first, and from the bottom of the slab second. Free into the free list only. If you memory utilization is stable in a long run, then at some point you will be allocating/freeing from the list only.