title: Boost::Mutex & Malloc
body: <p>I'm trying to use a faster memory allocator in C++.  I can't use Hoard due to licensing / cost.  I was using NEDMalloc in a single threaded setting and got excellent performance, but I'm wondering if I should switch to something else -- as I understand things, NEDMalloc is just a replacement for C-based malloc() &amp; free(), <strong>not</strong> the C++-based new &amp; delete operators (which I use extensively).</p>
  
  <p>The problem is that I now need to be thread-safe, so I'm trying to malloc an object which is reference counted (to prevent excess copying), but which also contains a mutex pointer.  That way, if you're about to delete the last copy, you first need to lock the pointer, then free the object, and lastly unlock &amp; free the mutex.</p>
  
  <p>However, using malloc to create a boost::mutex appears impossible because I can't initialize the private object as calling the constructor directly ist verboten.</p>
  
  <p>So I'm left with this odd situation, where I'm using new to allocate the lock and nedmalloc to allocate everything else.  But when I allocate a large amount of memory, I run into allocation errors (which disappear when I switch to malloc instead of nedmalloc ~ but the performance is terrible).  My guess is that this is due to fragmentation in the memory and an inability of nedmalloc and new to place nice side by side.</p>
  
  <p>There has to be a better solution.  What would you suggest?</p>