Jump to content
  • Advertisement
Sign in to follow this  
Conoktra

Non-Blocking Memory Allocator

This topic is 2889 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello!

I am looking for a cross-platform, open source, ANSI-C, non-blocking memory allocator. That's pretty specific, but hopefully there is one out there :).

I am looking for this because I have an application that has several threads. Each thread malloc's ~80 MB of memory each cycle for inter-thread communication, and each thread cycles about ~1000 times a second (because the threads cleanup up after each other the memory usage idles around ~150 MB per thread). After profiling my application I noticed one of the slowest things was memory management, because if two threads where allocating or freeing memory at the same time one thread would have to wait for the other too finish before it could continue. It makes sense that this would cause a performance drop, because that ~80MB is composed of thousands of malloc's/free's, and that's done ~1000 times a second per thread.

I could implement one of the several methods for multithreaded memory management solutions (buckets, free lists, etc), but for the sake of time and simplicity, is there a pre-existing non-blocking memory allocator that someone can refer me to?

Thanks!

Share this post


Link to post
Share on other sites
Advertisement
Why don't you just pre-allocate ~200MB per thread and just use placement new to allocate. I guess I'm saying just make your own memory manager, but if each worker thread has it's own pool from which assigned jobs allocate, you don't have to worry about making it thread-safe

Share this post


Link to post
Share on other sites

Why don't you just pre-allocate ~200MB per thread and just use placement new to allocate. I guess I'm saying just make your own memory manager, but if each worker thread has it's own pool from which assigned jobs allocate, you don't have to worry about making it thread-safe

Thank you for your reply Palidine! I am not looking for how to implement a memory manager (as I already know how :P), but for the sake of simplicity and time I am looking for a pre-existing one. Thanks anyways!

Share this post


Link to post
Share on other sites
Intel's TBB has a mostly non-blocking general purpose allocator, but it's C++. But you can still use malloc/free with it.

You can also easily roll your own in Windows by creating a non-serializing heap via HeapCreate for each thread, although that may not have the kind of ideal performance characteristics that you're looking for.

Share this post


Link to post
Share on other sites
You might want to try tcmalloc, which is part of google's perftools. I haven't used it myself, but I've heard that for small allocations in multiple threads it works pretty well.

Share this post


Link to post
Share on other sites

Hello!

I am looking for a cross-platform, open source, ANSI-C, non-blocking memory allocator. That's pretty specific, but hopefully there is one out there :).

I am looking for this because I have an application that has several threads. Each thread malloc's ~80 MB of memory each cycle for inter-thread communication, and each thread cycles about ~1000 times a second (because the threads cleanup up after each other the memory usage idles around ~150 MB per thread). After profiling my application I noticed one of the slowest things was memory management, because if two threads where allocating or freeing memory at the same time one thread would have to wait for the other too finish before it could continue. It makes sense that this would cause a performance drop, because that ~80MB is composed of thousands of malloc's/free's, and that's done ~1000 times a second per thread.

I could implement one of the several methods for multithreaded memory management solutions (buckets, free lists, etc), but for the sake of time and simplicity, is there a pre-existing non-blocking memory allocator that someone can refer me to?

Thanks!


If your program allocates 80MB of memory each loop, per thread then the obvious choice is to reuse the first alloc and do not de alloc it. Then, your problem is solved.

Share this post


Link to post
Share on other sites

If your program allocates 80MB of memory each loop, per thread then the obvious choice is to reuse the first alloc and do not de alloc it. Then, your problem is solved.

It fluctuates around 80 MB, so pre-allocating the memory isn't an option.


Thanks everybody for your replies! I am going to check out each of those but tcmalloc looks the most promising so far. Thanks again! :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!