///////////////////////////////////////////////////////////////////////////////
//
-// (C) Copyright Ion Gaztanaga 2005-2011. Distributed under the Boost
+// (C) Copyright Ion Gaztanaga 2005-2012. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BOOST_INTERPROCESS_ALLOCATOR_HPP
#define BOOST_INTERPROCESS_ALLOCATOR_HPP
-#if (defined _MSC_VER) && (_MSC_VER >= 1200)
+#if defined(_MSC_VER)
# pragma once
#endif
typedef SegmentManager segment_manager;
typedef typename SegmentManager::void_pointer void_pointer;
- /// @cond
+ #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
private:
//Self type
//Pointer to the allocator
alloc_ptr_t mp_mngr;
- /// @endcond
+ #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
public:
typedef T value_type;
typedef boost::interprocess::version_type<allocator, 2> version;
- /// @cond
+ #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
//Experimental. Don't use.
typedef boost::container::container_detail::transform_multiallocation_chain
<typename SegmentManager::multiallocation_chain, T>multiallocation_chain;
- /// @endcond
+ #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
//!Obtains an allocator that allocates
//!objects of type T2
template<class T2>
struct rebind
- {
+ {
typedef allocator<T2, SegmentManager> other;
};
pointer allocate(size_type count, cvoid_ptr hint = 0)
{
(void)hint;
- if(count > this->max_size())
+ if(size_overflows<sizeof(T)>(count)){
throw bad_alloc();
+ }
return pointer(static_cast<value_type*>(mp_mngr->allocate(count*sizeof(T))));
}
//!pointed by p can hold. This size only works for memory allocated with
//!allocate, allocation_command and allocate_many.
size_type size(const pointer &p) const
- {
+ {
return (size_type)mp_mngr->size(ipcdetail::to_raw_pointer(p))/sizeof(T);
}
//!preferred_elements. The number of actually allocated elements is
//!will be assigned to received_size. The elements must be deallocated
//!with deallocate(...)
- multiallocation_chain allocate_many
- (size_type elem_size, size_type num_elements)
+ void allocate_many(size_type elem_size, size_type num_elements, multiallocation_chain &chain)
{
- return multiallocation_chain(mp_mngr->allocate_many(sizeof(T)*elem_size, num_elements));
+ if(size_overflows<sizeof(T)>(elem_size)){
+ throw bad_alloc();
+ }
+ mp_mngr->allocate_many(elem_size*sizeof(T), num_elements, chain);
}
//!Allocates n_elements elements, each one of size elem_sizes[i]in a
//!contiguous block
//!of memory. The elements must be deallocated
- multiallocation_chain allocate_many
- (const size_type *elem_sizes, size_type n_elements)
+ void allocate_many(const size_type *elem_sizes, size_type n_elements, multiallocation_chain &chain)
{
- multiallocation_chain(mp_mngr->allocate_many(elem_sizes, n_elements, sizeof(T)));
+ mp_mngr->allocate_many(elem_sizes, n_elements, sizeof(T), chain);
}
//!Allocates many elements of size elem_size in a contiguous block
//!preferred_elements. The number of actually allocated elements is
//!will be assigned to received_size. The elements must be deallocated
//!with deallocate(...)
- void deallocate_many(multiallocation_chain chain)
- {
- return mp_mngr->deallocate_many(chain.extract_multiallocation_chain());
- }
+ void deallocate_many(multiallocation_chain &chain)
+ { mp_mngr->deallocate_many(chain); }
//!Allocates just one object. Memory allocated with this function
//!must be deallocated only with deallocate_one().
//!preferred_elements. The number of actually allocated elements is
//!will be assigned to received_size. Memory allocated with this function
//!must be deallocated only with deallocate_one().
- multiallocation_chain allocate_individual
- (size_type num_elements)
- { return this->allocate_many(1, num_elements); }
+ void allocate_individual(size_type num_elements, multiallocation_chain &chain)
+ { this->allocate_many(1, num_elements, chain); }
//!Deallocates memory previously allocated with allocate_one().
//!You should never use deallocate_one to deallocate memory allocated
//!preferred_elements. The number of actually allocated elements is
//!will be assigned to received_size. Memory allocated with this function
//!must be deallocated only with deallocate_one().
- void deallocate_individual(multiallocation_chain chain)
- { return this->deallocate_many(boost::move(chain)); }
+ void deallocate_individual(multiallocation_chain &chain)
+ { this->deallocate_many(chain); }
//!Returns address of mutable object.
//!Never throws
} //namespace interprocess {
-/// @cond
+#if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
template<class T>
struct has_trivial_destructor;
{
static const bool value = true;
};
-/// @endcond
+#endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
} //namespace boost {