[interprocess] Memory deallocation doesn't seem to work

Hi there, I seem to get a strange behavior with 1.40 on windows concerning deallocation. Basically, I have a managed shared memory segment and I allocate several blocks of mem in it typedef boost::interprocess::managed_windows_shared_memory shared_segment; typedef boost::shared_ptr<shared_segment> shared_segment_ptr; ... shared_segment_ptr p = new shared_segment(create_only, buffername.c_str(), begin_size); ... Now I have several allocate_aligned operations: ptr = m_segment->allocate_aligned(static_cast<size_t>(rawsize), 128); Now after a while the segment will have no more room for further blocks. So I delete some of them to gain more room: m_segment->deallocate(raw.get()); (raw is an interprocess::offset_ptr) I debugged into this and there's indeed deallocation functionality called but when I try to allocate afterwards... ptr = m_segment->allocate_aligned(static_cast<size_t>(rawsize), 128); ... I get an interprocess::bad_alloc This makes me believe that either deallocate didn't do a good job or I have to do something after the deallocate() to really make it happen. I looked into the docs for this but there was nothing mentioned so I suppose deallocate() should suffice. I think fragmentation is not really a problem here. We're talking about a few >1MB blocks in a 30MB segment. Plus some administrative overhead. Any ideas what's going on here? Cheers, Stephan

Just an update On Wed, Sep 23, 2009 at 3:43 PM, Stephan Menzel <stephan.menzel@gmail.com> wrote:
ptr = m_segment->allocate_aligned(static_cast<size_t>(rawsize), 128);
Now after a while the segment will have no more room for further blocks. So I delete some of them to gain more room:
m_segment->deallocate(raw.get()); ...
This makes me believe that either deallocate didn't do a good job...
Actually it just turned out this is the case. I tried among many other things replacing the allocate_aligned() with an ordinary allocate() and this works. So I'm afraid this looks a lot like a bug in interprocess to me. Pointers returned by allocate_aligned are aligned but cannot be deallocated. At least not in a way that would have the mem actually available afterwards. HTH, Stephan

Stephan Menzel escribió:
Just an update
On Wed, Sep 23, 2009 at 3:43 PM, Stephan Menzel <stephan.menzel@gmail.com> wrote:
ptr = m_segment->allocate_aligned(static_cast<size_t>(rawsize), 128);
Now after a while the segment will have no more room for further blocks. So I delete some of them to gain more room:
m_segment->deallocate(raw.get()); ...
This makes me believe that either deallocate didn't do a good job...
Actually it just turned out this is the case. I tried among many other things replacing the allocate_aligned() with an ordinary allocate() and this works. So I'm afraid this looks a lot like a bug in interprocess to me. Pointers returned by allocate_aligned are aligned but cannot be deallocated. At least not in a way that would have the mem actually available afterwards.
Can you give me a use case to reproduce the problem? This seems to work in may windows machine: #include <vector> #include <boost/interprocess/managed_windows_shared_memory.hpp> int main() { using namespace boost::interprocess; typedef boost::interprocess:: managed_windows_shared_memory shared_segment; std::vector<void *> ptrs; shared_segment m_segment(create_only, "shmem", 4096*16); try{ while(1){ //Now I have several allocate_aligned operations: ptrs.push_back(m_segment.allocate_aligned(128, 128)); } } catch(...){ m_segment.deallocate(ptrs.back()); ptrs.pop_back(); ptrs.push_back(m_segment.allocate_aligned(128, 128)); } return 0; } Ion

2009/9/23 Ion Gaztañaga <igaztanaga@gmail.com>:
Can you give me a use case to reproduce the problem? This seems to work in may windows machine:
Hi Ion, I just tried to create a standalone test case but I failed. A simple test program such as yours does the job and yet my complex scenario still shows the faulty behaviour. I don't know what to make of it but since it works with non-aligned version and I failed to reproduce it on a smaller scale I'd say forget about it. It's only windows after all and who knows what's going on inside? For the real performance critical stuff I don't have to reallocate mem so one allocate_aligned() will remain inside the segment but the additional blocks don't really need to be aligned. Thanks for looking into it though. Maybe I can dig out additional information later on. Cazart, Stephan
participants (2)
-
Ion Gaztañaga
-
Stephan Menzel