Boost logo

Boost :

From: Paul Bormans (pbor1234_at_[hidden])
Date: 2008-08-26 14:44:14


Some time ago i had noticed some strange behavior in the boost pool_allocator regarding its memory usage. Now that i've found these great mailinglists ;) i've reproduced the error and with some additional analysis i can post the thing here.

My environment:
- VS2005
- Windows XP
- Boost 1_34_1 with BOOST_ALL_DYN_LINK set (if it makes a difference)
- Running release build

The test code:

  {
    std::pair<int, int> pairStart(m_spLeakDetection->ReportLeaks(_T("boost test 1a")));
    {
      std::vector<int> v;
      std::pair<int, int> pairInterim2(m_spLeakDetection->ReportLeaks(_T("boost test 1b"))); //0 bytes (only stack memory used)
      for (int i = 0; i < 1000; ++i) { v.push_back(5); }
      std::pair<int, int> pairInterim3(m_spLeakDetection->ReportLeaks(_T("boost test 1c"))); //4264 bytes in 1 block
      v.clear();
    }
    std::pair<int, int> pairInterim4(m_spLeakDetection->ReportLeaks(_T("boost test 1d"))); //0 bytes
  }

  {
    std::pair<int, int> pairStart(m_spLeakDetection->ReportLeaks(_T("boost test 2a")));
    {
      std::vector<int, boost::pool_allocator<int> > v;
      std::pair<int, int> pairInterim2(m_spLeakDetection->ReportLeaks(_T("boost test 2b"))); //0 bytes (only stack memory used)
      for (int i = 0; i < 1000; ++i) { v.push_back(5); }
      std::pair<int, int> pairInterim3(m_spLeakDetection->ReportLeaks(_T("boost test 2c"))); //16312 bytes over 7 blocks; 136, 264, 520, 1032, 2056, 4104, 8200
      v.clear();
    }
    std::pair<int, int> pairInterim4(m_spLeakDetection->ReportLeaks(_T("boost test 2d"))); //still 16312 bytes over 7 blocks
    boost::singleton_pool<boost::pool_allocator_tag, sizeof(int)>::release_memory();
    std::pair<int, int> pairEnd(m_spLeakDetection->ReportLeaks(_T("boost test 2e"))); //8112 over 6 blocks; 136, 264, 520, 1032, 2056, 4104
    {
      std::vector<int, boost::pool_allocator<int> > v;
      for (int i = 0; i < 10; ++i) { v.push_back(5); }
      std::pair<int, int> pairInterim3(m_spLeakDetection->ReportLeaks(_T("boost test 2f"))); //8112 over 6 blocks; 136, 264, 520, 1032, 2056, 4104
      v.clear();
    }
    {
      std::vector<int, boost::pool_allocator<int> > v;
      for (int i = 0; i < 1000; ++i) { v.push_back(5); }
      std::pair<int, int> pairInterim3(m_spLeakDetection->ReportLeaks(_T("boost test 2g"))); //24504 bytes over 7 blocks; 136, 264, 520, 1032, 2056, 4104, 16392
      v.clear();
    }
  }

>From these tests;
- why does the boost::pool_allocator reserve 16312 bytes for 1000 int's while the default stl vector consumes (only) 4264 bytes?
- why does a call to release_memory( ) not remove all the memory allocations done by the pool_allocator? But only the last block?
- why does the size of each new block gets duplicated in size (even after release_memory)?

Does this make sense to any of you?

Best regards,
Paul

_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk