Files
interprocess/test/data_test.cpp
Ion Gaztañaga 48990c0766 Implemented N1780 proposal to LWG issue 233: Insertion hints in associative containers in interprocess boost::interprocess::multiset and boost::interprocess::multimap class.
Source breaking: A shared memory object is now used including shared_memory_object.hpp header instead of shared memory.hpp.
ABI breaking: Changed global mutex when initializing managed shared memory and memory mapped files. This change tries to minimize deadlocks.
Source breaking: Changed shared memory, memory mapped files and mapped region's open mode to a single boost::interprocess::mode_t type.
Added extra WIN32_LEAN_AND_MEAN before including DateTime headers to avoid socket redefinition errors when using Interprocess and Asio in windows.
ABI breaking: mapped_region constructor no longer requires classes derived from memory_mappable, but classes the fulfill the MemoryMappable concept.
Added in-place reallocation capabilities to basic_string.
ABI breaking: Reimplemented and optimized small string optimization. The narrow string class has zero byte overhead with an internal 11 byte buffer in 32 systems!
Added move semantics to containers. Experimental and not documented yet. Improves performance when using containers of containers.
ABI breaking: End nodes of node containers (list, slist, map/set) are now embedded in the containers instead of allocated using the allocator. This allows no-throw move-constructors and improves performance.
ABI breaking: slist and list containers now have constant-time size() function. The size of the container is added as a member.


[SVN r35618]
2006-10-15 14:07:15 +00:00

100 lines
3.0 KiB
C++

//////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztañaga 2004-2006. 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)
//
// See http://www.boost.org/libs/interprocess for documentation.
//
//////////////////////////////////////////////////////////////////////////////
#include <boost/interprocess/detail/config_begin.hpp>
#include <boost/interprocess/detail/workaround.hpp>
#include <boost/interprocess/allocators/allocator.hpp>
#include <boost/interprocess/managed_shared_memory.hpp>
#include <boost/interprocess/containers/vector.hpp>
#include <boost/interprocess/containers/list.hpp>
#include <iostream>
#include <algorithm>
#include <functional>
#include "print_container.hpp"
using namespace boost::interprocess;
int main ()
{
const int memsize = 65536;
const char *const shMemName = "MySharedMemory";
shared_memory_object::remove(shMemName);
//Create shared memory
managed_shared_memory segment(create_only, shMemName, memsize);
//STL compatible allocator object, uses allocate(), deallocate() functions
typedef allocator<int, managed_shared_memory::segment_manager>
shmem_allocator_int_t;
const shmem_allocator_int_t myallocator (segment.get_segment_manager());
const int max = 100;
void *array[max];
const char *allocName = "testAllocation";
typedef boost::interprocess::vector<int, shmem_allocator_int_t > MyVect;
typedef boost::interprocess::list<int, shmem_allocator_int_t > MyList;
//---- ALLOC, NAMED_ALLOC, NAMED_NEW TEST ----//
{
int i;
//Let's allocate some memory
for(i = 0; i < max; ++i){
array[i] = segment.allocate(i+1);
}
//Deallocate allocated memory
for(i = 0; i < max; ++i){
segment.deallocate(array[i]);
}
bool res;
MyVect *shmem_vect;
//Construct and find
shmem_vect = segment.construct<MyVect> (allocName) (myallocator);
res = (shmem_vect == segment.find<MyVect>(allocName).first);
if(!res)
return 1;
//Destroy and check it is not present
segment.destroy<MyVect> (allocName);
res = (0 == segment.find<MyVect>(allocName).first);
if(!res)
return 1;
//Construct, dump to a file
shmem_vect = segment.construct<MyVect> (allocName) (myallocator);
segment.save_to_file("shmem_file");
/*
//Recreate objects in a new shared memory check object is present
bool created = segment.create_from_file("shmem_file", shMemName);
if(!created)
return 1;
shmem_vect = segment.find<MyVect>(allocName).first;
if(!shmem_vect)
return 1;
//Destroy and check it is not present
segment.destroy<MyVect> (allocName);
res = (0 == segment.find<MyVect>(allocName).first);
if(!res)
return 1;
*/
}
return 0;
}
#include <boost/interprocess/detail/config_end.hpp>