int main() { std::shared_ptr<int> p1(new int(1)); int* r1 = to_raw_pointer(p1); int* p2 = new int(2); int* r2 = to_raw_pointer(p2); }
static size_type shrink_buckets ( bucket_ptr buckets, size_type old_size , allocator_type &alloc, size_type new_size) { if(old_size <= new_size ) return old_size; size_type received_size; if(!alloc.allocation_command (boost::interprocess::try_shrink_in_place | boost::interprocess::nothrow_allocation, old_size, new_size, received_size, buckets).first){ return old_size; } for( bucket_type *p = ipcdetail::to_raw_pointer(buckets) + received_size , *pend = ipcdetail::to_raw_pointer(buckets) + old_size ; p != pend ; ++p){ p->~bucket_type(); } bucket_ptr shunk_p = alloc.allocation_command (boost::interprocess::shrink_in_place | boost::interprocess::nothrow_allocation, received_size, received_size, received_size, buckets).first; BOOST_ASSERT(buckets == shunk_p); (void)shunk_p; bucket_ptr buckets_init = buckets + received_size; for(size_type i = 0; i < (old_size - received_size); ++i){ to_raw_pointer(buckets_init++)->~bucket_type(); } return received_size; }
static bucket_ptr create_buckets(allocator_type &alloc, size_type num) { num = index_type::suggested_upper_bucket_count(num); bucket_ptr buckets = alloc.allocate(num); bucket_ptr buckets_init = buckets; for(size_type i = 0; i < num; ++i){ new(to_raw_pointer(buckets_init++))bucket_type(); } return buckets; }
static bucket_ptr expand_or_create_buckets ( bucket_ptr old_buckets, const size_type old_num , allocator_type &alloc, const size_type new_num) { size_type received_size = new_num; bucket_ptr reuse(old_buckets); bucket_ptr ret = alloc.allocation_command (boost::interprocess::expand_fwd | boost::interprocess::allocate_new, new_num, received_size, reuse); if(ret == old_buckets){ bucket_ptr buckets_init = old_buckets + old_num; for(size_type i = 0; i < (new_num - old_num); ++i){ ::new(to_raw_pointer(buckets_init++), boost_container_new_t())bucket_type(); } } else{ bucket_ptr buckets_init = ret; for(size_type i = 0; i < new_num; ++i){ ::new(to_raw_pointer(buckets_init++), boost_container_new_t())bucket_type(); } } return ret; }
static bucket_ptr expand_or_create_buckets ( bucket_ptr old_buckets, const size_type old_num , allocator_type &alloc, const size_type new_num) { size_type received_size; std::pair<bucket_ptr, bool> ret = alloc.allocation_command (boost::interprocess::expand_fwd | boost::interprocess::allocate_new, new_num, new_num, received_size, old_buckets); if(ret.first == old_buckets){ bucket_ptr buckets_init = old_buckets + old_num; for(size_type i = 0; i < (new_num - old_num); ++i){ new(to_raw_pointer(buckets_init++))bucket_type(); } } else{ bucket_ptr buckets_init = ret.first; for(size_type i = 0; i < new_num; ++i){ new(to_raw_pointer(buckets_init++))bucket_type(); } } return ret.first; }
static void destroy_buckets (allocator_type &alloc, bucket_ptr buckets, size_type num) { bucket_ptr buckets_destroy = buckets; for(size_type i = 0; i < num; ++i){ to_raw_pointer(buckets_destroy++)->~bucket_type(); } alloc.deallocate(buckets, num); }