Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 620468
Collapse All | Expand All

(-)a/boost/pool/pool.hpp.old (-9 / +25 lines)
Lines 26-31 Link Here
26
26
27
#include <boost/pool/poolfwd.hpp>
27
#include <boost/pool/poolfwd.hpp>
28
28
29
// std::numeric_limits
30
#include <boost/limits.hpp>
29
// boost::integer::static_lcm
31
// boost::integer::static_lcm
30
#include <boost/integer/common_factor_ct.hpp>
32
#include <boost/integer/common_factor_ct.hpp>
31
// boost::simple_segregated_storage
33
// boost::simple_segregated_storage
Lines 355-360 class pool: protected simple_segregated_storage < typename UserAllocator::size_t Link Here
355
      return s;
357
      return s;
356
    }
358
    }
357
359
360
    size_type max_chunks() const
361
    { //! Calculated maximum number of memory chunks that can be allocated in a single call by this Pool.
362
      size_type partition_size = alloc_size();
363
      size_type POD_size = integer::static_lcm<sizeof(size_type), sizeof(void *)>::value + sizeof(size_type);
364
      size_type max_chunks = (std::numeric_limits<size_type>::max() - POD_size) / alloc_size();
365
366
      return max_chunks;
367
    }
368
358
    static void * & nextof(void * const ptr)
369
    static void * & nextof(void * const ptr)
359
    { //! \returns Pointer dereferenced.
370
    { //! \returns Pointer dereferenced.
360
      //! (Provided and used for the sake of code readability :)
371
      //! (Provided and used for the sake of code readability :)
Lines 375-380 class pool: protected simple_segregated_storage < typename UserAllocator::size_t Link Here
375
      //!   the first time that object needs to allocate system memory.
386
      //!   the first time that object needs to allocate system memory.
376
      //!   The default is 32. This parameter may not be 0.
387
      //!   The default is 32. This parameter may not be 0.
377
      //! \param nmax_size is the maximum number of chunks to allocate in one block.
388
      //! \param nmax_size is the maximum number of chunks to allocate in one block.
389
      set_next_size(nnext_size);
390
      set_max_size(nmax_size);
378
    }
391
    }
379
392
380
    ~pool()
393
    ~pool()
Lines 398-405 class pool: protected simple_segregated_storage < typename UserAllocator::size_t Link Here
398
    }
411
    }
399
    void set_next_size(const size_type nnext_size)
412
    void set_next_size(const size_type nnext_size)
400
    { //! Set number of chunks to request from the system the next time that object needs to allocate system memory. This value should never be set to 0.
413
    { //! Set number of chunks to request from the system the next time that object needs to allocate system memory. This value should never be set to 0.
401
      //! \returns nnext_size.
414
      BOOST_USING_STD_MIN();
402
      next_size = start_size = nnext_size;
415
      next_size = start_size = min BOOST_PREVENT_MACRO_SUBSTITUTION(nnext_size, max_chunks());
403
    }
416
    }
404
    size_type get_max_size() const
417
    size_type get_max_size() const
405
    { //! \returns max_size.
418
    { //! \returns max_size.
Lines 407-413 class pool: protected simple_segregated_storage < typename UserAllocator::size_t Link Here
407
    }
420
    }
408
    void set_max_size(const size_type nmax_size)
421
    void set_max_size(const size_type nmax_size)
409
    { //! Set max_size.
422
    { //! Set max_size.
410
      max_size = nmax_size;
423
      BOOST_USING_STD_MIN();
424
      max_size = min BOOST_PREVENT_MACRO_SUBSTITUTION(nmax_size, max_chunks());
411
    }
425
    }
412
    size_type get_requested_size() const
426
    size_type get_requested_size() const
413
    { //!   \returns the requested size passed into the constructor.
427
    { //!   \returns the requested size passed into the constructor.
Lines 708-716 void * pool<UserAllocator>::malloc_need_resize() Link Here
708
722
709
  BOOST_USING_STD_MIN();
723
  BOOST_USING_STD_MIN();
710
  if(!max_size)
724
  if(!max_size)
711
    next_size <<= 1;
725
    set_next_size(next_size << 1);
712
  else if( next_size*partition_size/requested_size < max_size)
726
  else if( next_size*partition_size/requested_size < max_size)
713
    next_size = min BOOST_PREVENT_MACRO_SUBSTITUTION(next_size << 1, max_size*requested_size/ partition_size);
727
    set_next_size(min BOOST_PREVENT_MACRO_SUBSTITUTION(next_size << 1, max_size * requested_size / partition_size));
714
728
715
  //  initialize it,
729
  //  initialize it,
716
  store().add_block(node.begin(), node.element_size(), partition_size);
730
  store().add_block(node.begin(), node.element_size(), partition_size);
Lines 748-756 void * pool<UserAllocator>::ordered_malloc_need_resize() Link Here
748
762
749
  BOOST_USING_STD_MIN();
763
  BOOST_USING_STD_MIN();
750
  if(!max_size)
764
  if(!max_size)
751
    next_size <<= 1;
765
    set_next_size(next_size << 1);
752
  else if( next_size*partition_size/requested_size < max_size)
766
  else if( next_size*partition_size/requested_size < max_size)
753
    next_size = min BOOST_PREVENT_MACRO_SUBSTITUTION(next_size << 1, max_size*requested_size/ partition_size);
767
    set_next_size(min BOOST_PREVENT_MACRO_SUBSTITUTION(next_size << 1, max_size * requested_size / partition_size));
754
768
755
  //  initialize it,
769
  //  initialize it,
756
  //  (we can use "add_block" here because we know that
770
  //  (we can use "add_block" here because we know that
Lines 792-797 void * pool<UserAllocator>::ordered_malloc(const size_type n) Link Here
792
{ //! Gets address of a chunk n, allocating new memory if not already available.
806
{ //! Gets address of a chunk n, allocating new memory if not already available.
793
  //! \returns Address of chunk n if allocated ok.
807
  //! \returns Address of chunk n if allocated ok.
794
  //! \returns 0 if not enough memory for n chunks.
808
  //! \returns 0 if not enough memory for n chunks.
809
  if (n > max_chunks())
810
    return 0;
795
811
796
  const size_type partition_size = alloc_size();
812
  const size_type partition_size = alloc_size();
797
  const size_type total_req_size = n * requested_size;
813
  const size_type total_req_size = n * requested_size;
Lines 840-848 void * pool<UserAllocator>::ordered_malloc(const size_type n) Link Here
840
856
841
  BOOST_USING_STD_MIN();
857
  BOOST_USING_STD_MIN();
842
  if(!max_size)
858
  if(!max_size)
843
    next_size <<= 1;
859
    set_next_size(next_size << 1);
844
  else if( next_size*partition_size/requested_size < max_size)
860
  else if( next_size*partition_size/requested_size < max_size)
845
    next_size = min BOOST_PREVENT_MACRO_SUBSTITUTION(next_size << 1, max_size*requested_size/ partition_size);
861
    set_next_size(min BOOST_PREVENT_MACRO_SUBSTITUTION(next_size << 1, max_size * requested_size / partition_size));
846
862
847
  //  insert it into the list,
863
  //  insert it into the list,
848
  //   handle border case.
864
  //   handle border case.

Return to bug 620468