diff --git a/include/boost/interprocess/allocators/allocator.hpp b/include/boost/interprocess/allocators/allocator.hpp index 413a7f6..47fcaad 100644 --- a/include/boost/interprocess/allocators/allocator.hpp +++ b/include/boost/interprocess/allocators/allocator.hpp @@ -161,7 +161,7 @@ class allocator if(size_overflows(count)){ throw bad_alloc(); } - return pointer(static_cast(mp_mngr->allocate(count*sizeof(T)))); + return pointer(static_cast(mp_mngr->allocate_aligned(count*sizeof(T), boost::container::dtl::alignment_of::value))); } //!Deallocates memory previously allocated. @@ -242,7 +242,7 @@ class allocator if(size_overflows(elem_size)){ throw bad_alloc(); } - mp_mngr->allocate_many(elem_size*sizeof(T), num_elements, chain); + mp_mngr->allocate_many(elem_size*sizeof(T), num_elements, boost::container::dtl::alignment_of::value, chain); } //!Allocates n_elements elements, each one of size elem_sizes[i]in a @@ -250,7 +250,7 @@ class allocator //!of memory. The elements must be deallocated void allocate_many(const size_type *elem_sizes, size_type n_elements, multiallocation_chain &chain) { - mp_mngr->allocate_many(elem_sizes, n_elements, sizeof(T), chain); + mp_mngr->allocate_many(elem_sizes, n_elements, sizeof(T), boost::container::dtl::alignment_of::value, chain); } //!Allocates many elements of size elem_size in a contiguous block diff --git a/test/list_test.cpp b/test/list_test.cpp index d4975d6..8ef6af6 100644 --- a/test/list_test.cpp +++ b/test/list_test.cpp @@ -34,14 +34,14 @@ typedef boost::container::list ShmemCopyAllocator; typedef boost::container::list MyCopyList; +typedef allocator ShmemOveralignedAllocator; +typedef boost::container::list MyOveralignedList; + int main () { if(test::list_test()) return 1; -// if(test::list_test()) -// return 1; - if(test::list_test()) return 1; @@ -51,6 +51,9 @@ int main () if(test::list_test()) return 1; + if(test::list_test()) + return 1; + const test::EmplaceOptions Options = (test::EmplaceOptions)(test::EMPLACE_BACK | test::EMPLACE_FRONT | test::EMPLACE_BEFORE); if(!boost::interprocess::test::test_emplace, Options>()) diff --git a/test/list_test.hpp b/test/list_test.hpp index 4e46f4a..a1ddacc 100644 --- a/test/list_test.hpp +++ b/test/list_test.hpp @@ -98,7 +98,7 @@ int list_test (bool copied_allocators_equal = true) { typedef std::list MyStdList; typedef typename MyShmList::value_type IntType; - const int Memsize = 128u * 1024u; + const int Memsize = 256u * 1024u; const char *const shMemName = test::get_process_id_name(); const int max = 100; typedef push_data_function push_data_t; diff --git a/test/movable_int.hpp b/test/movable_int.hpp index 88f16d4..7dc6351 100644 --- a/test/movable_int.hpp +++ b/test/movable_int.hpp @@ -14,6 +14,7 @@ #include #include #include +#include //alignment_of, aligned_storage namespace boost { namespace interprocess { @@ -287,6 +288,84 @@ class non_copymovable_int int m_int; }; + +class overaligned_copyable_int +{ + public: + overaligned_copyable_int() + { + m_d.m_int = 0; + } + + explicit overaligned_copyable_int(int a) + { + m_d.m_int = a; + } + + overaligned_copyable_int(const overaligned_copyable_int& mmi) + { + m_d.m_int = mmi.m_d.m_int; + } + + overaligned_copyable_int & operator= (int i) + { this->m_d.m_int = i; return *this; } + + overaligned_copyable_int & operator=(const overaligned_copyable_int& mmi) + { m_d.m_int = mmi.m_d.m_int; return *this; } + + bool operator ==(const overaligned_copyable_int &mi) const + { return this->m_d.m_int == mi.m_d.m_int; } + + bool operator !=(const overaligned_copyable_int &mi) const + { return this->m_d.m_int != mi.m_d.m_int; } + + bool operator <(const overaligned_copyable_int &mi) const + { return this->m_d.m_int < mi.m_d.m_int; } + + bool operator <=(const overaligned_copyable_int &mi) const + { return this->m_d.m_int <= mi.m_d.m_int; } + + bool operator >=(const overaligned_copyable_int &mi) const + { return this->m_d.m_int >= mi.m_d.m_int; } + + bool operator >(const overaligned_copyable_int &mi) const + { return this->m_d.m_int > mi.m_d.m_int; } + + int get_int() const + { return m_d.m_int; } + + friend bool operator==(const overaligned_copyable_int &l, int r) + { return l.get_int() == r; } + + friend bool operator==(int l, const overaligned_copyable_int &r) + { return l == r.get_int(); } + + private: + + union data + { + boost::container::dtl::aligned_storage::type aligner; + int m_int; + } m_d; +}; + +template +std::basic_ostream & operator<< + (std::basic_ostream & os, overaligned_copyable_int const & p) + +{ + os << p.get_int(); + return os; +} + +template<> +struct is_copyable +{ + static const bool value = true; +}; + + + } //namespace test { } //namespace interprocess { } //namespace boost { diff --git a/test/vector_test.cpp b/test/vector_test.cpp index 7bcf04d..91692aa 100644 --- a/test/vector_test.cpp +++ b/test/vector_test.cpp @@ -72,7 +72,10 @@ int main() typedef allocator ShmemCopyAllocator; typedef boost::container::vector MyCopyVector; - +/* + typedef allocator ShmemOveralignedAllocator; + typedef boost::container::vector MyOveralignedVector; +*/ if(test::vector_test()) return 1; @@ -87,7 +90,10 @@ int main() if(test::vector_test()) return 1; - +/* + if(test::vector_test()) + return 1; +*/ if(test_expand_bwd()) return 1;