diff --git a/doc/Jamfile.v2 b/doc/Jamfile.v2 index 6eb1d7c..b6c00e5 100644 --- a/doc/Jamfile.v2 +++ b/doc/Jamfile.v2 @@ -25,8 +25,15 @@ doxygen autodoc EXTRACT_ALL=NO HIDE_UNDOC_MEMBERS=YES EXTRACT_PRIVATE=NO + ENABLE_PREPROCESSING=YES EXPAND_ONLY_PREDEF=YES - PREDEFINED=BOOST_INTERPROCESS_DOXYGEN_INVOKED + MACRO_EXPANSION=YES + "PREDEFINED=\"BOOST_INTERPROCESS_DOXYGEN_INVOKED\" \\ + \"BOOST_INTERPROCESS_ENABLE_MOVE_EMULATION(a)= \" \\ + \"BOOST_INTERPROCESS_RV_REF(a)=a &&\" \\ + \"BOOST_INTERPROCESS_RV_REF_2_TEMPL_ARGS(a,b,c)=a &&\" \\ + \"BOOST_INTERPROCESS_RV_REF_3_TEMPL_ARGS(a)=a &&\" \\ + \"BOOST_INTERPROCESS_FWD_REF(a)=a &&\"" "boost.doxygen.reftitle=Boost.Interprocess Reference" ; diff --git a/doc/interprocess.qbk b/doc/interprocess.qbk index c1bdc02..fce5e85 100644 --- a/doc/interprocess.qbk +++ b/doc/interprocess.qbk @@ -94,13 +94,8 @@ You can just allocate a portion of a shared memory segment, copy the message to that buffer, send the offset of that portion of shared memory to another process, and you are done. Let's see the example: -[import ../example/doc_ipc_messageA.cpp] -[doc_ipc_messageA] - -In receiver process one just could write the following lines: - -[import ../example/doc_ipc_messageB.cpp] -[doc_ipc_messageB] +[import ../example/doc_ipc_message.cpp] +[doc_ipc_message] [endsect] @@ -108,15 +103,10 @@ In receiver process one just could write the following lines: You want to create objects in a shared memory segment, giving a string name to them so that any other process can find, use and delete them from the segment when the objects are not -needed anymore. Just write in one process: +needed anymore. Example: -[import ../example/doc_named_allocA.cpp] -[doc_named_allocA] - -In other process execute the following: - -[import ../example/doc_named_allocB.cpp] -[doc_named_allocB] +[import ../example/doc_named_alloc.cpp] +[doc_named_alloc] [endsect] @@ -148,16 +138,19 @@ list, map, so you can avoid these manual data structures just like with standard mapped files. For example, we can construct STL-like containers in shared memory. To do this, we just need to create a special (managed) shared memory segment, declare a [*Boost.Interprocess] allocator and construct the vector in shared memory -just if it was any other object. Just execute this first process: +just if it was any other object. -[import ../example/doc_contA.cpp] -[doc_contA] +The class that allows this complex structures in shared memory is called +[classref boost::interprocess::managed_shared_memory] and it's easy to use. +Just execute this example without arguments: -After this process is executed we can search the constructed vector and use it with -STL algorithms: +[import ../example/doc_spawn_vector.cpp] +[doc_spawn_vector] -[import ../example/doc_contB.cpp] -[doc_contB] +The parent process will create an special shared memory class that allows easy construction +of many complex data structures associated with a name. The parent process executes the same +program with an additional argument so the child process opens the shared memory and uses +the vector and erases it. [endsect] @@ -498,16 +491,11 @@ For more details regarding `mapped_region` see the Let's see a simple example of shared memory use. A server process creates a shared memory object, maps it and initializes all the bytes to a value. After that, a client process opens the shared memory, maps it, and checks -that the data is correctly initialized. This is the server process: +that the data is correctly initialized: [import ../example/doc_shared_memory.cpp] [doc_shared_memory] -Now the client process: - -[import ../example/doc_shared_memory2.cpp] -[doc_shared_memory2] - [endsect] [section:emulation Emulation for systems without shared memory objects] @@ -521,12 +509,11 @@ POSIX: defined by POSIX (see [link interprocess.sharedmemorybetweenprocesses.sharedmemory.windows_shared_memory Native windows shared memory] section for more information). -* Some UNIX systems don't support shared memory objects at all. MacOS is - one of these operating systems. +* Some UNIX systems don't fully support POSIX shared memory objects at all. In those platforms, shared memory is emulated with mapped files created in the temporary files directory. Because of this emulation, shared memory -has filesystem lifetime in those systems. +has filesystem lifetime in some of those systems. [endsect] @@ -554,12 +541,9 @@ the name will subsequently cause the creation of a shared memory object of this name exists (that is, trying to open an object with that name will fail and an object of the same name can be created again). -In Windows operating systems, the function fails if the object is being used, -so a programmer can't consider the UNIX behavior as the portable behavior: - -`shared_memory_object::remove` [*can] fail if the shared memory is still in use, -but this does not mean that it [*will] fail if it's in use. Just the same -behavior as the standard C (stdio.h) `int remove(const char *path)` function. +In Windows operating systems, current version supports an usually acceptable emulation +of the UNIX unlink behaviour: the file is randomly renamed and marked as to be deleted when +the last open handle is closed. [endsect] @@ -586,7 +570,6 @@ be used so that `region` is used to communicate two related processes. [endsect] - [section:windows_shared_memory Native windows shared memory] Windows operating system also offers shared memory, but the lifetime of this @@ -624,20 +607,13 @@ shared memory object, maps it and initializes all the bytes to a value. After th a client process opens the shared memory, maps it, and checks that the data is correctly initialized. Take in care that [*if the server exits before the client connects to the shared memory the client connection will fail], because -the shared memory segment is destroyed when no processes are attached to the memory. +the shared memory segment is destroyed when no proces is attached to the memory. This is the server process: [import ../example/doc_windows_shared_memory.cpp] [doc_windows_shared_memory] -Now, before destroying the -[classref boost::interprocess::windows_shared_memory windows_shared memory] -object, launch the client process: - -[import ../example/doc_windows_shared_memory2.cpp] -[doc_windows_shared_memory2] - As we can see, native windows shared memory needs synchronization to make sure that the shared memory won't be destroyed before the client is launched. @@ -801,16 +777,11 @@ Let's reproduce the same example described in the shared memory section, using memory mapped files. A server process creates a shared memory segment, maps it and initializes all the bytes to a value. After that, a client process opens the shared memory, maps it, and checks -that the data is correctly initialized. This is the server process: +that the data is correctly initialized:: [import ../example/doc_file_mapping.cpp] [doc_file_mapping] -Now the client process: - -[import ../example/doc_file_mapping2.cpp] -[doc_file_mapping2] - [endsect] [endsect] @@ -1478,17 +1449,17 @@ will write a flag when ends writing the traces This is the process main process. Creates the shared memory, constructs the cyclic buffer and start writing traces: -[import ../example/doc_anonymous_mutexA.cpp] +[import ../example/comp_doc_anonymous_mutexA.cpp] [doc_anonymous_mutexA] The second process opens the shared memory, obtains access to the cyclic buffer and starts writing traces: -[import ../example/doc_anonymous_mutexB.cpp] +[import ../example/comp_doc_anonymous_mutexB.cpp] [doc_anonymous_mutexB] -As we can see, a mutex is useful to protect data but not to notify to another process -an event. For this, we need a condition variable, as we will see in the next section. +As we can see, a mutex is useful to protect data but not to notify an event to another +process. For this, we need a condition variable, as we will see in the next section. [endsect] @@ -1583,13 +1554,13 @@ This is the process main process. Creates the shared memory, places there the buffer and starts writing messages one by one until it writes "last message" to indicate that there are no more messages to print: -[import ../example/doc_anonymous_conditionA.cpp] +[import ../example/comp_doc_anonymous_conditionA.cpp] [doc_anonymous_conditionA] The second process opens the shared memory and prints each message until the "last message" message is received: -[import ../example/doc_anonymous_conditionB.cpp] +[import ../example/comp_doc_anonymous_conditionB.cpp] [doc_anonymous_conditionB] With condition variables, a process can block if it can't continue the work, @@ -1665,13 +1636,13 @@ This is the process main process. Creates the shared memory, places there the integer array and starts integers one by one, blocking if the array is full: -[import ../example/doc_anonymous_semaphoreA.cpp] +[import ../example/comp_doc_anonymous_semaphoreA.cpp] [doc_anonymous_semaphoreA] The second process opens the shared memory and copies the received integers to it's own buffer: -[import ../example/doc_anonymous_semaphoreB.cpp] +[import ../example/comp_doc_anonymous_semaphoreB.cpp] [doc_anonymous_semaphoreB] The same interprocess communication can be achieved with a condition variables @@ -2152,11 +2123,11 @@ more features and operations, see their reference for more informations [/section:upgradable_mutexes_example Anonymous Upgradable Mutex Example] -[/import ../example/doc_anonymous_upgradable_mutexA.cpp] +[/import ../example/comp_doc_anonymous_upgradable_mutexA.cpp] [/doc_anonymous_upgradable_mutexA] -[/import ../example/doc_anonymous_upgradable_mutexB.cpp] +[/import ../example/comp_doc_anonymous_upgradable_mutexB.cpp] [/doc_anonymous_upgradable_mutexB] [/endsect] @@ -2722,7 +2693,7 @@ objects are created pointing to the same file, no synchronization is guaranteed. POSIX, when two file descriptors are used to lock a file if a descriptor is closed, all file locks set by the calling process are cleared. -To sum up, if you plan to use file locking in your processes, use the following +To sum up, if you plan to use portable file locking in your processes, use the following restrictions: * [*For each file, use a single `file_lock` object per process.] @@ -2867,12 +2838,12 @@ In the following example, the first process creates the message queue, and write an array of integers on it. The other process just reads the array and checks that the sequence number is correct. This is the first process: -[import ../example/doc_message_queueA.cpp] +[import ../example/comp_doc_message_queueA.cpp] [doc_message_queueA] This is the second process: -[import ../example/doc_message_queueB.cpp] +[import ../example/comp_doc_message_queueB.cpp] [doc_message_queueB] To know more about this class and all its operations, please see the @@ -3246,11 +3217,16 @@ To use a managed mapped file, you must include the following header: managed_mapped_file mfile (open_or_create, "MyMappedFile", //Mapped file name 65536); //Mapped file size When the `managed_mapped_file` object is destroyed, the file is automatically unmapped, and all the resources are freed. To remove -the file from the filesystem you can use standard C `std::remove` -or [*Boost.Filesystem]'s `remove()` functions. File removing might fail +the file from the filesystem you could use standard C `std::remove` +or [*Boost.Filesystem]'s `remove()` functions, but file removing might fail if any process still has the file mapped in memory or the file is open by any process. +To obtain a more portable behaviour, use `file_mapping::remove(const char *)` operation, which +will remove the file even if it's being mapped. However, removal will fail in some OS systems if +the file (eg. by C++ file streams) and no delete share permission was granted to the file. But in +most common cases `file_mapping::remove` is portable enough. + [endsect] For more information about managed mapped file capabilities, see @@ -3871,20 +3847,20 @@ Here is the declaration of the function: [c++] - enum allocation_type + enum boost::interprocess::allocation_type { //Bitwise OR (|) combinable values - allocate_new = ..., - expand_fwd = ..., - expand_bwd = ..., - shrink_in_place = ..., - nothrow_allocation = ... + boost::interprocess::allocate_new = ..., + boost::interprocess::expand_fwd = ..., + boost::interprocess::expand_bwd = ..., + boost::interprocess::shrink_in_place = ..., + boost::interprocess::nothrow_allocation = ... }; template std::pair - allocation_command( allocation_type command + allocation_command( boost::interprocess::allocation_type command , std::size_t limit_size , std::size_t preferred_size , std::size_t &received_size @@ -3893,66 +3869,66 @@ Here is the declaration of the function: [*Preconditions for the function]: -* If the parameter command contains the value `shrink_in_place` it can't -contain any of these values: `expand_fwd`, `expand_bwd`. +* If the parameter command contains the value `boost::interprocess::shrink_in_place` it can't +contain any of these values: `boost::interprocess::expand_fwd`, `boost::interprocess::expand_bwd`. -* If the parameter command contains `expand_fwd` or `expand_bwd`, the parameter +* If the parameter command contains `boost::interprocess::expand_fwd` or `boost::interprocess::expand_bwd`, the parameter `reuse_ptr` must be non-null and returned by a previous allocation function. -* If the parameter command contains the value `shrink_in_place`, the parameter +* If the parameter command contains the value `boost::interprocess::shrink_in_place`, the parameter `limit_size` must be equal or greater than the parameter `preferred_size`. -* If the parameter `command` contains any of these values: `expand_fwd` or `expand_bwd`, +* If the parameter `command` contains any of these values: `boost::interprocess::expand_fwd` or `boost::interprocess::expand_bwd`, the parameter `limit_size` must be equal or less than the parameter `preferred_size`. [*Which are the effects of this function:] -* If the parameter command contains the value `shrink_in_place`, the function +* If the parameter command contains the value `boost::interprocess::shrink_in_place`, the function will try to reduce the size of the memory block referenced by pointer `reuse_ptr` to the value `preferred_size` moving only the end of the block. If it's not possible, it will try to reduce the size of the memory block as much as possible as long as this results in `size(p) <= limit_size`. Success is reported only if this results in `preferred_size <= size(p)` and `size(p) <= limit_size`. -* If the parameter `command` only contains the value `expand_fwd` (with optional - additional `nothrow_allocation`), the allocator will try to increase the size of the +* If the parameter `command` only contains the value `boost::interprocess::expand_fwd` (with optional + additional `boost::interprocess::nothrow_allocation`), the allocator will try to increase the size of the memory block referenced by pointer reuse moving only the end of the block to the value `preferred_size`. If it's not possible, it will try to increase the size of the memory block as much as possible as long as this results in `size(p) >= limit_size`. Success is reported only if this results in `limit_size <= size(p)`. -* If the parameter `command` only contains the value `expand_bwd` (with optional - additional `nothrow_allocation`), the allocator will try to increase the size of +* If the parameter `command` only contains the value `boost::interprocess::expand_bwd` (with optional + additional `boost::interprocess::nothrow_allocation`), the allocator will try to increase the size of the memory block referenced by pointer `reuse_ptr` only moving the start of the block to a returned new position `new_ptr`. If it's not possible, it will try to move the start of the block as much as possible as long as this results in `size(new_ptr) >= limit_size`. Success is reported only if this results in `limit_size <= size(new_ptr)`. -* If the parameter `command` only contains the value `allocate_new` (with optional - additional `nothrow_allocation`), the allocator will try to allocate memory for +* If the parameter `command` only contains the value `boost::interprocess::allocate_new` (with optional + additional `boost::interprocess::nothrow_allocation`), the allocator will try to allocate memory for `preferred_size` objects. If it's not possible it will try to allocate memory for at least `limit_size` objects. -* If the parameter `command` only contains a combination of `expand_fwd` and - `allocate_new`, (with optional additional `nothrow_allocation`) the allocator will +* If the parameter `command` only contains a combination of `boost::interprocess::expand_fwd` and + `boost::interprocess::allocate_new`, (with optional additional `boost::interprocess::nothrow_allocation`) the allocator will try first the forward expansion. If this fails, it would try a new allocation. -* If the parameter `command` only contains a combination of `expand_bwd` and - `allocate_new` (with optional additional `nothrow_allocation`), the allocator will +* If the parameter `command` only contains a combination of `boost::interprocess::expand_bwd` and + `boost::interprocess::allocate_new` (with optional additional `boost::interprocess::nothrow_allocation`), the allocator will try first to obtain `preferred_size` objects using both methods if necessary. If this fails, it will try to obtain `limit_size` objects using both methods if necessary. -* If the parameter `command` only contains a combination of `expand_fwd` and - `expand_bwd` (with optional additional `nothrow_allocation`), the allocator will +* If the parameter `command` only contains a combination of `boost::interprocess::expand_fwd` and + `boost::interprocess::expand_bwd` (with optional additional `boost::interprocess::nothrow_allocation`), the allocator will try first forward expansion. If this fails it will try to obtain preferred_size objects using backwards expansion or a combination of forward and backwards expansion. If this fails, it will try to obtain `limit_size` objects using both methods if necessary. * If the parameter `command` only contains a combination of allocation_new, - `expand_fwd` and `expand_bwd`, (with optional additional `nothrow_allocation`) + `boost::interprocess::expand_fwd` and `boost::interprocess::expand_bwd`, (with optional additional `boost::interprocess::nothrow_allocation`) the allocator will try first forward expansion. If this fails it will try to obtain preferred_size objects using new allocation, backwards expansion or a combination of forward and backwards expansion. If this fails, it will try to obtain `limit_size` @@ -3967,13 +3943,13 @@ contain any of these values: `expand_fwd`, `expand_bwd`. * The allocator is unable to allocate/expand/shrink the memory or there is an error in preconditions -* The parameter command does not contain `nothrow_allocation`. +* The parameter command does not contain `boost::interprocess::nothrow_allocation`. [*This function returns:] * The address of the allocated memory or the new address of the expanded memory as the first member of the pair. If the parameter command contains - `nothrow_allocation` the first member will be 0 + `boost::interprocess::nothrow_allocation` the first member will be 0 if the allocation/expansion fails or there is an error in preconditions. * The second member of the pair will be false if the memory has been allocated, @@ -5018,7 +4994,7 @@ Let's see an example: [endsect] -[section:containers_and_move_semantics Move semantics in Interprocess containers] +[section:containers_and_move Move semantics in Interprocess containers] [*Boost.Interprocess] containers support move semantics, which means that the contents of a container can be moved from a container two another one, without any copying. The @@ -5030,7 +5006,7 @@ objects in the container, avoiding unnecessary copies. To transfer the contents of a container to another one, use -`boost::interprocess::move()` function, as shown in the example. For more details +`boost::move()` function, as shown in the example. For more details about functions supporting move-semantics, see the reference section of Boost.Interprocess containers: @@ -6541,13 +6517,35 @@ warranty. [section:release_notes Release Notes] +[section:release_notes_boost_1_39_00 Boost 1.39 Release] + +* Added experimental `stable_vector` container. +* `shared_memory_object::remove` has now POSIX `unlink` semantics and + `file_mapping::remove` was added to obtain POSIX `unlink` semantics with mapped files. +* Shared memory in windows has now kernel lifetime instead of filesystem lifetime: shared + memory will disappear when the system reboots. +* Updated move semantics. +* Fixed bugs + [@https://svn.boost.org/trac/boost/ticket/2722 #2722], + [@https://svn.boost.org/trac/boost/ticket/2729 #2729], + [@https://svn.boost.org/trac/boost/ticket/2766 #2766], + [@https://svn.boost.org/trac/boost/ticket/1390 #1390], + [@https://svn.boost.org/trac/boost/ticket/2589 #2589], + +[endsect] + [section:release_notes_boost_1_38_00 Boost 1.38 Release] * Updated documentation to show rvalue-references funcions instead of emulation functions. * More non-copyable classes are now movable. * Move-constructor and assignments now leave moved object in default-constructed state instead of just swapping contents. -* Several bugfixes (#2391, #2431, #1390, #2570, #2528). +* Several bugfixes ( + [@https://svn.boost.org/trac/boost/ticket/2391 #2391], + [@https://svn.boost.org/trac/boost/ticket/2431 #2431], + [@https://svn.boost.org/trac/boost/ticket/1390 #1390], + [@https://svn.boost.org/trac/boost/ticket/2570 #2570], + [@https://svn.boost.org/trac/boost/ticket/2528 #2528]. [endsect] diff --git a/example/Jamfile.v2 b/example/Jamfile.v2 index 9551f9f..ba27162 100644 --- a/example/Jamfile.v2 +++ b/example/Jamfile.v2 @@ -19,7 +19,7 @@ rule test_all { local all_rules = ; - for local fileb in [ glob *.cpp ] + for local fileb in [ glob comp*.cpp ] { all_rules += [ link $(fileb) /boost/thread//boost_thread : # additional args @@ -28,6 +28,17 @@ rule test_all ] ; } + for local fileb in [ glob doc_*.cpp ] + { + all_rules += [ run $(fileb) /boost/thread//boost_thread + : # additional args + : # test-files + : # requirements + acc:-lrt + acc-pa_risc:-lrt + ] ; + } + return $(all_rules) ; } diff --git a/example/doc_anonymous_conditionA.cpp b/example/comp_doc_anonymous_conditionA.cpp similarity index 88% rename from example/doc_anonymous_conditionA.cpp rename to example/comp_doc_anonymous_conditionA.cpp index 1fb3336..cd0c7d3 100644 --- a/example/doc_anonymous_conditionA.cpp +++ b/example/comp_doc_anonymous_conditionA.cpp @@ -21,13 +21,17 @@ using namespace boost::interprocess; int main () { - //Erase previous shared memory - shared_memory_object::remove("shared_memory"); + //Erase previous shared memory and schedule erasure on exit + struct shm_destroy + { + shm_destroy() { shared_memory_object::remove("MySharedMemory"); } + ~shm_destroy(){ shared_memory_object::remove("MySharedMemory"); } + } remover; //Create a shared memory object. shared_memory_object shm (create_only //only create - ,"shared_memory" //name + ,"MySharedMemory" //name ,read_write //read-write mode ); try{ @@ -66,13 +70,10 @@ int main () } } catch(interprocess_exception &ex){ - shared_memory_object::remove("shared_memory"); std::cout << ex.what() << std::endl; return 1; } - //Erase shared memory - shared_memory_object::remove("shared_memory"); return 0; } //] diff --git a/example/doc_anonymous_conditionB.cpp b/example/comp_doc_anonymous_conditionB.cpp similarity index 92% rename from example/doc_anonymous_conditionB.cpp rename to example/comp_doc_anonymous_conditionB.cpp index 06d0a55..baa6a58 100644 --- a/example/doc_anonymous_conditionB.cpp +++ b/example/comp_doc_anonymous_conditionB.cpp @@ -23,7 +23,7 @@ int main () //Create a shared memory object. shared_memory_object shm (open_only //only create - ,"shared_memory" //name + ,"MySharedMemory" //name ,read_write //read-write mode ); @@ -61,13 +61,10 @@ int main () while(!end_loop); } catch(interprocess_exception &ex){ - shared_memory_object::remove("shared_memory"); std::cout << ex.what() << std::endl; return 1; } - //Erase shared memory - shared_memory_object::remove("shared_memory"); return 0; } //] diff --git a/example/doc_anonymous_mutexA.cpp b/example/comp_doc_anonymous_mutexA.cpp similarity index 87% rename from example/doc_anonymous_mutexA.cpp rename to example/comp_doc_anonymous_mutexA.cpp index 04710fb..bbbc33c 100644 --- a/example/doc_anonymous_mutexA.cpp +++ b/example/comp_doc_anonymous_mutexA.cpp @@ -21,13 +21,17 @@ using namespace boost::interprocess; int main () { try{ - //Erase previous shared memory - shared_memory_object::remove("shared_memory"); + //Remove shared memory on construction and destruction + struct shm_destroy + { + shm_destroy() { shared_memory_object::remove("MySharedMemory"); } + ~shm_destroy(){ shared_memory_object::remove("MySharedMemory"); } + } remover; //Create a shared memory object. shared_memory_object shm (create_only //only create - ,"shared_memory" //name + ,"MySharedMemory" //name ,read_write //read-write mode ); @@ -65,12 +69,9 @@ int main () } } catch(interprocess_exception &ex){ - shared_memory_object::remove("shared_memory"); std::cout << ex.what() << std::endl; return 1; } - //Erase shared memory - shared_memory_object::remove("shared_memory"); return 0; } //] diff --git a/example/comp_doc_anonymous_mutexB.cpp b/example/comp_doc_anonymous_mutexB.cpp new file mode 100644 index 0000000..4a7ed40 --- /dev/null +++ b/example/comp_doc_anonymous_mutexB.cpp @@ -0,0 +1,68 @@ +////////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2006-2007. 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 +//[doc_anonymous_mutexB +#include +#include +#include +#include "doc_anonymous_mutex_shared_data.hpp" +#include +#include + +using namespace boost::interprocess; + +int main () +{ + //Remove shared memory on destruction + struct shm_destroy + { + ~shm_destroy(){ shared_memory_object::remove("MySharedMemory"); } + } remover; + + //Open the shared memory object. + shared_memory_object shm + (open_only //only create + ,"MySharedMemory" //name + ,read_write //read-write mode + ); + + //Map the whole shared memory in this process + mapped_region region + (shm //What to map + ,read_write //Map it as read-write + ); + + //Get the address of the mapped region + void * addr = region.get_address(); + + //Construct the shared structure in memory + shared_memory_log * data = static_cast(addr); + + //Write some logs + for(int i = 0; i < 100; ++i){ + //Lock the mutex + scoped_lock lock(data->mutex); + std::sprintf(data->items[(data->current_line++) % shared_memory_log::NumItems] + ,"%s_%d", "process_a", i); + if(i == (shared_memory_log::NumItems-1)) + data->end_b = true; + //Mutex is released here + } + + //Wait until the other process ends + while(1){ + scoped_lock lock(data->mutex); + if(data->end_a) + break; + } + return 0; +} +//] +#include diff --git a/example/comp_doc_anonymous_semaphoreA.cpp b/example/comp_doc_anonymous_semaphoreA.cpp new file mode 100644 index 0000000..856ecfc --- /dev/null +++ b/example/comp_doc_anonymous_semaphoreA.cpp @@ -0,0 +1,64 @@ +////////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2006-2007. 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 +//[doc_anonymous_semaphoreA +#include +#include +#include +#include "doc_anonymous_semaphore_shared_data.hpp" + +using namespace boost::interprocess; + +int main () +{ + //Remove shared memory on construction and destruction + struct shm_destroy + { + shm_destroy() { shared_memory_object::remove("MySharedMemory"); } + ~shm_destroy(){ shared_memory_object::remove("MySharedMemory"); } + } remover; + + //Create a shared memory object. + shared_memory_object shm + (create_only //only create + ,"MySharedMemory" //name + ,read_write //read-write mode + ); + + //Set size + shm.truncate(sizeof(shared_memory_buffer)); + + //Map the whole shared memory in this process + mapped_region region + (shm //What to map + ,read_write //Map it as read-write + ); + + //Get the address of the mapped region + void * addr = region.get_address(); + + //Construct the shared structure in memory + shared_memory_buffer * data = new (addr) shared_memory_buffer; + + const int NumMsg = 100; + + //Insert data in the array + for(int i = 0; i < NumMsg; ++i){ + data->nempty.wait(); + data->mutex.wait(); + data->items[i % shared_memory_buffer::NumItems] = i; + data->mutex.post(); + data->nstored.post(); + } + + return 0; +} +//] +#include diff --git a/example/comp_doc_anonymous_semaphoreB.cpp b/example/comp_doc_anonymous_semaphoreB.cpp new file mode 100644 index 0000000..29975f7 --- /dev/null +++ b/example/comp_doc_anonymous_semaphoreB.cpp @@ -0,0 +1,61 @@ +////////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2006-2007. 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 +//[doc_anonymous_semaphoreB +#include +#include +#include +#include "doc_anonymous_semaphore_shared_data.hpp" + +using namespace boost::interprocess; + +int main () +{ + //Remove shared memory on destruction + struct shm_destroy + { + ~shm_destroy(){ shared_memory_object::remove("MySharedMemory"); } + } remover; + + //Create a shared memory object. + shared_memory_object shm + (open_only //only create + ,"MySharedMemory" //name + ,read_write //read-write mode + ); + + //Map the whole shared memory in this process + mapped_region region + (shm //What to map + ,read_write //Map it as read-write + ); + + //Get the address of the mapped region + void * addr = region.get_address(); + + //Obtain the shared structure + shared_memory_buffer * data = static_cast(addr); + + const int NumMsg = 100; + + int extracted_data [NumMsg]; + + //Extract the data + for(int i = 0; i < NumMsg; ++i){ + data->nstored.wait(); + data->mutex.wait(); + extracted_data[i] = data->items[i % shared_memory_buffer::NumItems]; + data->mutex.post(); + data->nempty.post(); + } + return 0; +} +//] +#include diff --git a/example/comp_doc_anonymous_upgradable_mutexA.cpp b/example/comp_doc_anonymous_upgradable_mutexA.cpp new file mode 100644 index 0000000..b07d9dd --- /dev/null +++ b/example/comp_doc_anonymous_upgradable_mutexA.cpp @@ -0,0 +1,72 @@ +////////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2006-2007. 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 +//[doc_anonymous_upgradable_mutexA +#include +#include +#include +#include "doc_upgradable_mutex_shared_data.hpp" +#include +#include + +using namespace boost::interprocess; + +int main () +{ + //Remove shared memory on destruction + struct shm_destroy + { + ~shm_destroy(){ shared_memory_object::remove("MySharedMemory"); } + } remover; + + //Create a shared memory object. + shared_memory_object shm + (create_only //only create + ,"MySharedMemory" //name + ,read_write //read-write mode + ); + + //Set size + shm.truncate(sizeof(shared_data)); + + //Map the whole shared memory in this process + mapped_region region + (shm //What to map + ,read_write //Map it as read-write + ); + + //Get the address of the mapped region + void * addr = region.get_address(); + + //Construct the shared structure in memory + shared_data * data = new (addr) shared_data; + + //Write some logs + for(int i = 0; i < shared_data::NumItems; ++i){ + //Lock the upgradable_mutex + scoped_lock lock(data->upgradable_mutex); + std::sprintf(data->items[(data->current_line++) % shared_data::NumItems] + ,"%s_%d", "process_a", i); + if(i == (shared_data::NumItems-1)) + data->end_a = true; + //Mutex is released here + } + + //Wait until the other process ends + while(1){ + scoped_lock lock(data->upgradable_mutex); + if(data->end_b) + break; + } + + return 0; +} +//] +#include diff --git a/example/comp_doc_anonymous_upgradable_mutexB.cpp b/example/comp_doc_anonymous_upgradable_mutexB.cpp new file mode 100644 index 0000000..e0448e7 --- /dev/null +++ b/example/comp_doc_anonymous_upgradable_mutexB.cpp @@ -0,0 +1,70 @@ +////////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2006-2007. 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 + +//[doc_anonymous_upgradable_mutexB +#include +#include +#include +#include "doc_upgradable_mutex_shared_data.hpp" +#include +#include + +using namespace boost::interprocess; + +int main () +{ + //Remove shared memory on destruction + struct shm_destroy + { + ~shm_destroy(){ shared_memory_object::remove("MySharedMemory"); } + } remover; + + //Open the shared memory object. + shared_memory_object shm + (open_only //only create + ,"MySharedMemory" //name + ,read_write //read-write mode + ); + + //Map the whole shared memory in this process + mapped_region region + (shm //What to map + ,read_write //Map it as read-write + ); + + //Get the address of the mapped region + void * addr = region.get_address(); + + //Construct the shared structure in memory + shared_data * data = static_cast(addr); + + //Write some logs + for(int i = 0; i < 100; ++i){ + //Lock the upgradable_mutex + scoped_lock lock(data->upgradable_mutex); + std::sprintf(data->items[(data->current_line++) % shared_data::NumItems] + ,"%s_%d", "process_a", i); + if(i == (shared_data::NumItems-1)) + data->end_b = true; + //Mutex is released here + } + + //Wait until the other process ends + while(1){ + scoped_lock lock(data->upgradable_mutex); + if(data->end_a) + break; + } + return 0; +} +//] + +#include diff --git a/example/doc_message_queueA.cpp b/example/comp_doc_message_queueA.cpp similarity index 100% rename from example/doc_message_queueA.cpp rename to example/comp_doc_message_queueA.cpp diff --git a/example/doc_message_queueB.cpp b/example/comp_doc_message_queueB.cpp similarity index 100% rename from example/doc_message_queueB.cpp rename to example/comp_doc_message_queueB.cpp diff --git a/example/doc_adaptive_pool.cpp b/example/doc_adaptive_pool.cpp index 9aeb0d4..e013ea3 100644 --- a/example/doc_adaptive_pool.cpp +++ b/example/doc_adaptive_pool.cpp @@ -18,46 +18,44 @@ using namespace boost::interprocess; int main () { - shared_memory_object::remove("MySharedMemory"); + //Remove shared memory on construction and destruction + struct shm_destroy + { + shm_destroy() { shared_memory_object::remove("MySharedMemory"); } + ~shm_destroy(){ shared_memory_object::remove("MySharedMemory"); } + } remover; - try{ - //Create shared memory - managed_shared_memory segment(create_only, - "MySharedMemory", //segment name - 65536); + //Create shared memory + managed_shared_memory segment(create_only, + "MySharedMemory", //segment name + 65536); - //Create a adaptive_pool that allocates ints from the managed segment - //The number of chunks per segment is the default value - typedef adaptive_pool - adaptive_pool_t; - adaptive_pool_t allocator_instance(segment.get_segment_manager()); + //Create a adaptive_pool that allocates ints from the managed segment + //The number of chunks per segment is the default value + typedef adaptive_pool + adaptive_pool_t; + adaptive_pool_t allocator_instance(segment.get_segment_manager()); - //Create another adaptive_pool. Since the segment manager address - //is the same, this adaptive_pool will be - //attached to the same pool so "allocator_instance2" can deallocate - //nodes allocated by "allocator_instance" - adaptive_pool_t allocator_instance2(segment.get_segment_manager()); + //Create another adaptive_pool. Since the segment manager address + //is the same, this adaptive_pool will be + //attached to the same pool so "allocator_instance2" can deallocate + //nodes allocated by "allocator_instance" + adaptive_pool_t allocator_instance2(segment.get_segment_manager()); - //Create another adaptive_pool using copy-constructor. This - //adaptive_pool will also be attached to the same pool - adaptive_pool_t allocator_instance3(allocator_instance2); + //Create another adaptive_pool using copy-constructor. This + //adaptive_pool will also be attached to the same pool + adaptive_pool_t allocator_instance3(allocator_instance2); - //All allocators are equal - assert(allocator_instance == allocator_instance2); - assert(allocator_instance2 == allocator_instance3); + //All allocators are equal + assert(allocator_instance == allocator_instance2); + assert(allocator_instance2 == allocator_instance3); - //So memory allocated with one can be deallocated with another - allocator_instance2.deallocate(allocator_instance.allocate(1), 1); - allocator_instance3.deallocate(allocator_instance2.allocate(1), 1); + //So memory allocated with one can be deallocated with another + allocator_instance2.deallocate(allocator_instance.allocate(1), 1); + allocator_instance3.deallocate(allocator_instance2.allocate(1), 1); - //The common pool will be destroyed here, since no allocator is - //attached to the pool - } - catch(...){ - shared_memory_object::remove("MySharedMemory"); - throw; - } - shared_memory_object::remove("MySharedMemory"); + //The common pool will be destroyed here, since no allocator is + //attached to the pool return 0; } //] diff --git a/example/doc_allocator.cpp b/example/doc_allocator.cpp index 87b071d..132658f 100644 --- a/example/doc_allocator.cpp +++ b/example/doc_allocator.cpp @@ -18,7 +18,12 @@ using namespace boost::interprocess; int main () { - shared_memory_object::remove("MySharedMemory"); + //Remove shared memory on construction and destruction + struct shm_destroy + { + shm_destroy() { shared_memory_object::remove("MySharedMemory"); } + ~shm_destroy(){ shared_memory_object::remove("MySharedMemory"); } + } remover; //Create shared memory managed_shared_memory segment(create_only, diff --git a/example/doc_anonymous_mutexB.cpp b/example/doc_anonymous_mutexB.cpp deleted file mode 100644 index c7854eb..0000000 --- a/example/doc_anonymous_mutexB.cpp +++ /dev/null @@ -1,70 +0,0 @@ -////////////////////////////////////////////////////////////////////////////// -// -// (C) Copyright Ion Gaztanaga 2006-2007. 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 -//[doc_anonymous_mutexB -#include -#include -#include -#include "doc_anonymous_mutex_shared_data.hpp" -#include -#include - -using namespace boost::interprocess; - -int main () -{ - try{ - //Open the shared memory object. - shared_memory_object shm - (open_only //only create - ,"shared_memory" //name - ,read_write //read-write mode - ); - - //Map the whole shared memory in this process - mapped_region region - (shm //What to map - ,read_write //Map it as read-write - ); - - //Get the address of the mapped region - void * addr = region.get_address(); - - //Construct the shared structure in memory - shared_memory_log * data = static_cast(addr); - - //Write some logs - for(int i = 0; i < 100; ++i){ - //Lock the mutex - scoped_lock lock(data->mutex); - std::sprintf(data->items[(data->current_line++) % shared_memory_log::NumItems] - ,"%s_%d", "process_a", i); - if(i == (shared_memory_log::NumItems-1)) - data->end_b = true; - //Mutex is released here - } - - //Wait until the other process ends - while(1){ - scoped_lock lock(data->mutex); - if(data->end_a) - break; - } - } - catch(interprocess_exception &ex){ - shared_memory_object::remove("shared_memory"); - std::cout << ex.what() << std::endl; - return 1; - } - shared_memory_object::remove("shared_memory"); - return 0; -} -//] -#include diff --git a/example/doc_anonymous_semaphoreA.cpp b/example/doc_anonymous_semaphoreA.cpp deleted file mode 100644 index f687049..0000000 --- a/example/doc_anonymous_semaphoreA.cpp +++ /dev/null @@ -1,70 +0,0 @@ -////////////////////////////////////////////////////////////////////////////// -// -// (C) Copyright Ion Gaztanaga 2006-2007. 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 -//[doc_anonymous_semaphoreA -#include -#include -#include -#include "doc_anonymous_semaphore_shared_data.hpp" - -using namespace boost::interprocess; - -int main () -{ - try{ - //Erase previous shared memory - shared_memory_object::remove("shared_memory"); - - //Create a shared memory object. - shared_memory_object shm - (create_only //only create - ,"shared_memory" //name - ,read_write //read-write mode - ); - - //Set size - shm.truncate(sizeof(shared_memory_buffer)); - - //Map the whole shared memory in this process - mapped_region region - (shm //What to map - ,read_write //Map it as read-write - ); - - //Get the address of the mapped region - void * addr = region.get_address(); - - //Construct the shared structure in memory - shared_memory_buffer * data = new (addr) shared_memory_buffer; - - const int NumMsg = 100; - - //Insert data in the array - for(int i = 0; i < NumMsg; ++i){ - data->nempty.wait(); - data->mutex.wait(); - data->items[i % shared_memory_buffer::NumItems] = i; - data->mutex.post(); - data->nstored.post(); - } - } - catch(interprocess_exception &ex){ - shared_memory_object::remove("shared_memory"); - std::cout << ex.what() << std::endl; - return 1; - } - - //Erase shared memory - shared_memory_object::remove("shared_memory"); - - return 0; -} -//] -#include diff --git a/example/doc_anonymous_semaphoreB.cpp b/example/doc_anonymous_semaphoreB.cpp deleted file mode 100644 index daf4e98..0000000 --- a/example/doc_anonymous_semaphoreB.cpp +++ /dev/null @@ -1,66 +0,0 @@ -////////////////////////////////////////////////////////////////////////////// -// -// (C) Copyright Ion Gaztanaga 2006-2007. 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 -//[doc_anonymous_semaphoreB -#include -#include -#include -#include "doc_anonymous_semaphore_shared_data.hpp" - -using namespace boost::interprocess; - -int main () -{ - try{ - //Create a shared memory object. - shared_memory_object shm - (open_only //only create - ,"shared_memory" //name - ,read_write //read-write mode - ); - - //Map the whole shared memory in this process - mapped_region region - (shm //What to map - ,read_write //Map it as read-write - ); - - //Get the address of the mapped region - void * addr = region.get_address(); - - //Obtain the shared structure - shared_memory_buffer * data = static_cast(addr); - - const int NumMsg = 100; - - int extracted_data [NumMsg]; - - //Extract the data - for(int i = 0; i < NumMsg; ++i){ - data->nstored.wait(); - data->mutex.wait(); - extracted_data[i] = data->items[i % shared_memory_buffer::NumItems]; - data->mutex.post(); - data->nempty.post(); - } - } - catch(interprocess_exception &ex){ - shared_memory_object::remove("shared_memory"); - std::cout << ex.what() << std::endl; - return 1; - } - - //Erase shared memory - shared_memory_object::remove("shared_memory"); - - return 0; -} -//] -#include diff --git a/example/doc_anonymous_upgradable_mutexA.cpp b/example/doc_anonymous_upgradable_mutexA.cpp deleted file mode 100644 index 158ea1c..0000000 --- a/example/doc_anonymous_upgradable_mutexA.cpp +++ /dev/null @@ -1,79 +0,0 @@ -////////////////////////////////////////////////////////////////////////////// -// -// (C) Copyright Ion Gaztanaga 2006-2007. 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 -//[doc_anonymous_upgradable_mutexA -#include -#include -#include -#include "doc_upgradable_mutex_shared_data.hpp" -#include -#include - -using namespace boost::interprocess; - -int main () -{ - try{ - //Erase previous shared memory - shared_memory_object::remove("shared_memory"); - - //Create a shared memory object. - shared_memory_object shm - (create_only //only create - ,"shared_memory" //name - ,read_write //read-write mode - ); - - //Set size - shm.truncate(sizeof(shared_data)); - - //Map the whole shared memory in this process - mapped_region region - (shm //What to map - ,read_write //Map it as read-write - ); - - //Get the address of the mapped region - void * addr = region.get_address(); - - //Construct the shared structure in memory - shared_data * data = new (addr) shared_data; - - //Write some logs - for(int i = 0; i < shared_data::NumItems; ++i){ - //Lock the upgradable_mutex - scoped_lock lock(data->upgradable_mutex); - std::sprintf(data->items[(data->current_line++) % shared_data::NumItems] - ,"%s_%d", "process_a", i); - if(i == (shared_data::NumItems-1)) - data->end_a = true; - //Mutex is released here - } - - //Wait until the other process ends - while(1){ - scoped_lock lock(data->upgradable_mutex); - if(data->end_b) - break; - } - } - catch(interprocess_exception &ex){ - shared_memory_object::remove("shared_memory"); - std::cout << ex.what() << std::endl; - return 1; - } - - //Erase shared memory - shared_memory_object::remove("shared_memory"); - - return 0; -} -//] -#include diff --git a/example/doc_anonymous_upgradable_mutexB.cpp b/example/doc_anonymous_upgradable_mutexB.cpp deleted file mode 100644 index 1b83e11..0000000 --- a/example/doc_anonymous_upgradable_mutexB.cpp +++ /dev/null @@ -1,72 +0,0 @@ -////////////////////////////////////////////////////////////////////////////// -// -// (C) Copyright Ion Gaztanaga 2006-2007. 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 - -//[doc_anonymous_upgradable_mutexB -#include -#include -#include -#include "doc_upgradable_mutex_shared_data.hpp" -#include -#include - -using namespace boost::interprocess; - -int main () -{ - try{ - //Open the shared memory object. - shared_memory_object shm - (open_only //only create - ,"shared_memory" //name - ,read_write //read-write mode - ); - - //Map the whole shared memory in this process - mapped_region region - (shm //What to map - ,read_write //Map it as read-write - ); - - //Get the address of the mapped region - void * addr = region.get_address(); - - //Construct the shared structure in memory - shared_data * data = static_cast(addr); - - //Write some logs - for(int i = 0; i < 100; ++i){ - //Lock the upgradable_mutex - scoped_lock lock(data->upgradable_mutex); - std::sprintf(data->items[(data->current_line++) % shared_data::NumItems] - ,"%s_%d", "process_a", i); - if(i == (shared_data::NumItems-1)) - data->end_b = true; - //Mutex is released here - } - - //Wait until the other process ends - while(1){ - scoped_lock lock(data->upgradable_mutex); - if(data->end_a) - break; - } - } - catch(interprocess_exception &ex){ - shared_memory_object::remove("shared_memory"); - std::cout << ex.what() << std::endl; - return 1; - } - shared_memory_object::remove("shared_memory"); - return 0; -} -//] - -#include diff --git a/example/doc_bufferstream.cpp b/example/doc_bufferstream.cpp index 4fd6d75..9e14d6a 100644 --- a/example/doc_bufferstream.cpp +++ b/example/doc_bufferstream.cpp @@ -14,72 +14,73 @@ #include #include #include +#include using namespace boost::interprocess; int main () { - shared_memory_object::remove("MySharedMemory"); - try{ - //Create shared memory - managed_shared_memory segment(create_only, - "MySharedMemory", //segment name - 65536); + //Remove shared memory on construction and destruction + struct shm_destroy + { + shm_destroy() { shared_memory_object::remove("MySharedMemory"); } + ~shm_destroy(){ shared_memory_object::remove("MySharedMemory"); } + } remover; - //Fill data - std::vector data, data2; - data.reserve(100); - for(int i = 0; i < 100; ++i){ - data.push_back(i); - } + //Create shared memory + managed_shared_memory segment(create_only, + "MySharedMemory", //segment name + 65536); - //Allocate a buffer in shared memory to write data - char *my_cstring = - segment.construct("MyCString")[100*5](0); - bufferstream mybufstream(my_cstring, 100*5); - - //Now write data to the buffer - for(int i = 0; i < 100; ++i){ - mybufstream << data[i] << std::endl; - } - - //Check there was no overflow attempt - assert(mybufstream.good()); - - //Extract all values from the shared memory string - //directly to a vector. - data2.reserve(100); - std::istream_iterator it(mybufstream), itend; - std::copy(it, itend, std::back_inserter(data2)); - - //This extraction should have ended will fail error since - //the numbers formatted in the buffer end before the end - //of the buffer. (Otherwise it would trigger eofbit) - assert(mybufstream.fail()); - - //Compare data - assert(std::equal(data.begin(), data.end(), data2.begin())); - - //Clear errors and rewind - mybufstream.clear(); - mybufstream.seekp(0, std::ios::beg); - - //Now write again the data trying to do a buffer overflow - for(int i = 0; i < 500; ++i){ - mybufstream << data[i] << std::endl; - } - - //Now make sure badbit is active - //which means overflow attempt. - assert(!mybufstream.good()); - assert(mybufstream.bad()); - segment.destroy_ptr(my_cstring); + //Fill data + std::vector data; + data.reserve(100); + for(int i = 0; i < 100; ++i){ + data.push_back(i); } - catch(...){ - shared_memory_object::remove("MySharedMemory"); - throw; + const std::size_t BufferSize = 100*5; + + //Allocate a buffer in shared memory to write data + char *my_cstring = + segment.construct("MyCString")[BufferSize](0); + bufferstream mybufstream(my_cstring, BufferSize); + + //Now write data to the buffer + for(int i = 0; i < 100; ++i){ + mybufstream << data[i] << std::endl; } - shared_memory_object::remove("MySharedMemory"); + + //Check there was no overflow attempt + assert(mybufstream.good()); + + //Extract all values from the shared memory string + //directly to a vector. + std::vector data2; + std::istream_iterator it(mybufstream), itend; + std::copy(it, itend, std::back_inserter(data2)); + + //This extraction should have ended will fail error since + //the numbers formatted in the buffer end before the end + //of the buffer. (Otherwise it would trigger eofbit) + assert(mybufstream.fail()); + + //Compare data + assert(std::equal(data.begin(), data.end(), data2.begin())); + + //Clear errors and rewind + mybufstream.clear(); + mybufstream.seekp(0, std::ios::beg); + + //Now write again the data trying to do a buffer overflow + for(int i = 0, m = data.size()*5; i < m; ++i){ + mybufstream << data[i%5] << std::endl; + } + + //Now make sure badbit is active + //which means overflow attempt. + assert(!mybufstream.good()); + assert(mybufstream.bad()); + segment.destroy_ptr(my_cstring); return 0; } //] diff --git a/example/doc_cached_adaptive_pool.cpp b/example/doc_cached_adaptive_pool.cpp index c138ef0..6f0f7bf 100644 --- a/example/doc_cached_adaptive_pool.cpp +++ b/example/doc_cached_adaptive_pool.cpp @@ -18,54 +18,53 @@ using namespace boost::interprocess; int main () { - shared_memory_object::remove("MySharedMemory"); - try{ - //Create shared memory - managed_shared_memory segment(create_only, - "MySharedMemory", //segment name - 65536); + //Remove shared memory on construction and destruction + struct shm_destroy + { + shm_destroy() { shared_memory_object::remove("MySharedMemory"); } + ~shm_destroy(){ shared_memory_object::remove("MySharedMemory"); } + } remover; - //Create a cached_adaptive_pool that allocates ints from the managed segment - //The number of chunks per segment is the default value - typedef cached_adaptive_pool - cached_adaptive_pool_t; - cached_adaptive_pool_t allocator_instance(segment.get_segment_manager()); + //Create shared memory + managed_shared_memory segment(create_only, + "MySharedMemory", //segment name + 65536); - //The max cached nodes are configurable per instance - allocator_instance.set_max_cached_nodes(3); + //Create a cached_adaptive_pool that allocates ints from the managed segment + //The number of chunks per segment is the default value + typedef cached_adaptive_pool + cached_adaptive_pool_t; + cached_adaptive_pool_t allocator_instance(segment.get_segment_manager()); - //Create another cached_adaptive_pool. Since the segment manager address - //is the same, this cached_adaptive_pool will be - //attached to the same pool so "allocator_instance2" can deallocate - //nodes allocated by "allocator_instance" - cached_adaptive_pool_t allocator_instance2(segment.get_segment_manager()); + //The max cached nodes are configurable per instance + allocator_instance.set_max_cached_nodes(3); - //The max cached nodes are configurable per instance - allocator_instance2.set_max_cached_nodes(5); + //Create another cached_adaptive_pool. Since the segment manager address + //is the same, this cached_adaptive_pool will be + //attached to the same pool so "allocator_instance2" can deallocate + //nodes allocated by "allocator_instance" + cached_adaptive_pool_t allocator_instance2(segment.get_segment_manager()); - //Create another cached_adaptive_pool using copy-constructor. This - //cached_adaptive_pool will also be attached to the same pool - cached_adaptive_pool_t allocator_instance3(allocator_instance2); + //The max cached nodes are configurable per instance + allocator_instance2.set_max_cached_nodes(5); - //We can clear the cache - allocator_instance3.deallocate_cache(); + //Create another cached_adaptive_pool using copy-constructor. This + //cached_adaptive_pool will also be attached to the same pool + cached_adaptive_pool_t allocator_instance3(allocator_instance2); - //All allocators are equal - assert(allocator_instance == allocator_instance2); - assert(allocator_instance2 == allocator_instance3); + //We can clear the cache + allocator_instance3.deallocate_cache(); - //So memory allocated with one can be deallocated with another - allocator_instance2.deallocate(allocator_instance.allocate(1), 1); - allocator_instance3.deallocate(allocator_instance2.allocate(1), 1); + //All allocators are equal + assert(allocator_instance == allocator_instance2); + assert(allocator_instance2 == allocator_instance3); - //The common pool will be destroyed here, since no allocator is - //attached to the pool - } - catch(...){ - shared_memory_object::remove("MySharedMemory"); - throw; - } - shared_memory_object::remove("MySharedMemory"); + //So memory allocated with one can be deallocated with another + allocator_instance2.deallocate(allocator_instance.allocate(1), 1); + allocator_instance3.deallocate(allocator_instance2.allocate(1), 1); + + //The common pool will be destroyed here, since no allocator is + //attached to the pool return 0; } //] diff --git a/example/doc_cached_node_allocator.cpp b/example/doc_cached_node_allocator.cpp index 091a17e..0d19046 100644 --- a/example/doc_cached_node_allocator.cpp +++ b/example/doc_cached_node_allocator.cpp @@ -18,54 +18,53 @@ using namespace boost::interprocess; int main () { - shared_memory_object::remove("MySharedMemory"); - try{ - //Create shared memory - managed_shared_memory segment(create_only, - "MySharedMemory", //segment name - 65536); + //Remove shared memory on construction and destruction + struct shm_destroy + { + shm_destroy() { shared_memory_object::remove("MySharedMemory"); } + ~shm_destroy(){ shared_memory_object::remove("MySharedMemory"); } + } remover; - //Create a cached_node_allocator that allocates ints from the managed segment - //The number of chunks per segment is the default value - typedef cached_node_allocator - cached_node_allocator_t; - cached_node_allocator_t allocator_instance(segment.get_segment_manager()); + //Create shared memory + managed_shared_memory segment(create_only, + "MySharedMemory", //segment name + 65536); - //The max cached nodes are configurable per instance - allocator_instance.set_max_cached_nodes(3); + //Create a cached_node_allocator that allocates ints from the managed segment + //The number of chunks per segment is the default value + typedef cached_node_allocator + cached_node_allocator_t; + cached_node_allocator_t allocator_instance(segment.get_segment_manager()); - //Create another cached_node_allocator. Since the segment manager address - //is the same, this cached_node_allocator will be - //attached to the same pool so "allocator_instance2" can deallocate - //nodes allocated by "allocator_instance" - cached_node_allocator_t allocator_instance2(segment.get_segment_manager()); + //The max cached nodes are configurable per instance + allocator_instance.set_max_cached_nodes(3); - //The max cached nodes are configurable per instance - allocator_instance2.set_max_cached_nodes(5); + //Create another cached_node_allocator. Since the segment manager address + //is the same, this cached_node_allocator will be + //attached to the same pool so "allocator_instance2" can deallocate + //nodes allocated by "allocator_instance" + cached_node_allocator_t allocator_instance2(segment.get_segment_manager()); - //Create another cached_node_allocator using copy-constructor. This - //cached_node_allocator will also be attached to the same pool - cached_node_allocator_t allocator_instance3(allocator_instance2); + //The max cached nodes are configurable per instance + allocator_instance2.set_max_cached_nodes(5); - //We can clear the cache - allocator_instance3.deallocate_cache(); + //Create another cached_node_allocator using copy-constructor. This + //cached_node_allocator will also be attached to the same pool + cached_node_allocator_t allocator_instance3(allocator_instance2); - //All allocators are equal - assert(allocator_instance == allocator_instance2); - assert(allocator_instance2 == allocator_instance3); + //We can clear the cache + allocator_instance3.deallocate_cache(); - //So memory allocated with one can be deallocated with another - allocator_instance2.deallocate(allocator_instance.allocate(1), 1); - allocator_instance3.deallocate(allocator_instance2.allocate(1), 1); + //All allocators are equal + assert(allocator_instance == allocator_instance2); + assert(allocator_instance2 == allocator_instance3); - //The common pool will be destroyed here, since no allocator is - //attached to the pool - } - catch(...){ - shared_memory_object::remove("MySharedMemory"); - throw; - } - shared_memory_object::remove("MySharedMemory"); + //So memory allocated with one can be deallocated with another + allocator_instance2.deallocate(allocator_instance.allocate(1), 1); + allocator_instance3.deallocate(allocator_instance2.allocate(1), 1); + + //The common pool will be destroyed here, since no allocator is + //attached to the pool return 0; } //] diff --git a/example/doc_complex_map.cpp b/example/doc_complex_map.cpp index 1d64dac..e8d7238 100644 --- a/example/doc_complex_map.cpp +++ b/example/doc_complex_map.cpp @@ -52,28 +52,31 @@ typedef map< char_string, complex_data int main () { - shared_memory_object::remove("MySharedMemory"); - remove_shared_memory_on_destroy remove_on_destroy("MySharedMemory"); + //Remove shared memory on construction and destruction + struct shm_destroy { - //Create shared memory - managed_shared_memory segment(create_only,"MySharedMemory", 65536); + shm_destroy() { shared_memory_object::remove("MySharedMemory"); } + ~shm_destroy(){ shared_memory_object::remove("MySharedMemory"); } + } remover; - //An allocator convertible to any allocator type - void_allocator alloc_inst (segment.get_segment_manager()); + //Create shared memory + managed_shared_memory segment(create_only,"MySharedMemory", 65536); - //Construct the shared memory map and fill it - complex_map_type *mymap = segment.construct - //(object name), (first ctor parameter, second ctor parameter) - ("MyMap")(std::less(), alloc_inst); + //An allocator convertible to any allocator type + void_allocator alloc_inst (segment.get_segment_manager()); - for(int i = 0; i < 100; ++i){ - //Both key(string) and value(complex_data) need an allocator in their constructors - char_string key_object(alloc_inst); - complex_data mapped_object(i, "default_name", alloc_inst); - map_value_type value(key_object, mapped_object); - //Modify values and insert them in the map - mymap->insert(value); - } + //Construct the shared memory map and fill it + complex_map_type *mymap = segment.construct + //(object name), (first ctor parameter, second ctor parameter) + ("MyMap")(std::less(), alloc_inst); + + for(int i = 0; i < 100; ++i){ + //Both key(string) and value(complex_data) need an allocator in their constructors + char_string key_object(alloc_inst); + complex_data mapped_object(i, "default_name", alloc_inst); + map_value_type value(key_object, mapped_object); + //Modify values and insert them in the map + mymap->insert(value); } return 0; } diff --git a/example/doc_cont.cpp b/example/doc_cont.cpp index 6b899ae..cd0680d 100644 --- a/example/doc_cont.cpp +++ b/example/doc_cont.cpp @@ -17,48 +17,47 @@ int main () { using namespace boost::interprocess; - shared_memory_object::remove("MySharedMemory"); - try{ - //A managed shared memory where we can construct objects - //associated with a c-string - managed_shared_memory segment(create_only, - "MySharedMemory", //segment name - 65536); + //Remove shared memory on construction and destruction + struct shm_destroy + { + shm_destroy() { shared_memory_object::remove("MySharedMemory"); } + ~shm_destroy(){ shared_memory_object::remove("MySharedMemory"); } + } remover; - //Alias an STL-like allocator of ints that allocates ints from the segment - typedef allocator - ShmemAllocator; + //A managed shared memory where we can construct objects + //associated with a c-string + managed_shared_memory segment(create_only, + "MySharedMemory", //segment name + 65536); - //Alias a vector that uses the previous STL-like allocator - typedef vector MyVector; + //Alias an STL-like allocator of ints that allocates ints from the segment + typedef allocator + ShmemAllocator; - int initVal[] = {0, 1, 2, 3, 4, 5, 6 }; - const int *begVal = initVal; - const int *endVal = initVal + sizeof(initVal)/sizeof(initVal[0]); + //Alias a vector that uses the previous STL-like allocator + typedef vector MyVector; - //Initialize the STL-like allocator - const ShmemAllocator alloc_inst (segment.get_segment_manager()); + int initVal[] = {0, 1, 2, 3, 4, 5, 6 }; + const int *begVal = initVal; + const int *endVal = initVal + sizeof(initVal)/sizeof(initVal[0]); - //Construct the vector in the shared memory segment with the STL-like allocator - //from a range of iterators - MyVector *myvector = - segment.construct - ("MyVector")/*object name*/ - (begVal /*first ctor parameter*/, - endVal /*second ctor parameter*/, - alloc_inst /*third ctor parameter*/); + //Initialize the STL-like allocator + const ShmemAllocator alloc_inst (segment.get_segment_manager()); - //Use vector as your want - std::sort(myvector->rbegin(), myvector->rend()); - // . . . - //When done, destroy and delete vector from the segment - segment.destroy("MyVector"); - } - catch(...){ - shared_memory_object::remove("MySharedMemory"); - throw; - } - shared_memory_object::remove("MySharedMemory"); + //Construct the vector in the shared memory segment with the STL-like allocator + //from a range of iterators + MyVector *myvector = + segment.construct + ("MyVector")/*object name*/ + (begVal /*first ctor parameter*/, + endVal /*second ctor parameter*/, + alloc_inst /*third ctor parameter*/); + + //Use vector as your want + std::sort(myvector->rbegin(), myvector->rend()); + // . . . + //When done, destroy and delete vector from the segment + segment.destroy("MyVector"); return 0; } //] diff --git a/example/doc_contA.cpp b/example/doc_contA.cpp deleted file mode 100644 index 72812da..0000000 --- a/example/doc_contA.cpp +++ /dev/null @@ -1,60 +0,0 @@ -////////////////////////////////////////////////////////////////////////////// -// -// (C) Copyright Ion Gaztanaga 2006-2007. 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 -#include -//[doc_contA -#include -#include -#include - -int main () -{ - using namespace boost::interprocess; - try{ - //Shared memory front-end that is able to construct objects - //associated with a c-string. Erase previous shared memory with the name - //to be used and create the memory segment at the specified address and initialize resources - shared_memory_object::remove("MySharedMemory"); - managed_shared_memory segment - (create_only - ,"MySharedMemory" //segment name - ,65536); //segment size in bytes - - //Alias an STL compatible allocator of ints that allocates ints from the managed - //shared memory segment. This allocator will allow to place containers - //in managed shared memory segments - typedef allocator - ShmemAllocator; - - //Alias a vector that uses the previous STL-like allocator - typedef vector MyVector; - - //Initialize shared memory STL-compatible allocator - const ShmemAllocator alloc_inst (segment.get_segment_manager()); - - //Construct a shared memory - MyVector *myvector = - segment.construct("MyVector") //object name - (alloc_inst);//first ctor parameter - - //Insert data in the vector - for(int i = 0; i < 100; ++i){ - myvector->push_back(i); - } - } - catch(...){ - shared_memory_object::remove("MySharedMemory"); - throw; - } - shared_memory_object::remove("MySharedMemory"); - return 0; -} -//] -#include diff --git a/example/doc_contB.cpp b/example/doc_contB.cpp deleted file mode 100644 index 4aad144..0000000 --- a/example/doc_contB.cpp +++ /dev/null @@ -1,57 +0,0 @@ -////////////////////////////////////////////////////////////////////////////// -// -// (C) Copyright Ion Gaztanaga 2006-2007. 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 -#include -//[doc_contB -#include -#include -#include -#include - -int main () -{ - using namespace boost::interprocess; - try{ - //A special shared memory where we can - //construct objects associated with a name. - //Connect to the already created shared memory segment - //and initialize needed resources - managed_shared_memory segment - (open_only - ,"MySharedMemory"); //segment name - - //Alias an STL compatible allocator of ints that allocates ints from the managed - //shared memory segment. This allocator will allow to place containers - //in managed shared memory segments - typedef allocator - ShmemAllocator; - - //Alias a vector that uses the previous STL-like allocator - typedef vector MyVector; - - //Find the vector using the c-string name - MyVector *myvector = segment.find("MyVector").first; - - //Use vector in reverse order - std::sort(myvector->rbegin(), myvector->rend()); - // . . . - - //When done, destroy the vector from the segment - segment.destroy("MyVector"); - } - catch(...){ - shared_memory_object::remove("MySharedMemory"); - throw; - } - shared_memory_object::remove("MySharedMemory"); - return 0; -} -//] -#include diff --git a/example/doc_file_mapping.cpp b/example/doc_file_mapping.cpp index 568f577..3286cef 100644 --- a/example/doc_file_mapping.cpp +++ b/example/doc_file_mapping.cpp @@ -13,35 +13,36 @@ #include #include #include +#include +#include #include #include -#include //std::remove +#include -int main () +int main(int argc, char *argv[]) { using namespace boost::interprocess; - try{ - //Create a file - std::filebuf fbuf; - fbuf.open("file.bin", std::ios_base::in | std::ios_base::out - | std::ios_base::trunc | std::ios_base::binary); + const std::size_t FileSize = 10000; + if(argc == 1){ //Parent process executes this + { //Create a file + std::filebuf fbuf; + fbuf.open("file.bin", std::ios_base::in | std::ios_base::out + | std::ios_base::trunc | std::ios_base::binary); + //Set the size + fbuf.pubseekoff(FileSize-1, std::ios_base::beg); + fbuf.sputc(0); + } + //Remove file on exit + struct file_remove + { + ~file_remove (){ file_mapping::remove("file.bin"); } + } destroy_on_exit; - //Set the size - fbuf.pubseekoff(9999, std::ios_base::beg); - fbuf.sputc(0); - fbuf.close(); - - //Create a file mapping. + //Create a file mapping file_mapping m_file("file.bin", read_write); - //Map the whole file in this process - mapped_region region - (m_file //What to map - ,read_write //Map it as read-write - ); - - if(region.get_size() != 10000) - return 1; + //Map the whole file with read-write permissions in this process + mapped_region region(m_file, read_write); //Get the address of the mapped region void * addr = region.get_address(); @@ -50,12 +51,42 @@ int main () //Write all the memory to 1 std::memset(addr, 1, size); + //Launch child process + std::string s(argv[0]); s += " child"; + if(0 != std::system(s.c_str())) + return 1; } - catch(interprocess_exception &ex){ - std::remove("file.bin"); - std::cout << ex.what() << std::endl; - return 1; + else{ //Child process executes this + { //Open the file mapping and map it as read-only + file_mapping m_file ("file.bin", read_only); + mapped_region region(m_file, read_only); + + //Get the address of the mapped region + void * addr = region.get_address(); + std::size_t size = region.get_size(); + + //Check that memory was initialized to 1 + const char *mem = static_cast(addr); + for(std::size_t i = 0; i < size; ++i) + if(*mem++ != 1) + return 1; //Error checking memory + } + { //Now test it reading the file + std::filebuf fbuf; + fbuf.open("file.bin", std::ios_base::in | std::ios_base::binary); + + //Read it to memory + std::vector vect(FileSize, 0); + fbuf.sgetn(&vect[0], std::streamsize(vect.size())); + + //Check that memory was initialized to 1 + const char *mem = static_cast(&vect[0]); + for(std::size_t i = 0; i < FileSize; ++i) + if(*mem++ != 1) + return 1; //Error checking memory + } } + return 0; } //] diff --git a/example/doc_file_mapping2.cpp b/example/doc_file_mapping2.cpp deleted file mode 100644 index 058963f..0000000 --- a/example/doc_file_mapping2.cpp +++ /dev/null @@ -1,74 +0,0 @@ -////////////////////////////////////////////////////////////////////////////// -// -// (C) Copyright Ion Gaztanaga 2006-2007. 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 -//[doc_file_mapping2 -#include -#include -#include -#include -#include -#include //std::remove -#include - -int main () -{ - using namespace boost::interprocess; - try{ - //Open the file mapping - file_mapping m_file ("file.bin", read_only); - - //Map the whole file in this process - mapped_region region - (m_file //What to map - ,read_only //Map it as read-only - ); - - //Get the address of the mapped region - void * addr = region.get_address(); - std::size_t size = region.get_size(); - - //Check that memory was initialized to 1 - const char *mem = static_cast(addr); - for(std::size_t i = 0; i < size; ++i){ - if(*mem++ != 1){ - std::cout << "Error checking memory!" << std::endl; - return 1; - } - } - - //Now test it reading the file - std::filebuf fbuf; - fbuf.open("file.bin", std::ios_base::in | std::ios_base::binary); - - //Read it to memory - std::vector vect(region.get_size(), 0); - fbuf.sgetn(&vect[0], std::streamsize(vect.size())); - - //Check that memory was initialized to 1 - mem = static_cast(&vect[0]); - for(std::size_t i = 0; i < size; ++i){ - if(*mem++ != 1){ - std::cout << "Error checking memory!" << std::endl; - return 1; - } - } - - std::cout << "Test successful!" << std::endl; - } - catch(interprocess_exception &ex){ - std::remove("file.bin"); - std::cout << "Unexpected exception: " << ex.what() << std::endl; - return 1; - } - std::remove("file.bin"); - return 0; -} -//] -#include diff --git a/example/doc_intrusive.cpp b/example/doc_intrusive.cpp index 1f898ad..1548959 100644 --- a/example/doc_intrusive.cpp +++ b/example/doc_intrusive.cpp @@ -7,6 +7,7 @@ // See http://www.boost.org/libs/interprocess for documentation. // ////////////////////////////////////////////////////////////////////////////// + #include #include //[doc_intrusive @@ -68,42 +69,40 @@ class intrusive_ptr_owner : m_intrusive_ptr(ptr){} }; -int main () +int main() { - shared_memory_object::remove("my_shmem"); + //Remove shared memory on construction and destruction + struct shm_destroy + { + shm_destroy() { shared_memory_object::remove("MySharedMemory"); } + ~shm_destroy(){ shared_memory_object::remove("MySharedMemory"); } + } remover; - try{ - //Create shared memory - managed_shared_memory shmem(create_only, "my_shmem", 10000); + //Create shared memory + managed_shared_memory shmem(create_only, "MySharedMemory", 10000); - //Create the unique reference counted object in shared memory - N::reference_counted_class *ref_counted = - shmem.construct - ("ref_counted")(shmem.get_segment_manager()); + //Create the unique reference counted object in shared memory + N::reference_counted_class *ref_counted = + shmem.construct + ("ref_counted")(shmem.get_segment_manager()); - //Create an array of ten intrusive pointer owners in shared memory - intrusive_ptr_owner *intrusive_owner_array = - shmem.construct - (anonymous_instance)[10](ref_counted); + //Create an array of ten intrusive pointer owners in shared memory + intrusive_ptr_owner *intrusive_owner_array = + shmem.construct + (anonymous_instance)[10](ref_counted); - //Now test that reference count is ten - if(ref_counted->use_count() != 10) - return 1; + //Now test that reference count is ten + if(ref_counted->use_count() != 10) + return 1; - //Now destroy the array of intrusive pointer owners - //This should destroy every intrusive_ptr and because of - //that reference_counted_class will be destroyed - shmem.destroy_ptr(intrusive_owner_array); + //Now destroy the array of intrusive pointer owners + //This should destroy every intrusive_ptr and because of + //that reference_counted_class will be destroyed + shmem.destroy_ptr(intrusive_owner_array); - //Now the reference counted object should have been destroyed - if(shmem.find("ref_counted").first) - return 1; - } - catch(...){ - shared_memory_object::remove("my_shmem"); - throw; - } - shared_memory_object::remove("my_shmem"); + //Now the reference counted object should have been destroyed + if(shmem.find("ref_counted").first) + return 1; //Success! return 0; } diff --git a/example/doc_ipc_message.cpp b/example/doc_ipc_message.cpp new file mode 100644 index 0000000..edceb85 --- /dev/null +++ b/example/doc_ipc_message.cpp @@ -0,0 +1,72 @@ +////////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2006-2007. 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 +#include +//[run_ipc_message +#include +#include //std::system +#include + +int main (int argc, char *argv[]) +{ + using namespace boost::interprocess; + if(argc == 1){ //Parent process + //Remove shared memory on construction and destruction + struct shm_remove + { + shm_remove() { shared_memory_object::remove("MySharedMemory"); } + ~shm_remove(){ shared_memory_object::remove("MySharedMemory"); } + } remover; + + //Create a managed shared memory segment + managed_shared_memory segment(create_only, "MySharedMemory", 65536); + + //Allocate a portion of the segment (raw memory) + std::size_t free_memory = segment.get_free_memory(); + void * shptr = segment.allocate(1024/*bytes to allocate*/); + + //Check invariant + if(free_memory <= segment.get_free_memory()) + return 1; + + //An handle from the base address can identify any byte of the shared + //memory segment even if it is mapped in different base addresses + managed_shared_memory::handle_t handle = segment.get_handle_from_address(shptr); + std::stringstream s; + s << argv[0] << " " << handle << std::ends; + + //Launch child process + if(0 != std::system(s.str().c_str())) + return 1; + //Check memory has been freed + if(free_memory != segment.get_free_memory()) + return 1; + } + else{ + //Open managed segment + managed_shared_memory segment(open_only, "MySharedMemory"); + + //An handle from the base address can identify any byte of the shared + //memory segment even if it is mapped in different base addresses + managed_shared_memory::handle_t handle = 0; + + //Obtain handle value + std::stringstream s; s << argv[1]; s >> handle; + + //Get buffer local address from handle + void *msg = segment.get_address_from_handle(handle); + + //Deallocate previously allocated memory + segment.deallocate(msg); + } + return 0; +} +//] +#include diff --git a/example/doc_ipc_messageA.cpp b/example/doc_ipc_messageA.cpp deleted file mode 100644 index 3a730f1..0000000 --- a/example/doc_ipc_messageA.cpp +++ /dev/null @@ -1,55 +0,0 @@ -////////////////////////////////////////////////////////////////////////////// -// -// (C) Copyright Ion Gaztanaga 2006-2007. 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 -#include -//[doc_ipc_messageA -#include - -int main () -{ - using namespace boost::interprocess; - - //A special shared memory from which we are - //able to allocate raw memory buffers. - //First remove any old shared memory of the same name, create - //the shared memory segment and initialize needed resources - shared_memory_object::remove("MySharedMemory"); - try{ - managed_shared_memory segment - (create_only, - "MySharedMemory", //segment name - 65536); //segment size in bytes - - //Allocate a portion of the segment - void * shptr = segment.allocate(1024/*bytes to allocate*/); - - //An handle from the base address can identify any byte of the shared - //memory segment even if it is mapped in different base addresses - managed_shared_memory::handle_t handle = segment.get_handle_from_address(shptr); - (void)handle; - // Copy message to buffer - // . . . - // Send handle to other process - // . . . - // Wait response from other process - // . . . - - //Deallocate the portion previously allocated - segment.deallocate(shptr); - } - catch(...){ - shared_memory_object::remove("MySharedMemory"); - throw; - } - shared_memory_object::remove("MySharedMemory"); - return 0; -} -//] -#include diff --git a/example/doc_ipc_messageB.cpp b/example/doc_ipc_messageB.cpp deleted file mode 100644 index 2c30d1a..0000000 --- a/example/doc_ipc_messageB.cpp +++ /dev/null @@ -1,47 +0,0 @@ -////////////////////////////////////////////////////////////////////////////// -// -// (C) Copyright Ion Gaztanaga 2006-2007. 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 -#include -//[doc_ipc_messageB -#include - -int main () -{ - using namespace boost::interprocess; - - try{ - //A special shared memory from which we are - //able to allocate raw memory buffers. - //Connect to the already created shared memory segment - //and initialize needed resources - managed_shared_memory segment(open_only, "MySharedMemory"); //segment name - - //An handle from the base address can identify any byte of the shared - //memory segment even if it is mapped in different base addresses - managed_shared_memory::handle_t handle = 0; - - //Wait handle msg from the other process and put it in - //"handle" local variable - //Get buffer local address from handle - void *msg = segment.get_address_from_handle(handle); - (void)msg; - //Do anything with msg - //. . . - //Send ack to sender process - } - catch(...){ - shared_memory_object::remove("MySharedMemory"); - throw; - } - shared_memory_object::remove("MySharedMemory"); - return 0; -} -//] -#include diff --git a/example/doc_managed_aligned_allocation.cpp b/example/doc_managed_aligned_allocation.cpp index 2af9266..f94f569 100644 --- a/example/doc_managed_aligned_allocation.cpp +++ b/example/doc_managed_aligned_allocation.cpp @@ -16,53 +16,52 @@ int main() { using namespace boost::interprocess; + //Remove shared memory on construction and destruction + struct shm_destroy + { + shm_destroy() { shared_memory_object::remove("MySharedMemory"); } + ~shm_destroy(){ shared_memory_object::remove("MySharedMemory"); } + } remover; + //Managed memory segment that allocates portions of a shared memory //segment with the default management algorithm - shared_memory_object::remove("MyManagedShm"); + managed_shared_memory managed_shm(create_only, "MySharedMemory", 65536); - try{ - managed_shared_memory managed_shm(create_only, "MyManagedShm", 65536); + const std::size_t Alignment = 128; - const std::size_t Alignment = 128; + //Allocate 100 bytes aligned to Alignment from segment, throwing version + void *ptr = managed_shm.allocate_aligned(100, Alignment); - //Allocate 100 bytes aligned to Alignment from segment, throwing version - void *ptr = managed_shm.allocate_aligned(100, Alignment); + //Check alignment + assert((static_cast(ptr)-static_cast(0)) % Alignment == 0); - //Check alignment - assert((static_cast(ptr)-static_cast(0)) % Alignment == 0); + //Deallocate it + managed_shm.deallocate(ptr); - //Deallocate it - managed_shm.deallocate(ptr); + //Non throwing version + ptr = managed_shm.allocate_aligned(100, Alignment, std::nothrow); - //Non throwing version - ptr = managed_shm.allocate_aligned(100, Alignment, std::nothrow); + //Check alignment + assert((static_cast(ptr)-static_cast(0)) % Alignment == 0); - //Check alignment - assert((static_cast(ptr)-static_cast(0)) % Alignment == 0); + //Deallocate it + managed_shm.deallocate(ptr); - //Deallocate it - managed_shm.deallocate(ptr); + //If we want to efficiently allocate aligned blocks of memory + //use managed_shared_memory::PayloadPerAllocation value + assert(Alignment > managed_shared_memory::PayloadPerAllocation); - //If we want to efficiently allocate aligned blocks of memory - //use managed_shared_memory::PayloadPerAllocation value - assert(Alignment > managed_shared_memory::PayloadPerAllocation); + //This allocation will maximize the size of the aligned memory + //and will increase the possibility of finding more aligned memory + ptr = managed_shm.allocate_aligned + (3*Alignment - managed_shared_memory::PayloadPerAllocation, Alignment); - //This allocation will maximize the size of the aligned memory - //and will increase the possibility of finding more aligned memory - ptr = managed_shm.allocate_aligned - (3*Alignment - managed_shared_memory::PayloadPerAllocation, Alignment); + //Check alignment + assert((static_cast(ptr)-static_cast(0)) % Alignment == 0); - //Check alignment - assert((static_cast(ptr)-static_cast(0)) % Alignment == 0); + //Deallocate it + managed_shm.deallocate(ptr); - //Deallocate it - managed_shm.deallocate(ptr); - } - catch(...){ - shared_memory_object::remove("MyManagedShm"); - throw; - } - shared_memory_object::remove("MyManagedShm"); return 0; } //] diff --git a/example/doc_managed_allocation_command.cpp b/example/doc_managed_allocation_command.cpp index b77f838..8023c6d 100644 --- a/example/doc_managed_allocation_command.cpp +++ b/example/doc_managed_allocation_command.cpp @@ -16,73 +16,71 @@ int main() { using namespace boost::interprocess; + //Remove shared memory on construction and destruction + struct shm_destroy + { + shm_destroy() { shared_memory_object::remove("MySharedMemory"); } + ~shm_destroy(){ shared_memory_object::remove("MySharedMemory"); } + } remover; + //Managed memory segment that allocates portions of a shared memory //segment with the default management algorithm - shared_memory_object::remove("MyManagedShm"); + managed_shared_memory managed_shm(create_only, "MySharedMemory", 10000*sizeof(std::size_t)); - try{ - managed_shared_memory managed_shm(create_only, "MyManagedShm", 10000*sizeof(std::size_t)); + //Allocate at least 100 bytes, 1000 bytes if possible + std::size_t received_size, min_size = 100, preferred_size = 1000; + std::size_t *ptr = managed_shm.allocation_command + (boost::interprocess::allocate_new, min_size, preferred_size, received_size).first; - //Allocate at least 100 bytes, 1000 bytes if possible - std::size_t received_size, min_size = 100, preferred_size = 1000; - std::size_t *ptr = managed_shm.allocation_command - (allocate_new, min_size, preferred_size, received_size).first; + //Received size must be bigger than min_size + assert(received_size >= min_size); - //Received size must be bigger than min_size - assert(received_size >= min_size); + //Get free memory + std::size_t free_memory_after_allocation = managed_shm.get_free_memory(); - //Get free memory - std::size_t free_memory_after_allocation = managed_shm.get_free_memory(); + //Now write the data + for(std::size_t i = 0; i < received_size; ++i) ptr[i] = i; - //Now write the data - for(std::size_t i = 0; i < received_size; ++i) ptr[i] = i; + //Now try to triplicate the buffer. We won't admit an expansion + //lower to the double of the original buffer. + //This "should" be successful since no other class is allocating + //memory from the segment + std::size_t expanded_size; + std::pair ret = managed_shm.allocation_command + (boost::interprocess::expand_fwd, received_size*2, received_size*3, expanded_size, ptr); - //Now try to triplicate the buffer. We won't admit an expansion - //lower to the double of the original buffer. - //This "should" be successful since no other class is allocating - //memory from the segment - std::size_t expanded_size; - std::pair ret = managed_shm.allocation_command - (expand_fwd, received_size*2, received_size*3, expanded_size, ptr); + //Check invariants + assert(ret.second == true); + assert(ret.first == ptr); + assert(expanded_size >= received_size*2); - //Check invariants - assert(ret.second == true); - assert(ret.first == ptr); - assert(expanded_size >= received_size*2); + //Get free memory and compare + std::size_t free_memory_after_expansion = managed_shm.get_free_memory(); + assert(free_memory_after_expansion < free_memory_after_allocation); - //Get free memory and compare - std::size_t free_memory_after_expansion = managed_shm.get_free_memory(); - assert(free_memory_after_expansion < free_memory_after_allocation); + //Write new values + for(std::size_t i = received_size; i < expanded_size; ++i) ptr[i] = i; - //Write new values - for(std::size_t i = received_size; i < expanded_size; ++i) ptr[i] = i; + //Try to shrink approximately to min_size, but the new size + //should be smaller than min_size*2. + //This "should" be successful since no other class is allocating + //memory from the segment + std::size_t shrunk_size; + ret = managed_shm.allocation_command + (boost::interprocess::shrink_in_place, min_size*2, min_size, shrunk_size, ptr); - //Try to shrink approximately to min_size, but the new size - //should be smaller than min_size*2. - //This "should" be successful since no other class is allocating - //memory from the segment - std::size_t shrunk_size; - ret = managed_shm.allocation_command - (shrink_in_place, min_size*2, min_size, shrunk_size, ptr); + //Check invariants + assert(ret.second == true); + assert(ret.first == ptr); + assert(shrunk_size <= min_size*2); + assert(shrunk_size >= min_size); - //Check invariants - assert(ret.second == true); - assert(ret.first == ptr); - assert(shrunk_size <= min_size*2); - assert(shrunk_size >= min_size); + //Get free memory and compare + std::size_t free_memory_after_shrinking = managed_shm.get_free_memory(); + assert(free_memory_after_shrinking > free_memory_after_expansion); - //Get free memory and compare - std::size_t free_memory_after_shrinking = managed_shm.get_free_memory(); - assert(free_memory_after_shrinking > free_memory_after_expansion); - - //Deallocate the buffer - managed_shm.deallocate(ptr); - } - catch(...){ - shared_memory_object::remove("MyManagedShm"); - throw; - } - shared_memory_object::remove("MyManagedShm"); + //Deallocate the buffer + managed_shm.deallocate(ptr); return 0; } //] diff --git a/example/doc_managed_construction_info.cpp b/example/doc_managed_construction_info.cpp index 8a3f711..f573181 100644 --- a/example/doc_managed_construction_info.cpp +++ b/example/doc_managed_construction_info.cpp @@ -21,41 +21,39 @@ class my_class int main() { using namespace boost::interprocess; - typedef managed_shared_memory msm; - shared_memory_object::remove("MyManagedShm"); - try{ - msm managed_shm(create_only, "MyManagedShm", 10000*sizeof(std::size_t)); + //Remove shared memory on construction and destruction + struct shm_destroy + { + shm_destroy() { shared_memory_object::remove("MySharedMemory"); } + ~shm_destroy(){ shared_memory_object::remove("MySharedMemory"); } + } remover; - //Construct objects - my_class *named_object = managed_shm.construct("Object name")[1](); - my_class *unique_object = managed_shm.construct(unique_instance)[2](); - my_class *anon_object = managed_shm.construct(anonymous_instance)[3](); + managed_shared_memory managed_shm(create_only, "MySharedMemory", 10000*sizeof(std::size_t)); - //Now test "get_instance_name" function. - assert(0 == std::strcmp(msm::get_instance_name(named_object), "Object name")); - assert(0 == msm::get_instance_name(unique_object)); - assert(0 == msm::get_instance_name(anon_object)); + //Construct objects + my_class *named_object = managed_shm.construct("Object name")[1](); + my_class *unique_object = managed_shm.construct(unique_instance)[2](); + my_class *anon_object = managed_shm.construct(anonymous_instance)[3](); - //Now test "get_instance_type" function. - assert(named_type == msm::get_instance_type(named_object)); - assert(unique_type == msm::get_instance_type(unique_object)); - assert(anonymous_type == msm::get_instance_type(anon_object)); + //Now test "get_instance_name" function. + assert(0 == std::strcmp(managed_shared_memory::get_instance_name(named_object), "Object name")); + assert(0 == managed_shared_memory::get_instance_name(unique_object)); + assert(0 == managed_shared_memory::get_instance_name(anon_object)); - //Now test "get_instance_length" function. - assert(1 == msm::get_instance_length(named_object)); - assert(2 == msm::get_instance_length(unique_object)); - assert(3 == msm::get_instance_length(anon_object)); + //Now test "get_instance_type" function. + assert(named_type == managed_shared_memory::get_instance_type(named_object)); + assert(unique_type == managed_shared_memory::get_instance_type(unique_object)); + assert(anonymous_type == managed_shared_memory::get_instance_type(anon_object)); - managed_shm.destroy_ptr(named_object); - managed_shm.destroy_ptr(unique_object); - managed_shm.destroy_ptr(anon_object); - } - catch(...){ - shared_memory_object::remove("MyManagedShm"); - throw; - } - shared_memory_object::remove("MyManagedShm"); + //Now test "get_instance_length" function. + assert(1 == managed_shared_memory::get_instance_length(named_object)); + assert(2 == managed_shared_memory::get_instance_length(unique_object)); + assert(3 == managed_shared_memory::get_instance_length(anon_object)); + + managed_shm.destroy_ptr(named_object); + managed_shm.destroy_ptr(unique_object); + managed_shm.destroy_ptr(anon_object); return 0; } //] diff --git a/example/doc_managed_copy_on_write.cpp b/example/doc_managed_copy_on_write.cpp index 304be95..7daa76e 100644 --- a/example/doc_managed_copy_on_write.cpp +++ b/example/doc_managed_copy_on_write.cpp @@ -11,7 +11,6 @@ //[doc_managed_copy_on_write #include #include //std::fstream -#include //std::remove #include //std::distance int main() @@ -19,8 +18,8 @@ int main() using namespace boost::interprocess; //Try to erase any previous managed segment with the same name - std::remove("MyManagedFile"); - std::remove("MyManagedFile2"); + file_mapping::remove("MyManagedFile"); + file_mapping::remove("MyManagedFile2"); remove_file_on_destroy destroyer1("MyManagedFile"); remove_file_on_destroy destroyer2("MyManagedFile2"); diff --git a/example/doc_managed_external_buffer.cpp b/example/doc_managed_external_buffer.cpp index 051b430..f9e9855 100644 --- a/example/doc_managed_external_buffer.cpp +++ b/example/doc_managed_external_buffer.cpp @@ -43,7 +43,9 @@ int main() //be stored in the static_buffer! MyBufferList *list = objects_in_static_memory.construct(L"MyList") (objects_in_static_memory.get_segment_manager()); - + //<- + (void)list; + //-> //Since the allocation algorithm from wmanaged_external_buffer uses relative //pointers and all the pointers constructed int the static memory point //to objects in the same segment, we can create another static buffer diff --git a/example/doc_managed_grow.cpp b/example/doc_managed_grow.cpp index ee7a31e..1523222 100644 --- a/example/doc_managed_grow.cpp +++ b/example/doc_managed_grow.cpp @@ -21,48 +21,49 @@ class MyClass int main() { using namespace boost::interprocess; - try{ - { //Remove old shared memory if present - shared_memory_object::remove("MyManagedShm"); - //Create a managed shared memory - managed_shared_memory shm(create_only, "MyManagedShm", 1000); - //Check size - assert(shm.get_size() == 1000); - //Construct a named object - MyClass *myclass = shm.construct("MyClass")(); - //The managed segment is unmapped here - } - { - //Now that the segment is not mapped grow it adding extra 500 bytes - managed_shared_memory::grow("MyManagedShm", 500); - //Map it again - managed_shared_memory shm(open_only, "MyManagedShm"); - //Check size - assert(shm.get_size() == 1500); - //Check "MyClass" is still there - MyClass *myclass = shm.find("MyClass").first; - assert(myclass != 0); - //The managed segment is unmapped here - } - { - //Now minimize the size of the segment - managed_shared_memory::shrink_to_fit("MyManagedShm"); - //Map it again - managed_shared_memory shm(open_only, "MyManagedShm"); - //Check size - assert(shm.get_size() < 1000); - //Check "MyClass" is still there - MyClass *myclass = shm.find("MyClass").first; - assert(myclass != 0); - //The managed segment is unmapped here - } + //Remove shared memory on construction and destruction + struct shm_destroy + { + shm_destroy() { shared_memory_object::remove("MySharedMemory"); } + ~shm_destroy(){ shared_memory_object::remove("MySharedMemory"); } + } remover; + + { + //Create a managed shared memory + managed_shared_memory shm(create_only, "MySharedMemory", 1000); + //Check size + assert(shm.get_size() == 1000); + //Construct a named object + MyClass *myclass = shm.construct("MyClass")(); + //The managed segment is unmapped here + //<- + (void)myclass; + //-> } - catch(...){ - shared_memory_object::remove("MyManagedShm"); - throw; + { + //Now that the segment is not mapped grow it adding extra 500 bytes + managed_shared_memory::grow("MySharedMemory", 500); + //Map it again + managed_shared_memory shm(open_only, "MySharedMemory"); + //Check size + assert(shm.get_size() == 1500); + //Check "MyClass" is still there + MyClass *myclass = shm.find("MyClass").first; + assert(myclass != 0); + //The managed segment is unmapped here + } + { + //Now minimize the size of the segment + managed_shared_memory::shrink_to_fit("MySharedMemory"); + //Map it again + managed_shared_memory shm(open_only, "MySharedMemory"); + //Check size + assert(shm.get_size() < 1000); + //Check "MyClass" is still there + MyClass *myclass = shm.find("MyClass").first; + assert(myclass != 0); + //The managed segment is unmapped here } - //Remove the managed segment - shared_memory_object::remove("MyManagedShm"); return 0; } //] diff --git a/example/doc_managed_mapped_file.cpp b/example/doc_managed_mapped_file.cpp index 2dacbd0..091a7eb 100644 --- a/example/doc_managed_mapped_file.cpp +++ b/example/doc_managed_mapped_file.cpp @@ -24,59 +24,67 @@ int main () { const char *FileName = "file_mapping"; const std::size_t FileSize = 1000; - std::remove(FileName); + file_mapping::remove(FileName); try{ - managed_mapped_file mfile_memory(create_only, FileName, FileSize); - MyList * mylist = mfile_memory.construct("MyList") - (mfile_memory.get_segment_manager()); + std::size_t old_size = 0; + managed_mapped_file::handle_t list_handle; + { + managed_mapped_file mfile_memory(create_only, FileName, FileSize); + MyList *mylist = mfile_memory.construct("MyList") + (mfile_memory.get_segment_manager()); - //Obtain handle, that identifies the list in the buffer - managed_mapped_file::handle_t list_handle = mfile_memory.get_handle_from_address(mylist); + //Obtain handle, that identifies the list in the buffer + list_handle = mfile_memory.get_handle_from_address(mylist); - //Fill list until there is no more room in the file - try{ - while(1) { - mylist->insert(mylist->begin(), 0); + //Fill list until there is no more room in the file + try{ + while(1) { + mylist->insert(mylist->begin(), 0); + } } + catch(const bad_alloc &){ + //mapped file is full + } + //Let's obtain the size of the list + old_size = mylist->size(); } - catch(const bad_alloc &){ - //mapped file is full - } - //Let's obtain the size of the list - std::size_t old_size = mylist->size(); - //To make the list bigger, let's increase the mapped file //in FileSize bytes more. - //mfile_memory.grow(FileSize); + managed_mapped_file::grow(FileName, FileSize*2); - //If mapping address has changed, the old pointer is invalid, - //so use previously obtained handle to find the new pointer. - mylist = static_cast - (mfile_memory.get_address_from_handle(list_handle)); - - //Fill list until there is no more room in the file - try{ - while(1) { - mylist->insert(mylist->begin(), 0); + { + managed_mapped_file mfile_memory(open_only, FileName); + + + //If mapping address has changed, the old pointer is invalid, + //so use previously obtained handle to find the new pointer. + MyList *mylist = static_cast + (mfile_memory.get_address_from_handle(list_handle)); + + //Fill list until there is no more room in the file + try{ + while(1) { + mylist->insert(mylist->begin(), 0); + } } + catch(const bad_alloc &){ + //mapped file is full + } + + //Let's obtain the new size of the list + std::size_t new_size = mylist->size(); + + assert(new_size > old_size); + + //Destroy list + mfile_memory.destroy_ptr(mylist); } - catch(const bad_alloc &){ - //mapped file is full - } - - //Let's obtain the new size of the list - std::size_t new_size = mylist->size(); - - assert(new_size > old_size); - - //Destroy list - mfile_memory.destroy_ptr(mylist); } catch(...){ - std::remove(FileName); + file_mapping::remove(FileName); throw; } - std::remove(FileName); + file_mapping::remove(FileName); return 0; } diff --git a/example/doc_managed_multiple_allocation.cpp b/example/doc_managed_multiple_allocation.cpp index 3d508cf..e1ac02f 100644 --- a/example/doc_managed_multiple_allocation.cpp +++ b/example/doc_managed_multiple_allocation.cpp @@ -10,69 +10,59 @@ #include //[doc_managed_multiple_allocation #include +#include //boost::interprocess::move #include //assert #include //std::memset #include //std::nothrow #include //std::vector + int main() { using namespace boost::interprocess; - typedef managed_shared_memory::multiallocation_iterator multiallocation_iterator; + typedef managed_shared_memory::multiallocation_chain multiallocation_chain; - //Try to erase any previous managed segment with the same name - shared_memory_object::remove("MyManagedShm"); + //Remove shared memory on construction and destruction + struct shm_destroy + { + shm_destroy() { shared_memory_object::remove("MySharedMemory"); } + ~shm_destroy(){ shared_memory_object::remove("MySharedMemory"); } + } remover; - try{ - managed_shared_memory managed_shm(create_only, "MyManagedShm", 65536); + managed_shared_memory managed_shm(create_only, "MySharedMemory", 65536); - //Allocate 16 elements of 100 bytes in a single call. Non-throwing version. - multiallocation_iterator beg_it = managed_shm.allocate_many(100, 16, std::nothrow); + //Allocate 16 elements of 100 bytes in a single call. Non-throwing version. + multiallocation_chain chain(managed_shm.allocate_many(100, 16, std::nothrow)); - //To check for an error, we can use a boolean expression - //or compare it with a default constructed iterator - assert(!beg_it == (beg_it == multiallocation_iterator())); - - //Check if the memory allocation was successful - if(!beg_it) return 1; + //Check if the memory allocation was successful + if(chain.empty()) return 1; - //Allocated buffers - std::vector allocated_buffers; + //Allocated buffers + std::vector allocated_buffers; - //Initialize our data - for( multiallocation_iterator it = beg_it, end_it; it != end_it; ){ - allocated_buffers.push_back(&*it); - //The iterator must be incremented before overwriting memory - //because otherwise, the iterator is invalidated. - std::memset(&*it++, 0, 100); - } - - //Now deallocate - while(!allocated_buffers.empty()){ - managed_shm.deallocate(allocated_buffers.back()); - allocated_buffers.pop_back(); - } - - //Allocate 10 buffers of different sizes in a single call. Throwing version - std::size_t sizes[10]; - for(std::size_t i = 0; i < 10; ++i) - sizes[i] = i*3; - - beg_it = managed_shm.allocate_many(sizes, 10); - - //Iterate each allocated buffer and deallocate - //The "end" condition can be also checked with operator! - for(multiallocation_iterator it = beg_it; it;){ - //The iterator must be incremented before overwriting memory - //because otherwise, the iterator is invalidated. - managed_shm.deallocate(&*it++); - } + //Initialize our data + while(!chain.empty()){ + void *buf = chain.front(); + chain.pop_front(); + allocated_buffers.push_back(buf); + //The iterator must be incremented before overwriting memory + //because otherwise, the iterator is invalidated. + std::memset(buf, 0, 100); } - catch(...){ - shared_memory_object::remove("MyManagedShm"); - throw; + + //Now deallocate + while(!allocated_buffers.empty()){ + managed_shm.deallocate(allocated_buffers.back()); + allocated_buffers.pop_back(); } - shared_memory_object::remove("MyManagedShm"); + + //Allocate 10 buffers of different sizes in a single call. Throwing version + std::size_t sizes[10]; + for(std::size_t i = 0; i < 10; ++i) + sizes[i] = i*3; + + chain = managed_shm.allocate_many(sizes, 10); + managed_shm.deallocate_many(boost::interprocess::move(chain)); return 0; } //] diff --git a/example/doc_managed_raw_allocation.cpp b/example/doc_managed_raw_allocation.cpp index 0c31b12..ac7cf24 100644 --- a/example/doc_managed_raw_allocation.cpp +++ b/example/doc_managed_raw_allocation.cpp @@ -15,29 +15,28 @@ int main() { using namespace boost::interprocess; + //Remove shared memory on construction and destruction + struct shm_destroy + { + shm_destroy() { shared_memory_object::remove("MySharedMemory"); } + ~shm_destroy(){ shared_memory_object::remove("MySharedMemory"); } + } remover; + //Managed memory segment that allocates portions of a shared memory //segment with the default management algorithm - shared_memory_object::remove("MyManagedShm"); - try{ - managed_shared_memory managed_shm(create_only, "MyManagedShm", 65536); + managed_shared_memory managed_shm(create_only, "MySharedMemory", 65536); - //Allocate 100 bytes of memory from segment, throwing version - void *ptr = managed_shm.allocate(100); + //Allocate 100 bytes of memory from segment, throwing version + void *ptr = managed_shm.allocate(100); - //Deallocate it - managed_shm.deallocate(ptr); + //Deallocate it + managed_shm.deallocate(ptr); - //Non throwing version - ptr = managed_shm.allocate(100, std::nothrow); + //Non throwing version + ptr = managed_shm.allocate(100, std::nothrow); - //Deallocate it - managed_shm.deallocate(ptr); - } - catch(...){ - shared_memory_object::remove("MyManagedShm"); - throw; - } - shared_memory_object::remove("MyManagedShm"); + //Deallocate it + managed_shm.deallocate(ptr); return 0; } //] diff --git a/example/doc_map.cpp b/example/doc_map.cpp index 5a7da62..a1b2b14 100644 --- a/example/doc_map.cpp +++ b/example/doc_map.cpp @@ -19,56 +19,55 @@ int main () { using namespace boost::interprocess; + + //Remove shared memory on construction and destruction + struct shm_destroy + { + shm_destroy() { shared_memory_object::remove("MySharedMemory"); } + ~shm_destroy(){ shared_memory_object::remove("MySharedMemory"); } + } remover; + //Shared memory front-end that is able to construct objects //associated with a c-string. Erase previous shared memory with the name //to be used and create the memory segment at the specified address and initialize resources - shared_memory_object::remove("MySharedMemory"); + managed_shared_memory segment + (create_only + ,"MySharedMemory" //segment name + ,65536); //segment size in bytes - try{ - managed_shared_memory segment - (create_only - ,"MySharedMemory" //segment name - ,65536); //segment size in bytes + //Note that map's value_type is std::pair, + //so the allocator must allocate that pair. + typedef int KeyType; + typedef float MappedType; + typedef std::pair ValueType; - //Note that map's value_type is std::pair, - //so the allocator must allocate that pair. - typedef int KeyType; - typedef float MappedType; - typedef std::pair ValueType; + //Alias an STL compatible allocator of for the map. + //This allocator will allow to place containers + //in managed shared memory segments + typedef allocator + ShmemAllocator; - //Alias an STL compatible allocator of for the map. - //This allocator will allow to place containers - //in managed shared memory segments - typedef allocator - ShmemAllocator; + //Alias a map of ints that uses the previous STL-like allocator. + //Note that the third parameter argument is the ordering function + //of the map, just like with std::map, used to compare the keys. + typedef map, ShmemAllocator> MyMap; - //Alias a map of ints that uses the previous STL-like allocator. - //Note that the third parameter argument is the ordering function - //of the map, just like with std::map, used to compare the keys. - typedef map, ShmemAllocator> MyMap; + //Initialize the shared memory STL-compatible allocator + ShmemAllocator alloc_inst (segment.get_segment_manager()); - //Initialize the shared memory STL-compatible allocator - ShmemAllocator alloc_inst (segment.get_segment_manager()); + //Construct a shared memory map. + //Note that the first parameter is the comparison function, + //and the second one the allocator. + //This the same signature as std::map's constructor taking an allocator + MyMap *mymap = + segment.construct("MyMap") //object name + (std::less() //first ctor parameter + ,alloc_inst); //second ctor parameter - //Construct a shared memory map. - //Note that the first parameter is the comparison function, - //and the second one the allocator. - //This the same signature as std::map's constructor taking an allocator - MyMap *mymap = - segment.construct("MyMap") //object name - (std::less() //first ctor parameter - ,alloc_inst); //second ctor parameter - - //Insert data in the map - for(int i = 0; i < 100; ++i){ - mymap->insert(std::pair(i, (float)i)); - } + //Insert data in the map + for(int i = 0; i < 100; ++i){ + mymap->insert(std::pair(i, (float)i)); } - catch(...){ - shared_memory_object::remove("MySharedMemory"); - throw; - } - shared_memory_object::remove("MySharedMemory"); return 0; } //] diff --git a/example/doc_move_containers.cpp b/example/doc_move_containers.cpp index aeadf61..c831bda 100644 --- a/example/doc_move_containers.cpp +++ b/example/doc_move_containers.cpp @@ -28,58 +28,57 @@ int main () typedef allocator StringAllocator; typedef vector MyShmStringVector; - //Remove old shared memory and create new one - shared_memory_object::remove("myshm"); - try{ - managed_shared_memory shm(create_only, "myshm", 10000); + //Remove shared memory on construction and destruction + struct shm_destroy + { + shm_destroy() { shared_memory_object::remove("MySharedMemory"); } + ~shm_destroy(){ shared_memory_object::remove("MySharedMemory"); } + } remover; - //Create allocators - CharAllocator charallocator (shm.get_segment_manager()); - StringAllocator stringallocator(shm.get_segment_manager()); + managed_shared_memory shm(create_only, "MySharedMemory", 10000); - //Create a vector of strings in shared memory. - MyShmStringVector *myshmvector = - shm.construct("myshmvector")(stringallocator); + //Create allocators + CharAllocator charallocator (shm.get_segment_manager()); + StringAllocator stringallocator(shm.get_segment_manager()); - //Insert 50 strings in shared memory. The strings will be allocated - //only once and no string copy-constructor will be called when inserting - //strings, leading to a great performance. - MyShmString string_to_compare(charallocator); - string_to_compare = "this is a long, long, long, long, long, long, string..."; - - myshmvector->reserve(50); - for(int i = 0; i < 50; ++i){ - MyShmString move_me(string_to_compare); - //In the following line, no string copy-constructor will be called. - //"move_me"'s contents will be transferred to the string created in - //the vector - myshmvector->push_back(boost::interprocess::move(move_me)); + //Create a vector of strings in shared memory. + MyShmStringVector *myshmvector = + shm.construct("myshmvector")(stringallocator); - //The source string is in default constructed state - assert(move_me.empty()); + //Insert 50 strings in shared memory. The strings will be allocated + //only once and no string copy-constructor will be called when inserting + //strings, leading to a great performance. + MyShmString string_to_compare(charallocator); + string_to_compare = "this is a long, long, long, long, long, long, string..."; + + myshmvector->reserve(50); + for(int i = 0; i < 50; ++i){ + MyShmString move_me(string_to_compare); + //In the following line, no string copy-constructor will be called. + //"move_me"'s contents will be transferred to the string created in + //the vector + myshmvector->push_back(boost::interprocess::move(move_me)); - //The newly created string will be equal to the "move_me"'s old contents - assert(myshmvector->back() == string_to_compare); - } + //The source string is in default constructed state + assert(move_me.empty()); - //Now erase a string... - myshmvector->pop_back(); - - //...And insert one in the first position. - //No string copy-constructor or assignments will be called, but - //move constructors and move-assignments. No memory allocation - //function will be called in this operations!! - myshmvector->insert(myshmvector->begin(), boost::interprocess::move(string_to_compare)); - - //Destroy vector. This will free all strings that the vector contains - shm.destroy_ptr(myshmvector); + //The newly created string will be equal to the "move_me"'s old contents + assert(myshmvector->back() == string_to_compare); } - catch(...){ - shared_memory_object::remove("myshmvector"); - throw; - } - shared_memory_object::remove("myshmvector"); + + //Now erase a string... + myshmvector->pop_back(); + + //...And insert one in the first position. + //No string copy-constructor or assignments will be called, but + //move constructors and move-assignments. No memory allocation + //function will be called in this operations!! + myshmvector->insert(myshmvector->begin(), boost::interprocess::move(string_to_compare)); + + //Destroy vector. This will free all strings that the vector contains + shm.destroy_ptr(myshmvector); return 0; } //] #include + diff --git a/example/doc_multi_index.cpp b/example/doc_multi_index.cpp index 24cbd63..dff5bd4 100644 --- a/example/doc_multi_index.cpp +++ b/example/doc_multi_index.cpp @@ -61,30 +61,27 @@ typedef bmi::multi_index_container< int main () { - //Erase previous shared memory with the name - shared_memory_object::remove("MySharedMemory"); + //Remove shared memory on construction and destruction + struct shm_destroy + { + shm_destroy() { shared_memory_object::remove("MySharedMemory"); } + ~shm_destroy(){ shared_memory_object::remove("MySharedMemory"); } + } remover; - try{ - //Create shared memory - managed_shared_memory segment(create_only,"MySharedMemory", 65536); + //Create shared memory + managed_shared_memory segment(create_only,"MySharedMemory", 65536); - //Construct the multi_index in shared memory - employee_set *es = segment.construct - ("My MultiIndex Container") //Container's name in shared memory - ( employee_set::ctor_args_list() - , segment.get_allocator()); //Ctor parameters + //Construct the multi_index in shared memory + employee_set *es = segment.construct + ("My MultiIndex Container") //Container's name in shared memory + ( employee_set::ctor_args_list() + , segment.get_allocator()); //Ctor parameters - //Now insert elements - char_allocator ca(segment.get_allocator()); - es->insert(employee(0,31, "Joe", ca)); - es->insert(employee(1,27, "Robert", ca)); - es->insert(employee(2,40, "John", ca)); - } - catch(...){ - shared_memory_object::remove("MySharedMemory"); - throw; - } - shared_memory_object::remove("MySharedMemory"); + //Now insert elements + char_allocator ca(segment.get_allocator()); + es->insert(employee(0,31, "Joe", ca)); + es->insert(employee(1,27, "Robert", ca)); + es->insert(employee(2,40, "John", ca)); return 0; } //] diff --git a/example/doc_named_allocA.cpp b/example/doc_named_alloc.cpp similarity index 50% rename from example/doc_named_allocA.cpp rename to example/doc_named_alloc.cpp index 84eb889..30767a8 100644 --- a/example/doc_named_allocA.cpp +++ b/example/doc_named_alloc.cpp @@ -9,24 +9,28 @@ ////////////////////////////////////////////////////////////////////////////// #include #include -//[doc_named_allocA +//[doc_named_alloc #include +#include //std::system +#include +#include #include -int main () +int main(int argc, char *argv[]) { using namespace boost::interprocess; typedef std::pair MyType; - try{ - //A special shared memory where we can - //construct objects associated with a name. - //First remove any old shared memory of the same name, create - //the shared memory segment and initialize needed resources - shared_memory_object::remove("MySharedMemory"); - managed_shared_memory segment - //create segment name segment size - (create_only, "MySharedMemory", 65536); + if(argc == 1){ //Parent process + //Remove shared memory on construction and destruction + struct shm_remove + { + shm_remove() { shared_memory_object::remove("MySharedMemory"); } + ~shm_remove(){ shared_memory_object::remove("MySharedMemory"); } + } remover; + + //Construct managed shared memory + managed_shared_memory segment(create_only, "MySharedMemory", 65536); //Create an object of MyType initialized to {0.0, 0} MyType *instance = segment.construct @@ -49,12 +53,50 @@ int main () [3] //number of elements ( &float_initializer[0] //Iterator for the 1st ctor argument , &int_initializer[0]); //Iterator for the 2nd ctor argument + + //Launch child process + std::string s(argv[0]); s += " child"; + if(0 != std::system(s.c_str())) + return 1; + + //<- + (void)instance; + (void)array; + (void)array_it; + //-> + + //Check child has destroyed all objects + if(segment.find("MyType array").first || + segment.find("MyType instance").first || + segment.find("MyType array from it").first) + return 1; } - catch(...){ - shared_memory_object::remove("MySharedMemory"); - throw; + else{ + //Open managed shared memory + managed_shared_memory segment(open_only, "MySharedMemory"); + + std::pair res; + + //Find the array + res = segment.find ("MyType array"); + //Length should be 10 + if(res.second != 10) return 1; + + //Find the object + res = segment.find ("MyType instance"); + //Length should be 1 + if(res.second != 1) return 1; + + //Find the array constructed from iterators + res = segment.find ("MyType array from it"); + //Length should be 3 + if(res.second != 3) return 1; + + //We're done, delete all the objects + segment.destroy("MyType array"); + segment.destroy("MyType instance"); + segment.destroy("MyType array from it"); } - shared_memory_object::remove("MySharedMemory"); return 0; } //] diff --git a/example/doc_named_allocB.cpp b/example/doc_named_allocB.cpp deleted file mode 100644 index 8b6bb65..0000000 --- a/example/doc_named_allocB.cpp +++ /dev/null @@ -1,63 +0,0 @@ -////////////////////////////////////////////////////////////////////////////// -// -// (C) Copyright Ion Gaztanaga 2006-2007. 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 -#include -//[doc_named_allocB -#include -#include -#include -#include - -int main () -{ - using namespace boost::interprocess; - typedef std::pair MyType; - - try{ - //A special shared memory where we can - //construct objects associated with a name. - //Connect to the already created shared memory segment - //and initialize needed resources - managed_shared_memory segment(open_only, "MySharedMemory"); - - std::pair res; - - //Find the array - res = segment.find ("MyType array"); - //Length should be 10 - assert(res.second == 10); - - //Find the object - res = segment.find ("MyType instance"); - //Length should be 1 - assert(res.second == 1); - - //Find the array constructed from iterators - res = segment.find ("MyType array from it"); - //Length should be 3 - assert(res.second == 3); - - //Use data - // . . . - - //We're done, delete all the objects - segment.destroy("MyType array"); - segment.destroy("MyType instance"); - segment.destroy("MyType array from it"); - } - catch(...){ - shared_memory_object::remove("MySharedMemory"); - throw; - } - shared_memory_object::remove("MySharedMemory"); - return 0; -} -//] -#include diff --git a/example/doc_named_mutex.cpp b/example/doc_named_mutex.cpp index 80e7f98..3ff1fa6 100644 --- a/example/doc_named_mutex.cpp +++ b/example/doc_named_mutex.cpp @@ -13,6 +13,7 @@ #include #include #include +#include int main () { @@ -37,10 +38,12 @@ int main () } catch(interprocess_exception &ex){ named_mutex::remove("fstream_named_mutex"); + std::remove("file_name"); std::cout << ex.what() << std::endl; return 1; } named_mutex::remove("fstream_named_mutex"); + std::remove("file_name"); return 0; } //] diff --git a/example/doc_node_allocator.cpp b/example/doc_node_allocator.cpp index 00ba3da..68087a0 100644 --- a/example/doc_node_allocator.cpp +++ b/example/doc_node_allocator.cpp @@ -18,46 +18,44 @@ using namespace boost::interprocess; int main () { - shared_memory_object::remove("MySharedMemory"); + //Remove shared memory on construction and destruction + struct shm_destroy + { + shm_destroy() { shared_memory_object::remove("MySharedMemory"); } + ~shm_destroy(){ shared_memory_object::remove("MySharedMemory"); } + } remover; - try{ - //Create shared memory - managed_shared_memory segment(create_only, - "MySharedMemory", //segment name - 65536); + //Create shared memory + managed_shared_memory segment(create_only, + "MySharedMemory", //segment name + 65536); - //Create a node_allocator that allocates ints from the managed segment - //The number of chunks per segment is the default value - typedef node_allocator - node_allocator_t; - node_allocator_t allocator_instance(segment.get_segment_manager()); + //Create a node_allocator that allocates ints from the managed segment + //The number of chunks per segment is the default value + typedef node_allocator + node_allocator_t; + node_allocator_t allocator_instance(segment.get_segment_manager()); - //Create another node_allocator. Since the segment manager address - //is the same, this node_allocator will be - //attached to the same pool so "allocator_instance2" can deallocate - //nodes allocated by "allocator_instance" - node_allocator_t allocator_instance2(segment.get_segment_manager()); + //Create another node_allocator. Since the segment manager address + //is the same, this node_allocator will be + //attached to the same pool so "allocator_instance2" can deallocate + //nodes allocated by "allocator_instance" + node_allocator_t allocator_instance2(segment.get_segment_manager()); - //Create another node_allocator using copy-constructor. This - //node_allocator will also be attached to the same pool - node_allocator_t allocator_instance3(allocator_instance2); + //Create another node_allocator using copy-constructor. This + //node_allocator will also be attached to the same pool + node_allocator_t allocator_instance3(allocator_instance2); - //All allocators are equal - assert(allocator_instance == allocator_instance2); - assert(allocator_instance2 == allocator_instance3); + //All allocators are equal + assert(allocator_instance == allocator_instance2); + assert(allocator_instance2 == allocator_instance3); - //So memory allocated with one can be deallocated with another - allocator_instance2.deallocate(allocator_instance.allocate(1), 1); - allocator_instance3.deallocate(allocator_instance2.allocate(1), 1); + //So memory allocated with one can be deallocated with another + allocator_instance2.deallocate(allocator_instance.allocate(1), 1); + allocator_instance3.deallocate(allocator_instance2.allocate(1), 1); - //The common pool will be destroyed here, since no allocator is - //attached to the pool - } - catch(...){ - shared_memory_object::remove("MySharedMemory"); - throw; - } - shared_memory_object::remove("MySharedMemory"); + //The common pool will be destroyed here, since no allocator is + //attached to the pool return 0; } //] diff --git a/example/doc_offset_ptr.cpp b/example/doc_offset_ptr.cpp index efa7930..8931177 100644 --- a/example/doc_offset_ptr.cpp +++ b/example/doc_offset_ptr.cpp @@ -24,45 +24,41 @@ struct list_node int main () { - //Destroy any previous shared memory with the name to be used. - //Create a special shared memory from which we can - //allocate buffers of raw memory. - shared_memory_object::remove("MySharedMemory"); - try{ - managed_shared_memory segment( - create_only, - "MySharedMemory", //segment name - 65536); //segment size in bytes + //Remove shared memory on construction and destruction + struct shm_destroy + { + shm_destroy() { shared_memory_object::remove("MySharedMemory"); } + ~shm_destroy(){ shared_memory_object::remove("MySharedMemory"); } + } remover; - //Create linked list with 10 nodes in shared memory - offset_ptr prev = 0, current, first; + managed_shared_memory segment( + create_only, + "MySharedMemory", //segment name + 65536); //segment size in bytes - int i; - for(i = 0; i < 10; ++i, prev = current){ - current = static_cast(segment.allocate(sizeof(list_node))); - current->value = i; - current->next = 0; + //Create linked list with 10 nodes in shared memory + offset_ptr prev = 0, current, first; - if(!prev) - first = current; - else - prev->next = current; - } + int i; + for(i = 0; i < 10; ++i, prev = current){ + current = static_cast(segment.allocate(sizeof(list_node))); + current->value = i; + current->next = 0; - //Communicate list to other processes - //. . . - //When done, destroy list - for(current = first; current; /**/){ - prev = current; - current = current->next; - segment.deallocate(prev.get()); - } + if(!prev) + first = current; + else + prev->next = current; } - catch(...){ - shared_memory_object::remove("MySharedMemory"); - throw; + + //Communicate list to other processes + //. . . + //When done, destroy list + for(current = first; current; /**/){ + prev = current; + current = current->next; + segment.deallocate(prev.get()); } - shared_memory_object::remove("MySharedMemory"); return 0; } //] diff --git a/example/doc_private_adaptive_pool.cpp b/example/doc_private_adaptive_pool.cpp index 8a5ac1e..38303ea 100644 --- a/example/doc_private_adaptive_pool.cpp +++ b/example/doc_private_adaptive_pool.cpp @@ -18,42 +18,40 @@ using namespace boost::interprocess; int main () { - shared_memory_object::remove("MySharedMemory"); + //Remove shared memory on construction and destruction + struct shm_destroy + { + shm_destroy() { shared_memory_object::remove("MySharedMemory"); } + ~shm_destroy(){ shared_memory_object::remove("MySharedMemory"); } + } remover; - try{ - //Create shared memory - managed_shared_memory segment(create_only, - "MySharedMemory", //segment name - 65536); + //Create shared memory + managed_shared_memory segment(create_only, + "MySharedMemory", //segment name + 65536); - //Create a private_adaptive_pool that allocates ints from the managed segment - //The number of chunks per segment is the default value - typedef private_adaptive_pool - private_adaptive_pool_t; - private_adaptive_pool_t allocator_instance(segment.get_segment_manager()); + //Create a private_adaptive_pool that allocates ints from the managed segment + //The number of chunks per segment is the default value + typedef private_adaptive_pool + private_adaptive_pool_t; + private_adaptive_pool_t allocator_instance(segment.get_segment_manager()); - //Create another private_adaptive_pool. - private_adaptive_pool_t allocator_instance2(segment.get_segment_manager()); + //Create another private_adaptive_pool. + private_adaptive_pool_t allocator_instance2(segment.get_segment_manager()); - //Although the segment manager address - //is the same, this private_adaptive_pool will have its own pool so - //"allocator_instance2" CAN'T deallocate nodes allocated by "allocator_instance". - //"allocator_instance2" is NOT equal to "allocator_instance" - assert(allocator_instance != allocator_instance2); + //Although the segment manager address + //is the same, this private_adaptive_pool will have its own pool so + //"allocator_instance2" CAN'T deallocate nodes allocated by "allocator_instance". + //"allocator_instance2" is NOT equal to "allocator_instance" + assert(allocator_instance != allocator_instance2); - //Create another adaptive_pool using copy-constructor. - private_adaptive_pool_t allocator_instance3(allocator_instance2); + //Create another adaptive_pool using copy-constructor. + private_adaptive_pool_t allocator_instance3(allocator_instance2); - //This allocator is also unequal to allocator_instance2 - assert(allocator_instance2 != allocator_instance3); + //This allocator is also unequal to allocator_instance2 + assert(allocator_instance2 != allocator_instance3); - //Pools are destroyed with the allocators - } - catch(...){ - shared_memory_object::remove("MySharedMemory"); - throw; - } - shared_memory_object::remove("MySharedMemory"); + //Pools are destroyed with the allocators return 0; } //] diff --git a/example/doc_private_node_allocator.cpp b/example/doc_private_node_allocator.cpp index e35f804..bbb7648 100644 --- a/example/doc_private_node_allocator.cpp +++ b/example/doc_private_node_allocator.cpp @@ -18,42 +18,40 @@ using namespace boost::interprocess; int main () { - shared_memory_object::remove("MySharedMemory"); + //Remove shared memory on construction and destruction + struct shm_destroy + { + shm_destroy() { shared_memory_object::remove("MySharedMemory"); } + ~shm_destroy(){ shared_memory_object::remove("MySharedMemory"); } + } remover; - try{ - //Create shared memory - managed_shared_memory segment(create_only, - "MySharedMemory", //segment name - 65536); + //Create shared memory + managed_shared_memory segment(create_only, + "MySharedMemory", //segment name + 65536); - //Create a private_node_allocator that allocates ints from the managed segment - //The number of chunks per segment is the default value - typedef private_node_allocator - private_node_allocator_t; - private_node_allocator_t allocator_instance(segment.get_segment_manager()); + //Create a private_node_allocator that allocates ints from the managed segment + //The number of chunks per segment is the default value + typedef private_node_allocator + private_node_allocator_t; + private_node_allocator_t allocator_instance(segment.get_segment_manager()); - //Create another private_node_allocator. - private_node_allocator_t allocator_instance2(segment.get_segment_manager()); + //Create another private_node_allocator. + private_node_allocator_t allocator_instance2(segment.get_segment_manager()); - //Although the segment manager address - //is the same, this private_node_allocator will have its own pool so - //"allocator_instance2" CAN'T deallocate nodes allocated by "allocator_instance". - //"allocator_instance2" is NOT equal to "allocator_instance" - assert(allocator_instance != allocator_instance2); + //Although the segment manager address + //is the same, this private_node_allocator will have its own pool so + //"allocator_instance2" CAN'T deallocate nodes allocated by "allocator_instance". + //"allocator_instance2" is NOT equal to "allocator_instance" + assert(allocator_instance != allocator_instance2); - //Create another node_allocator using copy-constructor. - private_node_allocator_t allocator_instance3(allocator_instance2); + //Create another node_allocator using copy-constructor. + private_node_allocator_t allocator_instance3(allocator_instance2); - //This allocator is also unequal to allocator_instance2 - assert(allocator_instance2 != allocator_instance3); + //This allocator is also unequal to allocator_instance2 + assert(allocator_instance2 != allocator_instance3); - //Pools are destroyed with the allocators - } - catch(...){ - shared_memory_object::remove("MySharedMemory"); - throw; - } - shared_memory_object::remove("MySharedMemory"); + //Pools are destroyed with the allocators return 0; } //] diff --git a/example/doc_scoped_ptr.cpp b/example/doc_scoped_ptr.cpp index 3eb423f..d4a577e 100644 --- a/example/doc_scoped_ptr.cpp +++ b/example/doc_scoped_ptr.cpp @@ -47,60 +47,59 @@ class my_deleter int main () { //Create shared memory - shared_memory_object::remove("my_shmem"); - try{ - managed_shared_memory shmem(create_only, "my_shmem", 10000); + //Remove shared memory on construction and destruction + struct shm_destroy + { + shm_destroy() { shared_memory_object::remove("MySharedMemory"); } + ~shm_destroy(){ shared_memory_object::remove("MySharedMemory"); } + } remover; - //In the first try, there will be no exceptions - //in the second try we will throw an exception - for(int i = 0; i < 2; ++i){ - //Create an object in shared memory - my_class * my_object = shmem.construct("my_object")(); - my_class * my_object2 = shmem.construct(anonymous_instance)(); - shmem.destroy_ptr(my_object2); - - //Since the next shared memory allocation can throw - //assign it to a scoped_ptr so that if an exception occurs - //we destroy the object automatically - my_deleter d(shmem.get_segment_manager()); + managed_shared_memory shmem(create_only, "MySharedMemory", 10000); - try{ - scoped_ptr > s_ptr(my_object, d); - //Let's emulate a exception capable operation - //In the second try, throw an exception - if(i == 1){ - throw(my_exception()); - } - //If we have passed the dangerous zone - //we can release the scoped pointer - //to avoid destruction - s_ptr.release(); + //In the first try, there will be no exceptions + //in the second try we will throw an exception + for(int i = 0; i < 2; ++i){ + //Create an object in shared memory + my_class * my_object = shmem.construct("my_object")(); + my_class * my_object2 = shmem.construct(anonymous_instance)(); + shmem.destroy_ptr(my_object2); + + //Since the next shared memory allocation can throw + //assign it to a scoped_ptr so that if an exception occurs + //we destroy the object automatically + my_deleter d(shmem.get_segment_manager()); + + try{ + scoped_ptr > s_ptr(my_object, d); + //Let's emulate a exception capable operation + //In the second try, throw an exception + if(i == 1){ + throw(my_exception()); } - catch(const my_exception &){} - //Here, scoped_ptr is destroyed - //so it we haven't thrown an exception - //the object should be there, otherwise, destroyed - if(i == 0){ - //Make sure the object is alive - if(!shmem.find("my_object").first){ - return 1; - } - //Now we can use it and delete it manually - shmem.destroy("my_object"); + //If we have passed the dangerous zone + //we can release the scoped pointer + //to avoid destruction + s_ptr.release(); + } + catch(const my_exception &){} + //Here, scoped_ptr is destroyed + //so it we haven't thrown an exception + //the object should be there, otherwise, destroyed + if(i == 0){ + //Make sure the object is alive + if(!shmem.find("my_object").first){ + return 1; } - else{ - //Make sure the object has been deleted - if(shmem.find("my_object").first){ - return 1; - } + //Now we can use it and delete it manually + shmem.destroy("my_object"); + } + else{ + //Make sure the object has been deleted + if(shmem.find("my_object").first){ + return 1; } } } - catch(...){ - shared_memory_object::remove("my_shmem"); - throw; - } - shared_memory_object::remove("my_shmem"); return 0; } //] diff --git a/example/doc_shared_memory.cpp b/example/doc_shared_memory.cpp index 3b5b7bc..053c031 100644 --- a/example/doc_shared_memory.cpp +++ b/example/doc_shared_memory.cpp @@ -11,18 +11,24 @@ //[doc_shared_memory #include #include -#include #include +#include +#include -int main () +int main(int argc, char *argv[]) { using namespace boost::interprocess; - try{ - //Erase previous shared memory - shared_memory_object::remove("shared_memory"); + + if(argc == 1){ //Parent process + //Remove shared memory on construction and destruction + struct shm_remove + { + shm_remove() { shared_memory_object::remove("MySharedMemory"); } + ~shm_remove(){ shared_memory_object::remove("MySharedMemory"); } + } remover; //Create a shared memory object. - shared_memory_object shm (create_only, "shared_memory", read_write); + shared_memory_object shm (create_only, "MySharedMemory", read_write); //Set size shm.truncate(1000); @@ -32,11 +38,24 @@ int main () //Write all the memory to 1 std::memset(region.get_address(), 1, region.get_size()); + + //Launch child process + std::string s(argv[0]); s += " child"; + if(0 != std::system(s.c_str())) + return 1; } - catch(interprocess_exception &ex){ - shared_memory_object::remove("shared_memory"); - std::cout << ex.what() << std::endl; - return 1; + else{ + //Open already created shared memory object. + shared_memory_object shm (open_only, "MySharedMemory", read_only); + + //Map the whole shared memory in this process + mapped_region region(shm, read_only); + + //Check that memory was initialized to 1 + char *mem = static_cast(region.get_address()); + for(std::size_t i = 0; i < region.get_size(); ++i) + if(*mem++ != 1) + return 1; //Error checking memory } return 0; } diff --git a/example/doc_shared_memory2.cpp b/example/doc_shared_memory2.cpp deleted file mode 100644 index c977095..0000000 --- a/example/doc_shared_memory2.cpp +++ /dev/null @@ -1,48 +0,0 @@ -////////////////////////////////////////////////////////////////////////////// -// -// (C) Copyright Ion Gaztanaga 2006-2007. 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 -//[doc_shared_memory2 -#include -#include -#include -#include - -int main () -{ - using namespace boost::interprocess; - shared_memory_object::remove("shared_memory"); - try{ - //Open already created shared memory object. - shared_memory_object shm (open_only, "shared_memory", read_only); - - //Map the whole shared memory in this process - mapped_region region(shm, read_only); - - //Check that memory was initialized to 1 - const char *mem = static_cast(region.get_address()); - for(std::size_t i = 0; i < region.get_size(); ++i){ - if(*mem++ != 1){ - std::cout << "Error checking memory!" << std::endl; - return 1; - } - } - std::cout << "Test successful!" << std::endl; - } - catch(interprocess_exception &ex){ - std::cout << "Unexpected exception: " << ex.what() << std::endl; - shared_memory_object::remove("shared_memory"); - return 1; - } - shared_memory_object::remove("shared_memory"); - return 0; -} -//] - -#include diff --git a/example/doc_shared_ptr.cpp b/example/doc_shared_ptr.cpp index ebdf6d5..3f41829 100644 --- a/example/doc_shared_ptr.cpp +++ b/example/doc_shared_ptr.cpp @@ -16,7 +16,6 @@ #include #include #include -#include //std::remove using namespace boost::interprocess; @@ -47,7 +46,7 @@ struct shared_ptr_owner int main () { //Destroy any previous file with the name to be used. - std::remove("MyMappedFile"); + file_mapping::remove("MyMappedFile"); { managed_mapped_file file(create_only, "MyMappedFile", 4096); @@ -114,7 +113,7 @@ int main () //The reference count will be deallocated when all weak pointers //disappear. After that, the file is unmapped. } - std::remove("MyMappedFile"); + file_mapping::remove("MyMappedFile"); return 0; } //] diff --git a/example/doc_shared_ptr_explicit.cpp b/example/doc_shared_ptr_explicit.cpp index 4a4121e..d1d97c7 100644 --- a/example/doc_shared_ptr_explicit.cpp +++ b/example/doc_shared_ptr_explicit.cpp @@ -31,8 +31,13 @@ typedef shared_ptr my_shared_ptr; int main () { - //Destroy any previous segment with the name to be used. - shared_memory_object::remove("MySharedMemory"); + //Remove shared memory on construction and destruction + struct shm_destroy + { + shm_destroy() { shared_memory_object::remove("MySharedMemory"); } + ~shm_destroy(){ shared_memory_object::remove("MySharedMemory"); } + } remover; + managed_shared_memory segment(create_only, "MySharedMemory", 4096); //Create a shared pointer in shared memory @@ -49,7 +54,6 @@ int main () //Destroy "shared ptr". "object to share" will be automatically destroyed segment.destroy_ptr(&shared_ptr_instance); - shared_memory_object::remove("MySharedMemory"); return 0; } //] diff --git a/example/doc_spawn_vector.cpp b/example/doc_spawn_vector.cpp new file mode 100644 index 0000000..6ec0789 --- /dev/null +++ b/example/doc_spawn_vector.cpp @@ -0,0 +1,79 @@ +////////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2006-2009. 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 +#include +//[run_doc_spawn_vector +#include +#include +#include +#include +#include //std::system + +using namespace boost::interprocess; + +//Define an STL compatible allocator of ints that allocates from the managed_shared_memory. +//This allocator will allow placing containers in the segment +typedef allocator ShmemAllocator; + +//Alias a vector that uses the previous STL-like allocator so that allocates +//its values from the segment +typedef vector MyVector; + +//Main function. For parent process argc == 1, for child process argc == 2 +int main(int argc, char *argv[]) +{ + if(argc == 1){ //Parent process + //Remove shared memory on construction and destruction + struct shm_remove + { + shm_remove() { shared_memory_object::remove("MySharedMemory"); } + ~shm_remove(){ shared_memory_object::remove("MySharedMemory"); } + } remover; + + //Create a new segment with given name and size + managed_shared_memory segment(create_only ,"MySharedMemory", 65536); + + //Initialize shared memory STL-compatible allocator + const ShmemAllocator alloc_inst (segment.get_segment_manager()); + + //Construct a vector named "MyVector" in shared memory with argument alloc_inst + MyVector *myvector = segment.construct("MyVector")(alloc_inst); + + for(int i = 0; i < 100; ++i) //Insert data in the vector + myvector->push_back(i); + + //Launch child process + std::string s(argv[0]); s += " child"; + if(0 != std::system(s.c_str())) + return 1; + + //Check child has destroyed the vector + if(segment.find("MyVector").first) + return 1; + } + else{ //Child process + //Open the managed segment + managed_shared_memory segment(open_only, "MySharedMemory"); + + //Find the vector using the c-string name + MyVector *myvector = segment.find("MyVector").first; + + //Use vector in reverse order + std::sort(myvector->rbegin(), myvector->rend()); + + //When done, destroy the vector from the segment + segment.destroy("MyVector"); + } + + return 0; +}; + +//] +#include diff --git a/example/doc_unique_ptr.cpp b/example/doc_unique_ptr.cpp index 0b6d5b5..9506297 100644 --- a/example/doc_unique_ptr.cpp +++ b/example/doc_unique_ptr.cpp @@ -18,7 +18,6 @@ #include #include #include -#include //std::remove using namespace boost::interprocess; @@ -49,7 +48,7 @@ typedef list int main () { //Destroy any previous file with the name to be used. - std::remove("MyMappedFile"); + file_mapping::remove("MyMappedFile"); { managed_mapped_file file(create_only, "MyMappedFile", 65536); @@ -72,9 +71,8 @@ int main () //Now insert all values for(int i = 0; i < 100; ++i){ - unique_vector->push_back( - make_managed_unique_ptr(file.construct(anonymous_instance)(i), file) - ); + unique_ptr_type p(make_managed_unique_ptr(file.construct(anonymous_instance)(i), file)); + unique_vector->push_back(boost::interprocess::move(p)); assert(unique_vector->back()->number_ == i); } @@ -84,7 +82,7 @@ int main () //Pass ownership of all values to the list for(int i = 99; !unique_vector->empty(); --i){ - unique_list->push_front(move(unique_vector->back())); + unique_list->push_front(boost::interprocess::move(unique_vector->back())); //The unique ptr of the vector is now empty... assert(unique_vector->back() == 0); unique_vector->pop_back(); @@ -114,7 +112,7 @@ int main () //Now destroy the list. All elements will be automatically deallocated. file.destroy_ptr(unique_list); } - std::remove("MyMappedFile"); + file_mapping::remove("MyMappedFile"); return 0; } //] diff --git a/example/doc_unordered_map.cpp b/example/doc_unordered_map.cpp index 3839c6f..03e289f 100644 --- a/example/doc_unordered_map.cpp +++ b/example/doc_unordered_map.cpp @@ -20,46 +20,43 @@ int main () { using namespace boost::interprocess; - //Erase previous shared memory with the name - shared_memory_object::remove("MySharedMemory"); + //Remove shared memory on construction and destruction + struct shm_destroy + { + shm_destroy() { shared_memory_object::remove("MySharedMemory"); } + ~shm_destroy(){ shared_memory_object::remove("MySharedMemory"); } + } remover; - try{ - //Create shared memory - managed_shared_memory segment(create_only ,"MySharedMemory" ,65536); + //Create shared memory + managed_shared_memory segment(create_only ,"MySharedMemory" ,65536); - //Note that unordered_map's value_type is std::pair, - //so the allocator must allocate that pair. - typedef int KeyType; - typedef float MappedType; - typedef std::pair ValueType; + //Note that unordered_map's value_type is std::pair, + //so the allocator must allocate that pair. + typedef int KeyType; + typedef float MappedType; + typedef std::pair ValueType; - //Typedef the allocator - typedef allocator ShmemAllocator; + //Typedef the allocator + typedef allocator ShmemAllocator; - //Alias an unordered_map of ints that uses the previous STL-like allocator. - typedef boost::unordered_map - < KeyType , MappedType - , boost::hash ,std::equal_to - , ShmemAllocator> - MyHashMap; + //Alias an unordered_map of ints that uses the previous STL-like allocator. + typedef boost::unordered_map + < KeyType , MappedType + , boost::hash ,std::equal_to + , ShmemAllocator> + MyHashMap; - //Construct a shared memory hash map. - //Note that the first parameter is the initial bucket count and - //after that, the hash function, the equality function and the allocator - MyHashMap *myhashmap = segment.construct("MyHashMap") //object name - ( 3, boost::hash(), std::equal_to() // - , segment.get_allocator()); //allocator instance + //Construct a shared memory hash map. + //Note that the first parameter is the initial bucket count and + //after that, the hash function, the equality function and the allocator + MyHashMap *myhashmap = segment.construct("MyHashMap") //object name + ( 3, boost::hash(), std::equal_to() // + , segment.get_allocator()); //allocator instance - //Insert data in the hash map - for(int i = 0; i < 100; ++i){ - myhashmap->insert(ValueType(i, (float)i)); - } + //Insert data in the hash map + for(int i = 0; i < 100; ++i){ + myhashmap->insert(ValueType(i, (float)i)); } - catch(...){ - shared_memory_object::remove("MySharedMemory"); - throw; - } - shared_memory_object::remove("MySharedMemory"); return 0; } //] diff --git a/example/doc_vectorstream.cpp b/example/doc_vectorstream.cpp index 5c4ed1f..f0021f6 100644 --- a/example/doc_vectorstream.cpp +++ b/example/doc_vectorstream.cpp @@ -30,83 +30,81 @@ typedef basic_vectorstream MyVectorStream; int main () { - //Create shared memory - shared_memory_object::remove("MySharedMemory"); - try{ - managed_shared_memory segment( - create_only, - "MySharedMemory", //segment name - 65536); //segment size in bytes + //Remove shared memory on construction and destruction + struct shm_destroy + { + shm_destroy() { shared_memory_object::remove("MySharedMemory"); } + ~shm_destroy(){ shared_memory_object::remove("MySharedMemory"); } + } remover; - //Construct shared memory vector - MyVector *myvector = - segment.construct("MyVector") - (IntAllocator(segment.get_segment_manager())); + managed_shared_memory segment( + create_only, + "MySharedMemory", //segment name + 65536); //segment size in bytes - //Fill vector - myvector->reserve(100); - for(int i = 0; i < 100; ++i){ - myvector->push_back(i); - } + //Construct shared memory vector + MyVector *myvector = + segment.construct("MyVector") + (IntAllocator(segment.get_segment_manager())); - //Create the vectorstream. To create the internal shared memory - //basic_string we need to pass the shared memory allocator as - //a constructor argument - MyVectorStream myvectorstream(CharAllocator(segment.get_segment_manager())); - - //Reserve the internal string - myvectorstream.reserve(100*5); - - //Write all vector elements as text in the internal string - //Data will be directly written in shared memory, because - //internal string's allocator is a shared memory allocator - for(std::size_t i = 0, max = myvector->size(); i < max; ++i){ - myvectorstream << (*myvector)[i] << std::endl; - } - - //Auxiliary vector to compare original data - MyVector *myvector2 = - segment.construct("MyVector2") - (IntAllocator(segment.get_segment_manager())); - - //Avoid reallocations - myvector2->reserve(100); - - //Extract all values from the internal - //string directly to a shared memory vector. - std::istream_iterator it(myvectorstream), itend; - std::copy(it, itend, std::back_inserter(*myvector2)); - - //Compare vectors - assert(std::equal(myvector->begin(), myvector->end(), myvector2->begin())); - - //Create a copy of the internal string - MyString stringcopy (myvectorstream.vector()); - - //Now we create a new empty shared memory string... - MyString *mystring = - segment.construct("MyString") - (CharAllocator(segment.get_segment_manager())); - - //...and we swap vectorstream's internal string - //with the new one: after this statement mystring - //will be the owner of the formatted data. - //No reallocations, no data copies - myvectorstream.swap_vector(*mystring); - - //Let's compare both strings - assert(stringcopy == *mystring); - - //Done, destroy and delete vectors and string from the segment - segment.destroy_ptr(myvector2); - segment.destroy_ptr(myvector); - segment.destroy_ptr(mystring); + //Fill vector + myvector->reserve(100); + for(int i = 0; i < 100; ++i){ + myvector->push_back(i); } - catch(...){ - shared_memory_object::remove("MySharedMemory"); - throw; + + //Create the vectorstream. To create the internal shared memory + //basic_string we need to pass the shared memory allocator as + //a constructor argument + MyVectorStream myvectorstream(CharAllocator(segment.get_segment_manager())); + + //Reserve the internal string + myvectorstream.reserve(100*5); + + //Write all vector elements as text in the internal string + //Data will be directly written in shared memory, because + //internal string's allocator is a shared memory allocator + for(std::size_t i = 0, max = myvector->size(); i < max; ++i){ + myvectorstream << (*myvector)[i] << std::endl; } - shared_memory_object::remove("MySharedMemory"); + + //Auxiliary vector to compare original data + MyVector *myvector2 = + segment.construct("MyVector2") + (IntAllocator(segment.get_segment_manager())); + + //Avoid reallocations + myvector2->reserve(100); + + //Extract all values from the internal + //string directly to a shared memory vector. + std::istream_iterator it(myvectorstream), itend; + std::copy(it, itend, std::back_inserter(*myvector2)); + + //Compare vectors + assert(std::equal(myvector->begin(), myvector->end(), myvector2->begin())); + + //Create a copy of the internal string + MyString stringcopy (myvectorstream.vector()); + + //Now we create a new empty shared memory string... + MyString *mystring = + segment.construct("MyString") + (CharAllocator(segment.get_segment_manager())); + + //...and we swap vectorstream's internal string + //with the new one: after this statement mystring + //will be the owner of the formatted data. + //No reallocations, no data copies + myvectorstream.swap_vector(*mystring); + + //Let's compare both strings + assert(stringcopy == *mystring); + + //Done, destroy and delete vectors and string from the segment + segment.destroy_ptr(myvector2); + segment.destroy_ptr(myvector); + segment.destroy_ptr(mystring); return 0; } //] diff --git a/example/doc_where_allocate.cpp b/example/doc_where_allocate.cpp index 7f14148..570de8e 100644 --- a/example/doc_where_allocate.cpp +++ b/example/doc_where_allocate.cpp @@ -29,45 +29,44 @@ int main () MyShmStringVector; //Open shared memory - shared_memory_object::remove("myshm"); - try{ - managed_shared_memory shm(create_only, "myshm", 10000); + //Remove shared memory on construction and destruction + struct shm_destroy + { + shm_destroy() { shared_memory_object::remove("MySharedMemory"); } + ~shm_destroy(){ shared_memory_object::remove("MySharedMemory"); } + } remover; - //Create allocators - CharAllocator charallocator (shm.get_segment_manager()); - StringAllocator stringallocator(shm.get_segment_manager()); + managed_shared_memory shm(create_only, "MySharedMemory", 10000); - //This string is in only in this process (the pointer pointing to the - //buffer that will hold the text is not in shared memory). - //But the buffer that will hold "this is my text" is allocated from - //shared memory - MyShmString mystring(charallocator); - mystring = "this is my text"; + //Create allocators + CharAllocator charallocator (shm.get_segment_manager()); + StringAllocator stringallocator(shm.get_segment_manager()); - //This vector is only in this process (the pointer pointing to the - //buffer that will hold the MyShmString-s is not in shared memory). - //But the buffer that will hold 10 MyShmString-s is allocated from - //shared memory using StringAllocator. Since strings use a shared - //memory allocator (CharAllocator) the 10 buffers that hold - //"this is my text" text are also in shared memory. - MyShmStringVector myvector(stringallocator); - myvector.insert(myvector.begin(), 10, mystring); + //This string is in only in this process (the pointer pointing to the + //buffer that will hold the text is not in shared memory). + //But the buffer that will hold "this is my text" is allocated from + //shared memory + MyShmString mystring(charallocator); + mystring = "this is my text"; - //This vector is fully constructed in shared memory. All pointers - //buffers are constructed in the same shared memory segment - //This vector can be safely accessed from other processes. - MyShmStringVector *myshmvector = - shm.construct("myshmvector")(stringallocator); - myshmvector->insert(myshmvector->begin(), 10, mystring); + //This vector is only in this process (the pointer pointing to the + //buffer that will hold the MyShmString-s is not in shared memory). + //But the buffer that will hold 10 MyShmString-s is allocated from + //shared memory using StringAllocator. Since strings use a shared + //memory allocator (CharAllocator) the 10 buffers that hold + //"this is my text" text are also in shared memory. + MyShmStringVector myvector(stringallocator); + myvector.insert(myvector.begin(), 10, mystring); - //Destroy vector. This will free all strings that the vector contains - shm.destroy_ptr(myshmvector); - } - catch(...){ - shared_memory_object::remove("myshm"); - throw; - } - shared_memory_object::remove("myshm"); + //This vector is fully constructed in shared memory. All pointers + //buffers are constructed in the same shared memory segment + //This vector can be safely accessed from other processes. + MyShmStringVector *myshmvector = + shm.construct("myshmvector")(stringallocator); + myshmvector->insert(myshmvector->begin(), 10, mystring); + + //Destroy vector. This will free all strings that the vector contains + shm.destroy_ptr(myshmvector); return 0; } //] diff --git a/example/doc_windows_shared_memory.cpp b/example/doc_windows_shared_memory.cpp index 94cd380..28da11e 100644 --- a/example/doc_windows_shared_memory.cpp +++ b/example/doc_windows_shared_memory.cpp @@ -8,41 +8,61 @@ // ////////////////////////////////////////////////////////////////////////////// #include -#include -#ifdef BOOST_WINDOWS +#ifdef BOOST_INTERPROCESS_WINDOWS + //[doc_windows_shared_memory #include #include -#include #include +#include +#include -int main () +int main(int argc, char *argv[]) { using namespace boost::interprocess; - try{ + + if(argc == 1){ //Parent process //Create a native windows shared memory object. - windows_shared_memory shm (create_only, "shared_memory", read_write, 1000); + windows_shared_memory shm (create_only, "MySharedMemory", read_write, 1000); //Map the whole shared memory in this process mapped_region region(shm, read_write); //Write all the memory to 1 - std::memset(region.get_address(), 1, 1000); + std::memset(region.get_address(), 1, region.get_size()); - //Launch the client process and wait until finishes... - //... + //Launch child process + std::string s(argv[0]); s += " child"; + if(0 != std::system(s.c_str())) + return 1; + //windows_shared_memory is destroyed when the last attached process dies... } - catch(interprocess_exception &ex){ - std::cout << ex.what() << std::endl; - return 1; + else{ + //Open already created shared memory object. + windows_shared_memory shm (open_only, "MySharedMemory", read_only); + + //Map the whole shared memory in this process + mapped_region region(shm, read_only); + + //Check that memory was initialized to 1 + char *mem = static_cast(region.get_address()); + for(std::size_t i = 0; i < region.get_size(); ++i) + if(*mem++ != 1) + return 1; //Error checking memory + return 0; } return 0; } //] -#else //#ifdef BOOST_WINDOWS + +#else //BOOST_INTERPROCESS_WINDOWS + int main() -{ return 0; } -#endif//#ifdef BOOST_WINDOWS +{ + return 0; +} + +#endif //BOOST_INTERPROCESS_WINDOWS #include diff --git a/example/doc_windows_shared_memory2.cpp b/example/doc_windows_shared_memory2.cpp deleted file mode 100644 index 405f244..0000000 --- a/example/doc_windows_shared_memory2.cpp +++ /dev/null @@ -1,55 +0,0 @@ -////////////////////////////////////////////////////////////////////////////// -// -// (C) Copyright Ion Gaztanaga 2006-2007. 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 -#include - -#ifdef BOOST_WINDOWS -//[doc_windows_shared_memory2 -#include -#include -#include -#include - -int main () -{ - using namespace boost::interprocess; - try{ - //Open already created shared memory object. - windows_shared_memory shm(open_only, "shared_memory", read_only); - - //Map the whole shared memory in this process - mapped_region region (shm, read_only); - - //Check that memory was initialized to 1 - const char *mem = static_cast(region.get_address()); - for(std::size_t i = 0; i < 1000; ++i){ - if(*mem++ != 1){ - std::cout << "Error checking memory!" << std::endl; - return 1; - } - } - - std::cout << "Test successful!" << std::endl; - } - catch(interprocess_exception &ex){ - std::cout << "Unexpected exception: " << ex.what() << std::endl; - return 1; - } - - return 0; -} -//] -#else //#ifdef BOOST_WINDOWS -int main() -{ return 0; } -#endif//#ifdef BOOST_WINDOWS - -#include - diff --git a/proj/conceptgcc/MakeAll b/proj/conceptgcc/MakeAll deleted file mode 100644 index 1770e5e..0000000 --- a/proj/conceptgcc/MakeAll +++ /dev/null @@ -1,35 +0,0 @@ - -#ifndef CC -CC=i686-pc-cygwin-conceptg++.exe -#endif - -BOOST_ROOT=../../../.. - -INTERPROCESS_CPP := $(wildcard ../../src/*.cpp) -INTERPROCESS_OBJ := $(patsubst ../../src/%.cpp, lib_%.o, $(INTERPROCESS_CPP)) - -INTERPROCESSTEST_CPP := $(wildcard ../../test/*.cpp) -INTERPROCESSTEST_OUT := $(patsubst ../../test/%.cpp, ../../bin/conceptgcc/test_%.out, $(INTERPROCESSTEST_CPP)) - -INTERPROCESSDOC_CPP := $(wildcard ../../example/*.cpp) -INTERPROCESSDOC_OUT := $(patsubst ../../example/%.cpp, ../../bin/conceptgcc/ex_%.out, $(INTERPROCESSDOC_CPP)) - -LIBDIR:= ../../../../stage/lib - -.PHONY: createdir clean - -all: createdir $(INTERPROCESSTEST_OUT) $(INTERPROCESSDOC_OUT) - @cd . - -createdir: - @mkdir -p ../../bin/conceptgcc - -../../bin/conceptgcc/test_%.out: ../../test/%.cpp - $(CC) $< -Wall -DBOOST_DATE_TIME_NO_LIB -L$(LIBDIR) -lboost_thread-mgw-mt -I$(BOOST_ROOT) -lstdc++ -o $@ - -../../bin/conceptgcc/ex_%.out: ../../example/%.cpp - $(CC) $< -Wall -DBOOST_DATE_TIME_NO_LIB -L$(LIBDIR)-lboost_thread-mgw-mt -I$(BOOST_ROOT) -lstdc++ -o $@ - -clean: - rm -f *.o - rm -f ../../bin/conceptgcc/* diff --git a/proj/cygwin/MakeAll b/proj/cygwin/MakeAll deleted file mode 100644 index 72e7b80..0000000 --- a/proj/cygwin/MakeAll +++ /dev/null @@ -1,33 +0,0 @@ - -ifndef CC -CC=g++ -endif - -BOOST_ROOT=../../../.. - -INTERPROCESSTEST_CPP := $(wildcard ../../test/*.cpp) -INTERPROCESSTEST_OUT := $(patsubst ../../test/%.cpp, ../../bin/cygwin/test_%.out, $(INTERPROCESSTEST_CPP)) - -#INTERPROCESSEXAMPLE_CPP := $(wildcard ../../example/*.cpp) -#INTERPROCESSEXAMPLE_OUT := $(patsubst ../../example/%.cpp, ../../bin/cygwin/ex_%.out, $(INTERPROCESSEXAMPLE_CPP)) - -LIBDIR:= ../../../../stage/lib - -.PHONY: createdir clean - -all: createdir $(INTERPROCESSEXAMPLE_OUT) $(INTERPROCESSTEST_OUT) - @cd . - -createdir: - @mkdir -p ../../bin/cygwin - -../../bin/cygwin/test_%.out: ../../test/%.cpp - $(CC) -g $< -Wall -DBOOST_DATE_TIME_NO_LIB -L$(LIBDIR) -lboost_thread-gcc-mt -I$(BOOST_ROOT) -lstdc++ -o $@ - -#../../bin/cygwin/ex_%.out: ../../example/%.cpp -# $(CC) -g $< -Wall -DBOOST_DATE_TIME_NO_LIB -L$(LIBDIR)-lboost_thread-gcc-mt -I$(BOOST_ROOT) -lstdc++ -o $@ - - -clean: - rm -f *.o - rm -f ../../bin/cygwin/* diff --git a/proj/linux/MakeAll b/proj/linux/MakeAll deleted file mode 100644 index 9f0962f..0000000 --- a/proj/linux/MakeAll +++ /dev/null @@ -1,32 +0,0 @@ - -ifndef CC -CC=g++ -endif - -BOOST_ROOT=../../../.. -BOOST_LIBS=/usr/local/lib - - -INTERPROCESS_CPP := $(wildcard ../../test/*.cpp) -INTERPROCESS_OUT := $(patsubst ../../test/%.cpp, ../../bin/linux/test_%.out, $(INTERPROCESS_CPP)) - -INTERPROCESSEXAMPLE_CPP := $(wildcard ../../example/*.cpp) -INTERPROCESSEXAMPLE_OUT := $(patsubst ../../example/%.cpp, ../../bin/linux/ex_%.out, $(INTERPROCESSEXAMPLE_CPP)) - -.PHONY: createdir clean - -all: createdir $(INTERPROCESS_OUT) $(INTERPROCESSEXAMPLE_OUT) - @cd . - -createdir: - @mkdir -p ../../bin/linux - -../../bin/linux/test_%.out: ../../test/%.cpp - $(CC) $< -Wall -pedantic -g -pthread -DBOOST_DATE_TIME_NO_LIB -lstdc++ -lrt -lboost_thread-gcc-mt -I$(BOOST_ROOT) -L$(BOOST_LIBS) -o $@ - -../../bin/linux/ex_%.out: ../../example/%.cpp - $(CC) $< -Wall -pedantic -g -pthread -DBOOST_DATE_TIME_NO_LIB -lstdc++ -lrt -lboost_thread-gcc-mt -I$(BOOST_ROOT) -L$(BOOST_LIBS) -o $@ - -clean: - rm -f *.o - rm -f ../../bin/linux/* diff --git a/proj/mingw/MakeAll b/proj/mingw/MakeAll deleted file mode 100644 index 0b23825..0000000 --- a/proj/mingw/MakeAll +++ /dev/null @@ -1,35 +0,0 @@ - -ifndef CC -CC=g++ -endif - -BOOST_ROOT=../../../.. - -INTERPROCESS_CPP := $(wildcard ../../src/*.cpp) -INTERPROCESS_OBJ := $(patsubst ../../src/%.cpp, lib_%.o, $(INTERPROCESS_CPP)) - -INTERPROCESSTEST_CPP := $(wildcard ../../test/*.cpp) -INTERPROCESSTEST_OUT := $(patsubst ../../test/%.cpp, ../../bin/mingw/test_%.out, $(INTERPROCESSTEST_CPP)) - -INTERPROCESSEXAMPLE_CPP := $(wildcard ../../example/*.cpp) -INTERPROCESSEXAMPLE_OUT := $(patsubst ../../example/%.cpp, ../../bin/mingw/ex_%.out, $(INTERPROCESSEXAMPLE_CPP)) - -LIBDIR:= ../../../../stage/lib - -.PHONY: createdir clean - -all: createdir $(INTERPROCESSTEST_OUT) $(INTERPROCESSEXAMPLE_OUT) - @cd . - -createdir: - @mkdir -p ../../bin/mingw - -../../bin/mingw/test_%.out: ../../test/%.cpp - $(CC) $< -Wall -DBOOST_DATE_TIME_NO_LIB -L$(LIBDIR) -lboost_thread-mgw-mt -I$(BOOST_ROOT) -lstdc++ -o $@ - -../../bin/mingw/ex_%.out: ../../example/%.cpp - $(CC) $< -Wall -DBOOST_DATE_TIME_NO_LIB -L$(LIBDIR)-lboost_thread-mgw-mt -I$(BOOST_ROOT) -lstdc++ -o $@ - -clean: - rm -f *.o - rm -f ../../bin/mingw/* diff --git a/proj/qnx/MakeAll b/proj/qnx/MakeAll deleted file mode 100644 index b98dc49..0000000 --- a/proj/qnx/MakeAll +++ /dev/null @@ -1,33 +0,0 @@ - -ifndef CC -CC=g++ -endif - -BOOST_ROOT=../../../.. - -INTERPROCESS_CPP := $(wildcard ../../src/*.cpp) -INTERPROCESS_OBJ := $(patsubst ../../src/%.cpp, lib_%.o, $(INTERPROCESS_CPP)) - -INTERPROCESSTEST_CPP := $(wildcard ../../test/*.cpp) -INTERPROCESSTEST_OUT := $(patsubst ../../test/%.cpp, ../../bin/qnx/test_%.out, $(INTERPROCESSTEST_CPP)) - -INTERPROCESSEXAMPLE_CPP := $(wildcard ../../example/*.cpp) -INTERPROCESSEXAMPLE_OUT := $(patsubst ../../example/%.cpp, ../../bin/qnx/ex_%.out, $(INTERPROCESSEXAMPLE_CPP)) - -.PHONY: createdir clean - -all: createdir $(INTERPROCESSTEST_OUT) $(INTERPROCESSEXAMPLE_OUT) - @cd . - -createdir: - @mkdir -p ../../bin/qnx - -../../bin/qnx/test_%.out: ../../test/%.cpp - $(CC) $< -Wall -DBOOST_DATE_TIME_NO_LIB -lboost_thread-gcc-mt-s -I$(BOOST_ROOT) -o $@ - -../../bin/qnx/ex_%.out: ../../example/%.cpp - $(CC) $< -Wall -DBOOST_DATE_TIME_NO_LIB -lboost_thread-gcc-mt-s -I$(BOOST_ROOT) -o $@ - -clean: - rm -f *.o - rm -f ../../bin/qnx/* diff --git a/proj/to-do.txt b/proj/to-do.txt index 3ac56ac..623bd5d 100644 --- a/proj/to-do.txt +++ b/proj/to-do.txt @@ -1,5 +1,3 @@ --> change rvalue reference signatures in all containers - -> add private_read_only to mapped_region to support MAP_PRIVATE plus PROT_READ -> add contiguous_elements option to burst allocation @@ -43,28 +41,26 @@ -> barrier_test fails on MacOS X on PowerPC. -->use virtual functions to minimize template explosion in managed classes +-> use virtual functions to minimize template explosion in managed classes -->Insertions with InpIt are not tested in containers +-> Insertions with InpIt are not tested in containers -->Run tests with rvalue reference compilers with no variadic insertions +-> Run tests with rvalue reference compilers with no variadic insertions -->find a way to pass security attributes to shared memory +-> find a way to pass security attributes to shared memory -->Explain in docs that shared memory can't be used between different users in windows +-> Explain in docs that shared memory can't be used between different users in windows -> Implement vector with memcpy/memmove for trivially copyable types. --> Update all swap() calls to work with rvalues in all classes - --> correct swap overloads for the documentation so that just appears a single rvalue swap - --> correct splice()/merg overloads for the documentation so that just appears a single rvalue splice - -> flat_xxx constructors are not documented -> operator >> eta antzekoek moved_value behar dute --> make file_lock movable - -> Add cmath workaround for Boost < 1.37 + +-> rvalue reference enabled compilers are not optimized with is_movable and move_iterator + +-> Add allocator test template that test all new functions (allocate_many, etc.) + +-> MacOS shm_open is non-conformant. Is there a way to know the size of a shared memory object? diff --git a/proj/vc7ide/Interprocess.sln b/proj/vc7ide/Interprocess.sln index ed25a07..dfbe26e 100644 --- a/proj/vc7ide/Interprocess.sln +++ b/proj/vc7ide/Interprocess.sln @@ -103,18 +103,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "doc_cont", "doc_cont.vcproj ProjectSection(ProjectDependencies) = postProject EndProjectSection EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "doc_contA", "doc_contA.vcproj", "{58CCE183-6092-48FE-A4F7-BA0D3A792652}" - ProjectSection(ProjectDependencies) = postProject - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "doc_contB", "doc_contB.vcproj", "{58CCE183-6092-48FE-A4F7-BA0D3A792651}" - ProjectSection(ProjectDependencies) = postProject - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "doc_shared_memory", "doc_shared_memory.vcproj", "{58CCE183-6032-12FE-4FC7-83A79F760B61}" - ProjectSection(ProjectDependencies) = postProject - EndProjectSection -EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "unique_ptr_test", "unique_ptr_test.vcproj", "{571C3383-6092-A877-1238-B3786BAE7605}" ProjectSection(ProjectDependencies) = postProject EndProjectSection @@ -139,14 +127,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "iunordered_set_index_alloca ProjectSection(ProjectDependencies) = postProject EndProjectSection EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "doc_shared_memory2", "doc_shared_memory2.vcproj", "{58CE1D83-F31E-4FD7-6132-8A79F6307B61}" - ProjectSection(ProjectDependencies) = postProject - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "doc_file_mapping2", "doc_file_mapping2.vcproj", "{5CE19883-F413-7EFD-6342-B79639F7B611}" - ProjectSection(ProjectDependencies) = postProject - EndProjectSection -EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "doc_file_mapping", "doc_file_mapping.vcproj", "{58DE18C3-3261-2F3E-FD47-83760B9FA761}" ProjectSection(ProjectDependencies) = postProject EndProjectSection @@ -223,10 +203,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "doc_windows_shared_memory", ProjectSection(ProjectDependencies) = postProject EndProjectSection EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "doc_windows_shared_memory2", "doc_windows_shared_memory2.vcproj", "{5E1D6C83-31DE-4F6F-6132-87A9FB663041}" - ProjectSection(ProjectDependencies) = postProject - EndProjectSection -EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "adaptive_node_pool_test", "adaptive_node_pool_test.vcproj", "{CD57C283-1862-42FE-BF87-B96D3A2A7912}" ProjectSection(ProjectDependencies) = postProject EndProjectSection @@ -295,26 +271,10 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "doc_intrusive", "doc_intrus ProjectSection(ProjectDependencies) = postProject EndProjectSection EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "doc_ipc_messageA", "doc_ipc_messageA.vcproj", "{58CCE183-6092-48FE-A4F7-BA0D3A792649}" - ProjectSection(ProjectDependencies) = postProject - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "doc_ipc_messageB", "doc_ipc_messageB.vcproj", "{58CCE183-6092-48FE-A4F7-BA0D3A792648}" - ProjectSection(ProjectDependencies) = postProject - EndProjectSection -EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "doc_managed_mapped_file", "doc_managed_mapped_file.vcproj", "{58CCE183-5091-48FE-A4FC-BA0D3A792446}" ProjectSection(ProjectDependencies) = postProject EndProjectSection EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "doc_named_allocA", "doc_named_allocA.vcproj", "{58CCE183-6092-48FE-A4F7-BA0D3A792645}" - ProjectSection(ProjectDependencies) = postProject - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "doc_named_allocB", "doc_named_allocB.vcproj", "{58CCE183-6092-48FE-A4F7-BA0D3A792644}" - ProjectSection(ProjectDependencies) = postProject - EndProjectSection -EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "doc_offset_ptr", "doc_offset_ptr.vcproj", "{58CCE183-6092-48FE-A4F7-BA0D3A792643}" ProjectSection(ProjectDependencies) = postProject EndProjectSection @@ -463,11 +423,33 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "named_construct_test", "nam ProjectSection(ProjectDependencies) = postProject EndProjectSection EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "stable_vector_test", "stable_vector_test.vcproj", "{5E11C8D3-FA52-760A-84FE-943A6BA05A21}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "doc_spawn_vector", "doc_spawn_vector.vcproj", "{58CCE183-6092-48FE-A4F7-BA0D3A792652}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "doc_ipc_message", "doc_ipc_message.vcproj", "{58CCE183-6092-48FE-A4F7-BA0D3A792649}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "doc_named_alloc", "doc_named_alloc.vcproj", "{58CCE183-6092-48FE-A4F7-BA0D3A792645}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "doc_shared_memory", "doc_shared_memory.vcproj", "{58CCE183-6032-12FE-4FC7-83A79F760B61}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject Global GlobalSection(SolutionConfiguration) = preSolution Debug = Debug Release = Release EndGlobalSection + GlobalSection(ProjectDependencies) = postSolution + EndGlobalSection GlobalSection(ProjectConfiguration) = postSolution {5CE18C83-6025-36FE-A4F7-BA09176D3A11}.Debug.ActiveCfg = Debug|Win32 {5CE18C83-6025-36FE-A4F7-BA09176D3A11}.Debug.Build.0 = Debug|Win32 @@ -573,18 +555,6 @@ Global {58CCE183-6092-48FE-A4F7-BA0D3A792653}.Debug.Build.0 = Debug|Win32 {58CCE183-6092-48FE-A4F7-BA0D3A792653}.Release.ActiveCfg = Release|Win32 {58CCE183-6092-48FE-A4F7-BA0D3A792653}.Release.Build.0 = Release|Win32 - {58CCE183-6092-48FE-A4F7-BA0D3A792652}.Debug.ActiveCfg = Debug|Win32 - {58CCE183-6092-48FE-A4F7-BA0D3A792652}.Debug.Build.0 = Debug|Win32 - {58CCE183-6092-48FE-A4F7-BA0D3A792652}.Release.ActiveCfg = Release|Win32 - {58CCE183-6092-48FE-A4F7-BA0D3A792652}.Release.Build.0 = Release|Win32 - {58CCE183-6092-48FE-A4F7-BA0D3A792651}.Debug.ActiveCfg = Debug|Win32 - {58CCE183-6092-48FE-A4F7-BA0D3A792651}.Debug.Build.0 = Debug|Win32 - {58CCE183-6092-48FE-A4F7-BA0D3A792651}.Release.ActiveCfg = Release|Win32 - {58CCE183-6092-48FE-A4F7-BA0D3A792651}.Release.Build.0 = Release|Win32 - {58CCE183-6032-12FE-4FC7-83A79F760B61}.Debug.ActiveCfg = Debug|Win32 - {58CCE183-6032-12FE-4FC7-83A79F760B61}.Debug.Build.0 = Debug|Win32 - {58CCE183-6032-12FE-4FC7-83A79F760B61}.Release.ActiveCfg = Release|Win32 - {58CCE183-6032-12FE-4FC7-83A79F760B61}.Release.Build.0 = Release|Win32 {571C3383-6092-A877-1238-B3786BAE7605}.Debug.ActiveCfg = Debug|Win32 {571C3383-6092-A877-1238-B3786BAE7605}.Debug.Build.0 = Debug|Win32 {571C3383-6092-A877-1238-B3786BAE7605}.Release.ActiveCfg = Release|Win32 @@ -609,14 +579,6 @@ Global {5BD1C7C3-3F7F-6972-84BE-B731D9236035}.Debug.Build.0 = Debug|Win32 {5BD1C7C3-3F7F-6972-84BE-B731D9236035}.Release.ActiveCfg = Release|Win32 {5BD1C7C3-3F7F-6972-84BE-B731D9236035}.Release.Build.0 = Release|Win32 - {58CE1D83-F31E-4FD7-6132-8A79F6307B61}.Debug.ActiveCfg = Debug|Win32 - {58CE1D83-F31E-4FD7-6132-8A79F6307B61}.Debug.Build.0 = Debug|Win32 - {58CE1D83-F31E-4FD7-6132-8A79F6307B61}.Release.ActiveCfg = Release|Win32 - {58CE1D83-F31E-4FD7-6132-8A79F6307B61}.Release.Build.0 = Release|Win32 - {5CE19883-F413-7EFD-6342-B79639F7B611}.Debug.ActiveCfg = Debug|Win32 - {5CE19883-F413-7EFD-6342-B79639F7B611}.Debug.Build.0 = Debug|Win32 - {5CE19883-F413-7EFD-6342-B79639F7B611}.Release.ActiveCfg = Release|Win32 - {5CE19883-F413-7EFD-6342-B79639F7B611}.Release.Build.0 = Release|Win32 {58DE18C3-3261-2F3E-FD47-83760B9FA761}.Debug.ActiveCfg = Debug|Win32 {58DE18C3-3261-2F3E-FD47-83760B9FA761}.Debug.Build.0 = Debug|Win32 {58DE18C3-3261-2F3E-FD47-83760B9FA761}.Release.ActiveCfg = Release|Win32 @@ -693,10 +655,6 @@ Global {5E17C9C3-1362-2E1E-C84F-8A76B6739F21}.Debug.Build.0 = Debug|Win32 {5E17C9C3-1362-2E1E-C84F-8A76B6739F21}.Release.ActiveCfg = Release|Win32 {5E17C9C3-1362-2E1E-C84F-8A76B6739F21}.Release.Build.0 = Release|Win32 - {5E1D6C83-31DE-4F6F-6132-87A9FB663041}.Debug.ActiveCfg = Debug|Win32 - {5E1D6C83-31DE-4F6F-6132-87A9FB663041}.Debug.Build.0 = Debug|Win32 - {5E1D6C83-31DE-4F6F-6132-87A9FB663041}.Release.ActiveCfg = Release|Win32 - {5E1D6C83-31DE-4F6F-6132-87A9FB663041}.Release.Build.0 = Release|Win32 {CD57C283-1862-42FE-BF87-B96D3A2A7912}.Debug.ActiveCfg = Debug|Win32 {CD57C283-1862-42FE-BF87-B96D3A2A7912}.Debug.Build.0 = Debug|Win32 {CD57C283-1862-42FE-BF87-B96D3A2A7912}.Release.ActiveCfg = Release|Win32 @@ -765,26 +723,10 @@ Global {5E18CC83-6092-48FE-A677-B832A0D3A650}.Debug.Build.0 = Debug|Win32 {5E18CC83-6092-48FE-A677-B832A0D3A650}.Release.ActiveCfg = Release|Win32 {5E18CC83-6092-48FE-A677-B832A0D3A650}.Release.Build.0 = Release|Win32 - {58CCE183-6092-48FE-A4F7-BA0D3A792649}.Debug.ActiveCfg = Debug|Win32 - {58CCE183-6092-48FE-A4F7-BA0D3A792649}.Debug.Build.0 = Debug|Win32 - {58CCE183-6092-48FE-A4F7-BA0D3A792649}.Release.ActiveCfg = Release|Win32 - {58CCE183-6092-48FE-A4F7-BA0D3A792649}.Release.Build.0 = Release|Win32 - {58CCE183-6092-48FE-A4F7-BA0D3A792648}.Debug.ActiveCfg = Debug|Win32 - {58CCE183-6092-48FE-A4F7-BA0D3A792648}.Debug.Build.0 = Debug|Win32 - {58CCE183-6092-48FE-A4F7-BA0D3A792648}.Release.ActiveCfg = Release|Win32 - {58CCE183-6092-48FE-A4F7-BA0D3A792648}.Release.Build.0 = Release|Win32 {58CCE183-5091-48FE-A4FC-BA0D3A792446}.Debug.ActiveCfg = Debug|Win32 {58CCE183-5091-48FE-A4FC-BA0D3A792446}.Debug.Build.0 = Debug|Win32 {58CCE183-5091-48FE-A4FC-BA0D3A792446}.Release.ActiveCfg = Release|Win32 {58CCE183-5091-48FE-A4FC-BA0D3A792446}.Release.Build.0 = Release|Win32 - {58CCE183-6092-48FE-A4F7-BA0D3A792645}.Debug.ActiveCfg = Debug|Win32 - {58CCE183-6092-48FE-A4F7-BA0D3A792645}.Debug.Build.0 = Debug|Win32 - {58CCE183-6092-48FE-A4F7-BA0D3A792645}.Release.ActiveCfg = Release|Win32 - {58CCE183-6092-48FE-A4F7-BA0D3A792645}.Release.Build.0 = Release|Win32 - {58CCE183-6092-48FE-A4F7-BA0D3A792644}.Debug.ActiveCfg = Debug|Win32 - {58CCE183-6092-48FE-A4F7-BA0D3A792644}.Debug.Build.0 = Debug|Win32 - {58CCE183-6092-48FE-A4F7-BA0D3A792644}.Release.ActiveCfg = Release|Win32 - {58CCE183-6092-48FE-A4F7-BA0D3A792644}.Release.Build.0 = Release|Win32 {58CCE183-6092-48FE-A4F7-BA0D3A792643}.Debug.ActiveCfg = Debug|Win32 {58CCE183-6092-48FE-A4F7-BA0D3A792643}.Debug.Build.0 = Debug|Win32 {58CCE183-6092-48FE-A4F7-BA0D3A792643}.Release.ActiveCfg = Release|Win32 @@ -933,6 +875,26 @@ Global {5183C8CE-F2E1-3620-237A-B765C9896390}.Debug.Build.0 = Debug|Win32 {5183C8CE-F2E1-3620-237A-B765C9896390}.Release.ActiveCfg = Release|Win32 {5183C8CE-F2E1-3620-237A-B765C9896390}.Release.Build.0 = Release|Win32 + {5E11C8D3-FA52-760A-84FE-943A6BA05A21}.Debug.ActiveCfg = Debug|Win32 + {5E11C8D3-FA52-760A-84FE-943A6BA05A21}.Debug.Build.0 = Debug|Win32 + {5E11C8D3-FA52-760A-84FE-943A6BA05A21}.Release.ActiveCfg = Release|Win32 + {5E11C8D3-FA52-760A-84FE-943A6BA05A21}.Release.Build.0 = Release|Win32 + {58CCE183-6092-48FE-A4F7-BA0D3A792652}.Debug.ActiveCfg = Debug|Win32 + {58CCE183-6092-48FE-A4F7-BA0D3A792652}.Debug.Build.0 = Debug|Win32 + {58CCE183-6092-48FE-A4F7-BA0D3A792652}.Release.ActiveCfg = Release|Win32 + {58CCE183-6092-48FE-A4F7-BA0D3A792652}.Release.Build.0 = Release|Win32 + {58CCE183-6092-48FE-A4F7-BA0D3A792649}.Debug.ActiveCfg = Debug|Win32 + {58CCE183-6092-48FE-A4F7-BA0D3A792649}.Debug.Build.0 = Debug|Win32 + {58CCE183-6092-48FE-A4F7-BA0D3A792649}.Release.ActiveCfg = Release|Win32 + {58CCE183-6092-48FE-A4F7-BA0D3A792649}.Release.Build.0 = Release|Win32 + {58CCE183-6092-48FE-A4F7-BA0D3A792645}.Debug.ActiveCfg = Debug|Win32 + {58CCE183-6092-48FE-A4F7-BA0D3A792645}.Debug.Build.0 = Debug|Win32 + {58CCE183-6092-48FE-A4F7-BA0D3A792645}.Release.ActiveCfg = Release|Win32 + {58CCE183-6092-48FE-A4F7-BA0D3A792645}.Release.Build.0 = Release|Win32 + {58CCE183-6032-12FE-4FC7-83A79F760B61}.Debug.ActiveCfg = Debug|Win32 + {58CCE183-6032-12FE-4FC7-83A79F760B61}.Debug.Build.0 = Debug|Win32 + {58CCE183-6032-12FE-4FC7-83A79F760B61}.Release.ActiveCfg = Release|Win32 + {58CCE183-6032-12FE-4FC7-83A79F760B61}.Release.Build.0 = Release|Win32 EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution EndGlobalSection diff --git a/proj/vc7ide/adaptive_node_pool_test.vcproj b/proj/vc7ide/adaptive_node_pool_test.vcproj index e67a6c8..5ede3e9 100644 --- a/proj/vc7ide/adaptive_node_pool_test.vcproj +++ b/proj/vc7ide/adaptive_node_pool_test.vcproj @@ -21,6 +21,7 @@ Optimization="0" AdditionalIncludeDirectories="../../../.." PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;BOOST_DATE_TIME_NO_LIB" + GeneratePreprocessedFile="0" MinimalRebuild="TRUE" BasicRuntimeChecks="3" RuntimeLibrary="3" diff --git a/proj/vc7ide/doc_adaptive_pool.vcproj b/proj/vc7ide/doc_adaptive_pool.vcproj index 1961a35..39d77ad 100644 --- a/proj/vc7ide/doc_adaptive_pool.vcproj +++ b/proj/vc7ide/doc_adaptive_pool.vcproj @@ -127,11 +127,6 @@ RelativePath="..\..\example\doc_adaptive_pool.cpp"> - - diff --git a/proj/vc7ide/doc_allocator.vcproj b/proj/vc7ide/doc_allocator.vcproj index f87a509..a59fe9f 100644 --- a/proj/vc7ide/doc_allocator.vcproj +++ b/proj/vc7ide/doc_allocator.vcproj @@ -127,11 +127,6 @@ RelativePath="..\..\example\doc_allocator.cpp"> - - diff --git a/proj/vc7ide/doc_anonymous_conditionA.vcproj b/proj/vc7ide/doc_anonymous_conditionA.vcproj index f572274..f1e0831 100644 --- a/proj/vc7ide/doc_anonymous_conditionA.vcproj +++ b/proj/vc7ide/doc_anonymous_conditionA.vcproj @@ -124,14 +124,9 @@ Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx" UniqueIdentifier="{4BE2BEF1-C8A9-53BC-1A02-952FFA2D75A2}"> + RelativePath="..\..\example\comp_doc_anonymous_conditionA.cpp"> - - diff --git a/proj/vc7ide/doc_anonymous_conditionB.vcproj b/proj/vc7ide/doc_anonymous_conditionB.vcproj index 7005b51..e4a4028 100644 --- a/proj/vc7ide/doc_anonymous_conditionB.vcproj +++ b/proj/vc7ide/doc_anonymous_conditionB.vcproj @@ -124,14 +124,9 @@ Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx" UniqueIdentifier="{4B2EF711-14CA-5347-F025-7F75AF2D22A2}"> + RelativePath="..\..\example\comp_doc_anonymous_conditionB.cpp"> - - diff --git a/proj/vc7ide/doc_anonymous_mutexA.vcproj b/proj/vc7ide/doc_anonymous_mutexA.vcproj index f97c3ba..e562362 100644 --- a/proj/vc7ide/doc_anonymous_mutexA.vcproj +++ b/proj/vc7ide/doc_anonymous_mutexA.vcproj @@ -124,14 +124,9 @@ Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx" UniqueIdentifier="{4BE712F1-C98A-4537-12A0-72D752FFA2A2}"> + RelativePath="..\..\example\comp_doc_anonymous_mutexA.cpp"> - - diff --git a/proj/vc7ide/doc_anonymous_mutexB.vcproj b/proj/vc7ide/doc_anonymous_mutexB.vcproj index f696723..bde78a6 100644 --- a/proj/vc7ide/doc_anonymous_mutexB.vcproj +++ b/proj/vc7ide/doc_anonymous_mutexB.vcproj @@ -124,14 +124,9 @@ Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx" UniqueIdentifier="{4B712EF1-98CA-4537-A012-72D2FF75A2A2}"> + RelativePath="..\..\example\comp_doc_anonymous_mutexB.cpp"> - - diff --git a/proj/vc7ide/doc_anonymous_semaphoreA.vcproj b/proj/vc7ide/doc_anonymous_semaphoreA.vcproj index 21d58f3..07786c5 100644 --- a/proj/vc7ide/doc_anonymous_semaphoreA.vcproj +++ b/proj/vc7ide/doc_anonymous_semaphoreA.vcproj @@ -124,14 +124,9 @@ Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx" UniqueIdentifier="{4BEFCAB1-8AC0-3B5C-AF1B-9522D75AFFA2}"> + RelativePath="..\..\example\comp_doc_anonymous_semaphoreA.cpp"> - - diff --git a/proj/vc7ide/doc_anonymous_semaphoreB.vcproj b/proj/vc7ide/doc_anonymous_semaphoreB.vcproj index 30b1dd4..3d39e30 100644 --- a/proj/vc7ide/doc_anonymous_semaphoreB.vcproj +++ b/proj/vc7ide/doc_anonymous_semaphoreB.vcproj @@ -124,14 +124,9 @@ Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx" UniqueIdentifier="{4BCDF711-5717-14CA-F250-F2D8F75A22A2}"> + RelativePath="..\..\example\comp_doc_anonymous_semaphoreB.cpp"> - - diff --git a/proj/vc7ide/doc_anonymous_shared_memory.vcproj b/proj/vc7ide/doc_anonymous_shared_memory.vcproj index cd5d7a4..04cbf00 100644 --- a/proj/vc7ide/doc_anonymous_shared_memory.vcproj +++ b/proj/vc7ide/doc_anonymous_shared_memory.vcproj @@ -127,11 +127,6 @@ RelativePath="..\..\example\doc_anonymous_shared_memory.cpp"> - - diff --git a/proj/vc7ide/doc_anonymous_upgradable_mutexA.vcproj b/proj/vc7ide/doc_anonymous_upgradable_mutexA.vcproj index 2df71b6..af3aca3 100644 --- a/proj/vc7ide/doc_anonymous_upgradable_mutexA.vcproj +++ b/proj/vc7ide/doc_anonymous_upgradable_mutexA.vcproj @@ -124,14 +124,9 @@ Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx" UniqueIdentifier="{4BF1E712-4FB5-08CB-2A11-752DCD72F2B2}"> + RelativePath="..\..\example\comp_doc_anonymous_upgradable_mutexA.cpp"> - - diff --git a/proj/vc7ide/doc_anonymous_upgradable_mutexB.vcproj b/proj/vc7ide/doc_anonymous_upgradable_mutexB.vcproj index e5b0250..5204ec5 100644 --- a/proj/vc7ide/doc_anonymous_upgradable_mutexB.vcproj +++ b/proj/vc7ide/doc_anonymous_upgradable_mutexB.vcproj @@ -124,14 +124,9 @@ Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx" UniqueIdentifier="{4B712E2E-5347-A352-8C9F-FF72D27982A2}"> + RelativePath="..\..\example\comp_doc_anonymous_upgradable_mutexB.cpp"> - - diff --git a/proj/vc7ide/doc_bufferstream.vcproj b/proj/vc7ide/doc_bufferstream.vcproj index 1430223..129e265 100644 --- a/proj/vc7ide/doc_bufferstream.vcproj +++ b/proj/vc7ide/doc_bufferstream.vcproj @@ -127,11 +127,6 @@ RelativePath="..\..\example\doc_bufferstream.cpp"> - - diff --git a/proj/vc7ide/doc_cached_adaptive_pool.vcproj b/proj/vc7ide/doc_cached_adaptive_pool.vcproj index 86c6b9d..5164354 100644 --- a/proj/vc7ide/doc_cached_adaptive_pool.vcproj +++ b/proj/vc7ide/doc_cached_adaptive_pool.vcproj @@ -127,11 +127,6 @@ RelativePath="..\..\example\doc_cached_adaptive_pool.cpp"> - - diff --git a/proj/vc7ide/doc_cached_node_allocator.vcproj b/proj/vc7ide/doc_cached_node_allocator.vcproj index 3824942..e2f4655 100644 --- a/proj/vc7ide/doc_cached_node_allocator.vcproj +++ b/proj/vc7ide/doc_cached_node_allocator.vcproj @@ -127,11 +127,6 @@ RelativePath="..\..\example\doc_cached_node_allocator.cpp"> - - diff --git a/proj/vc7ide/doc_cont.vcproj b/proj/vc7ide/doc_cont.vcproj index 9d9126c..f19202d 100644 --- a/proj/vc7ide/doc_cont.vcproj +++ b/proj/vc7ide/doc_cont.vcproj @@ -127,11 +127,6 @@ RelativePath="..\..\example\doc_cont.cpp"> - - diff --git a/proj/vc7ide/doc_contB.vcproj b/proj/vc7ide/doc_contB.vcproj index 85807ca..9f545a6 100644 --- a/proj/vc7ide/doc_contB.vcproj +++ b/proj/vc7ide/doc_contB.vcproj @@ -124,14 +124,9 @@ Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx" UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"> + RelativePath="..\..\example\comp_doc_contB.cpp"> - - diff --git a/proj/vc7ide/doc_file_mapping.vcproj b/proj/vc7ide/doc_file_mapping.vcproj index b71b7cb..215ca40 100644 --- a/proj/vc7ide/doc_file_mapping.vcproj +++ b/proj/vc7ide/doc_file_mapping.vcproj @@ -127,11 +127,6 @@ RelativePath="..\..\example\doc_file_mapping.cpp"> - - diff --git a/proj/vc7ide/doc_file_mapping2.vcproj b/proj/vc7ide/doc_file_mapping2.vcproj deleted file mode 100644 index 9071a47..0000000 --- a/proj/vc7ide/doc_file_mapping2.vcproj +++ /dev/null @@ -1,138 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/proj/vc7ide/doc_intrusive.vcproj b/proj/vc7ide/doc_intrusive.vcproj index f1cbee5..757b60c 100644 --- a/proj/vc7ide/doc_intrusive.vcproj +++ b/proj/vc7ide/doc_intrusive.vcproj @@ -127,11 +127,6 @@ RelativePath="..\..\example\doc_intrusive.cpp"> - - diff --git a/proj/vc7ide/doc_ipc_messageA.vcproj b/proj/vc7ide/doc_ipc_message.vcproj similarity index 87% rename from proj/vc7ide/doc_ipc_messageA.vcproj rename to proj/vc7ide/doc_ipc_message.vcproj index d3ee38a..5e2208a 100644 --- a/proj/vc7ide/doc_ipc_messageA.vcproj +++ b/proj/vc7ide/doc_ipc_message.vcproj @@ -2,7 +2,7 @@ @@ -13,7 +13,7 @@ @@ -67,7 +67,7 @@ + RelativePath="..\..\example\doc_ipc_message.cpp"> - - diff --git a/proj/vc7ide/doc_managed_aligned_allocation.vcproj b/proj/vc7ide/doc_managed_aligned_allocation.vcproj index 0be1539..455d93f 100644 --- a/proj/vc7ide/doc_managed_aligned_allocation.vcproj +++ b/proj/vc7ide/doc_managed_aligned_allocation.vcproj @@ -127,11 +127,6 @@ RelativePath="..\..\example\doc_managed_aligned_allocation.cpp"> - - diff --git a/proj/vc7ide/doc_managed_allocation_command.vcproj b/proj/vc7ide/doc_managed_allocation_command.vcproj index f9ff6f1..367eb81 100644 --- a/proj/vc7ide/doc_managed_allocation_command.vcproj +++ b/proj/vc7ide/doc_managed_allocation_command.vcproj @@ -127,11 +127,6 @@ RelativePath="..\..\example\doc_managed_allocation_command.cpp"> - - diff --git a/proj/vc7ide/doc_managed_construction_info.vcproj b/proj/vc7ide/doc_managed_construction_info.vcproj index 36f749f..2ff84df6 100644 --- a/proj/vc7ide/doc_managed_construction_info.vcproj +++ b/proj/vc7ide/doc_managed_construction_info.vcproj @@ -127,11 +127,6 @@ RelativePath="..\..\example\doc_managed_construction_info.cpp"> - - diff --git a/proj/vc7ide/doc_managed_grow.vcproj b/proj/vc7ide/doc_managed_grow.vcproj index 8355e3b..a516ede 100644 --- a/proj/vc7ide/doc_managed_grow.vcproj +++ b/proj/vc7ide/doc_managed_grow.vcproj @@ -128,11 +128,6 @@ RelativePath="..\..\example\doc_managed_grow.cpp"> - - diff --git a/proj/vc7ide/doc_managed_heap_memory.vcproj b/proj/vc7ide/doc_managed_heap_memory.vcproj index fb63372..046ce13 100644 --- a/proj/vc7ide/doc_managed_heap_memory.vcproj +++ b/proj/vc7ide/doc_managed_heap_memory.vcproj @@ -127,11 +127,6 @@ RelativePath="..\..\example\doc_managed_heap_memory.cpp"> - - diff --git a/proj/vc7ide/doc_managed_mapped_file.vcproj b/proj/vc7ide/doc_managed_mapped_file.vcproj index 31a7c39..d0588af 100644 --- a/proj/vc7ide/doc_managed_mapped_file.vcproj +++ b/proj/vc7ide/doc_managed_mapped_file.vcproj @@ -127,11 +127,6 @@ RelativePath="..\..\example\doc_managed_mapped_file.cpp"> - - diff --git a/proj/vc7ide/doc_managed_multiple_allocation.vcproj b/proj/vc7ide/doc_managed_multiple_allocation.vcproj index fc35fde..69b2afc 100644 --- a/proj/vc7ide/doc_managed_multiple_allocation.vcproj +++ b/proj/vc7ide/doc_managed_multiple_allocation.vcproj @@ -128,11 +128,6 @@ RelativePath="..\..\example\doc_managed_multiple_allocation.cpp"> - - diff --git a/proj/vc7ide/doc_managed_raw_allocation.vcproj b/proj/vc7ide/doc_managed_raw_allocation.vcproj index 1269082..f537e1f 100644 --- a/proj/vc7ide/doc_managed_raw_allocation.vcproj +++ b/proj/vc7ide/doc_managed_raw_allocation.vcproj @@ -127,11 +127,6 @@ RelativePath="..\..\example\doc_managed_raw_allocation.cpp"> - - diff --git a/proj/vc7ide/doc_map.vcproj b/proj/vc7ide/doc_map.vcproj index 7c49867..9ac8ca3 100644 --- a/proj/vc7ide/doc_map.vcproj +++ b/proj/vc7ide/doc_map.vcproj @@ -127,11 +127,6 @@ RelativePath="..\..\example\doc_map.cpp"> - - diff --git a/proj/vc7ide/doc_message_queueA.vcproj b/proj/vc7ide/doc_message_queueA.vcproj index daf452c..f05e0fa 100644 --- a/proj/vc7ide/doc_message_queueA.vcproj +++ b/proj/vc7ide/doc_message_queueA.vcproj @@ -124,14 +124,9 @@ Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx" UniqueIdentifier="{42FBE7AD-C8A9-12A0-5347-72FFA25175A2}"> + RelativePath="..\..\example\comp_doc_message_queueA.cpp"> - - diff --git a/proj/vc7ide/doc_message_queueB.vcproj b/proj/vc7ide/doc_message_queueB.vcproj index 974b1a5..773af14 100644 --- a/proj/vc7ide/doc_message_queueB.vcproj +++ b/proj/vc7ide/doc_message_queueB.vcproj @@ -124,14 +124,9 @@ Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx" UniqueIdentifier="{412EC7F1-45A7-98CA-A012-7952A2D2AFF2}"> + RelativePath="..\..\example\comp_doc_message_queueB.cpp"> - - diff --git a/proj/vc7ide/doc_move_containers.vcproj b/proj/vc7ide/doc_move_containers.vcproj index 30c5981..5d91966 100644 --- a/proj/vc7ide/doc_move_containers.vcproj +++ b/proj/vc7ide/doc_move_containers.vcproj @@ -127,11 +127,6 @@ RelativePath="..\..\example\doc_move_containers.cpp"> - - diff --git a/proj/vc7ide/doc_named_allocA.vcproj b/proj/vc7ide/doc_named_alloc.vcproj similarity index 87% rename from proj/vc7ide/doc_named_allocA.vcproj rename to proj/vc7ide/doc_named_alloc.vcproj index 3954d12..68b97f9 100644 --- a/proj/vc7ide/doc_named_allocA.vcproj +++ b/proj/vc7ide/doc_named_alloc.vcproj @@ -2,7 +2,7 @@ @@ -13,7 +13,7 @@ @@ -67,7 +67,7 @@ + RelativePath="..\..\example\doc_named_alloc.cpp"> - - diff --git a/proj/vc7ide/doc_named_allocB.vcproj b/proj/vc7ide/doc_named_allocB.vcproj deleted file mode 100644 index 09f43f8..0000000 --- a/proj/vc7ide/doc_named_allocB.vcproj +++ /dev/null @@ -1,138 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/proj/vc7ide/doc_named_conditionA.vcproj b/proj/vc7ide/doc_named_conditionA.vcproj index 73fb140..909275b 100644 --- a/proj/vc7ide/doc_named_conditionA.vcproj +++ b/proj/vc7ide/doc_named_conditionA.vcproj @@ -124,14 +124,9 @@ Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx" UniqueIdentifier="{AB2F71E1-2E95-7FA3-2A10-741FA12A22F2}"> + RelativePath="..\..\example\comp_doc_named_conditionA.cpp"> - - diff --git a/proj/vc7ide/doc_named_conditionB.vcproj b/proj/vc7ide/doc_named_conditionB.vcproj index cb2bdd7..1ac14ae 100644 --- a/proj/vc7ide/doc_named_conditionB.vcproj +++ b/proj/vc7ide/doc_named_conditionB.vcproj @@ -124,14 +124,9 @@ Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx" UniqueIdentifier="{AB712FE1-92E5-7543-12A0-74522FFA12A2}"> + RelativePath="..\..\example\comp_doc_named_conditionB.cpp"> - - diff --git a/proj/vc7ide/doc_named_mutex.vcproj b/proj/vc7ide/doc_named_mutex.vcproj index 9aa0582..874a7a1 100644 --- a/proj/vc7ide/doc_named_mutex.vcproj +++ b/proj/vc7ide/doc_named_mutex.vcproj @@ -127,11 +127,6 @@ RelativePath="..\..\example\doc_named_mutex.cpp"> - - diff --git a/proj/vc7ide/doc_node_allocator.vcproj b/proj/vc7ide/doc_node_allocator.vcproj index 03c0a52..269ca8a 100644 --- a/proj/vc7ide/doc_node_allocator.vcproj +++ b/proj/vc7ide/doc_node_allocator.vcproj @@ -127,11 +127,6 @@ RelativePath="..\..\example\doc_node_allocator.cpp"> - - diff --git a/proj/vc7ide/doc_offset_ptr.vcproj b/proj/vc7ide/doc_offset_ptr.vcproj index 4768fa8..58d1ffd 100644 --- a/proj/vc7ide/doc_offset_ptr.vcproj +++ b/proj/vc7ide/doc_offset_ptr.vcproj @@ -127,11 +127,6 @@ RelativePath="..\..\example\doc_offset_ptr.cpp"> - - diff --git a/proj/vc7ide/doc_private_adaptive_pool.vcproj b/proj/vc7ide/doc_private_adaptive_pool.vcproj index ad9eda0..7a50b91 100644 --- a/proj/vc7ide/doc_private_adaptive_pool.vcproj +++ b/proj/vc7ide/doc_private_adaptive_pool.vcproj @@ -127,11 +127,6 @@ RelativePath="..\..\example\doc_private_adaptive_pool.cpp"> - - diff --git a/proj/vc7ide/doc_private_node_allocator.vcproj b/proj/vc7ide/doc_private_node_allocator.vcproj index b60943b..22ca032 100644 --- a/proj/vc7ide/doc_private_node_allocator.vcproj +++ b/proj/vc7ide/doc_private_node_allocator.vcproj @@ -127,11 +127,6 @@ RelativePath="..\..\example\doc_private_node_allocator.cpp"> - - diff --git a/proj/vc7ide/doc_scoped_ptr.vcproj b/proj/vc7ide/doc_scoped_ptr.vcproj index ec2dc09..e6a62dd 100644 --- a/proj/vc7ide/doc_scoped_ptr.vcproj +++ b/proj/vc7ide/doc_scoped_ptr.vcproj @@ -127,11 +127,6 @@ RelativePath="..\..\example\doc_scoped_ptr.cpp"> - - diff --git a/proj/vc7ide/doc_shared_memory.vcproj b/proj/vc7ide/doc_shared_memory.vcproj index f085b5e..66a1de0 100644 --- a/proj/vc7ide/doc_shared_memory.vcproj +++ b/proj/vc7ide/doc_shared_memory.vcproj @@ -127,11 +127,6 @@ RelativePath="..\..\example\doc_shared_memory.cpp"> - - diff --git a/proj/vc7ide/doc_shared_memory2.vcproj b/proj/vc7ide/doc_shared_memory2.vcproj deleted file mode 100644 index 4c454cd..0000000 --- a/proj/vc7ide/doc_shared_memory2.vcproj +++ /dev/null @@ -1,138 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/proj/vc7ide/doc_shared_ptr.vcproj b/proj/vc7ide/doc_shared_ptr.vcproj index bf0ecd7..160d883 100644 --- a/proj/vc7ide/doc_shared_ptr.vcproj +++ b/proj/vc7ide/doc_shared_ptr.vcproj @@ -127,11 +127,6 @@ RelativePath="..\..\example\doc_shared_ptr.cpp"> - - diff --git a/proj/vc7ide/doc_shared_ptr_explicit.vcproj b/proj/vc7ide/doc_shared_ptr_explicit.vcproj index c10bbdb..77480ad 100644 --- a/proj/vc7ide/doc_shared_ptr_explicit.vcproj +++ b/proj/vc7ide/doc_shared_ptr_explicit.vcproj @@ -127,11 +127,6 @@ RelativePath="..\..\example\doc_shared_ptr_explicit.cpp"> - - diff --git a/proj/vc7ide/doc_contA.vcproj b/proj/vc7ide/doc_spawn_vector.vcproj similarity index 88% rename from proj/vc7ide/doc_contA.vcproj rename to proj/vc7ide/doc_spawn_vector.vcproj index 7891af8..a6a6726 100644 --- a/proj/vc7ide/doc_contA.vcproj +++ b/proj/vc7ide/doc_spawn_vector.vcproj @@ -2,7 +2,7 @@ @@ -13,7 +13,7 @@ @@ -67,7 +67,7 @@ + RelativePath="..\..\example\doc_spawn_vector.cpp"> - - diff --git a/proj/vc7ide/doc_unique_ptr.vcproj b/proj/vc7ide/doc_unique_ptr.vcproj index f2cc7b5..39dd224 100644 --- a/proj/vc7ide/doc_unique_ptr.vcproj +++ b/proj/vc7ide/doc_unique_ptr.vcproj @@ -127,11 +127,6 @@ RelativePath="..\..\example\doc_unique_ptr.cpp"> - - diff --git a/proj/vc7ide/doc_vectorstream.vcproj b/proj/vc7ide/doc_vectorstream.vcproj index 9e2b8fc..9504650 100644 --- a/proj/vc7ide/doc_vectorstream.vcproj +++ b/proj/vc7ide/doc_vectorstream.vcproj @@ -127,11 +127,6 @@ RelativePath="..\..\example\doc_vectorstream.cpp"> - - diff --git a/proj/vc7ide/doc_where_allocate.vcproj b/proj/vc7ide/doc_where_allocate.vcproj index 9a255f5..6bd2493 100644 --- a/proj/vc7ide/doc_where_allocate.vcproj +++ b/proj/vc7ide/doc_where_allocate.vcproj @@ -127,11 +127,6 @@ RelativePath="..\..\example\doc_where_allocate.cpp"> - - diff --git a/proj/vc7ide/doc_windows_shared_memory.vcproj b/proj/vc7ide/doc_windows_shared_memory.vcproj index 990cb2c..dd6357d 100644 --- a/proj/vc7ide/doc_windows_shared_memory.vcproj +++ b/proj/vc7ide/doc_windows_shared_memory.vcproj @@ -127,11 +127,6 @@ RelativePath="..\..\example\doc_windows_shared_memory.cpp"> - - diff --git a/proj/vc7ide/doc_windows_shared_memory2.vcproj b/proj/vc7ide/doc_windows_shared_memory2.vcproj index 011cfbf..2be8642 100644 --- a/proj/vc7ide/doc_windows_shared_memory2.vcproj +++ b/proj/vc7ide/doc_windows_shared_memory2.vcproj @@ -39,7 +39,7 @@ LinkIncremental="1" AdditionalLibraryDirectories="../../../../stage/lib" GenerateDebugInformation="TRUE" - ProgramDatabaseFile="$(OutDir)/doc_windows_shared_memory2.pdb" + ProgramDatabaseFile="$(OutDir)/doc_windows_shared_memoryB.pdb" SubSystem="1" TargetMachine="1" FixedBaseAddress="1"/> @@ -86,7 +86,7 @@ + RelativePath="..\..\example\comp_doc_windows_shared_memoryB.cpp"> - - diff --git a/proj/vc7ide/interprocesslib.vcproj b/proj/vc7ide/interprocesslib.vcproj index abf9115..83dd2cf 100644 --- a/proj/vc7ide/interprocesslib.vcproj +++ b/proj/vc7ide/interprocesslib.vcproj @@ -119,25 +119,15 @@ + + - - - - - - - - + + @@ -361,18 +354,9 @@ - - - - - - @@ -385,9 +369,6 @@ - - @@ -397,9 +378,6 @@ - - @@ -418,9 +396,6 @@ - - @@ -454,6 +429,9 @@ + + @@ -463,9 +441,6 @@ - - diff --git a/proj/vc7ide/shared_memory_mappable_test.vcproj b/proj/vc7ide/shared_memory_mappable_test.vcproj index 2954e48..da82e29 100644 --- a/proj/vc7ide/shared_memory_mappable_test.vcproj +++ b/proj/vc7ide/shared_memory_mappable_test.vcproj @@ -22,9 +22,11 @@ AdditionalIncludeDirectories="../../../.." PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;BOOST_DATE_TIME_NO_LIB" GeneratePreprocessedFile="0" + KeepComments="FALSE" MinimalRebuild="TRUE" BasicRuntimeChecks="3" RuntimeLibrary="3" + DisableLanguageExtensions="FALSE" TreatWChar_tAsBuiltInType="TRUE" ForceConformanceInForLoopScope="FALSE" UsePrecompiledHeader="0" diff --git a/proj/vc7ide/doc_ipc_messageB.vcproj b/proj/vc7ide/stable_vector_test.vcproj similarity index 83% rename from proj/vc7ide/doc_ipc_messageB.vcproj rename to proj/vc7ide/stable_vector_test.vcproj index b3317e9..fdc2192 100644 --- a/proj/vc7ide/doc_ipc_messageB.vcproj +++ b/proj/vc7ide/stable_vector_test.vcproj @@ -2,8 +2,8 @@ @@ -67,7 +67,7 @@ + UniqueIdentifier="{37BC807F-2451-A306-7AC5-7A35A32A22DF}"> + RelativePath="..\..\test\stable_vector_test.cpp"> - - diff --git a/proj/vc7ide/string_test.vcproj b/proj/vc7ide/string_test.vcproj index 5bd6b2d..77f6f35 100644 --- a/proj/vc7ide/string_test.vcproj +++ b/proj/vc7ide/string_test.vcproj @@ -21,6 +21,7 @@ Optimization="0" AdditionalIncludeDirectories="../../../.." PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;BOOST_DATE_TIME_NO_LIB" + GeneratePreprocessedFile="0" MinimalRebuild="TRUE" BasicRuntimeChecks="3" RuntimeLibrary="3" diff --git a/proj/vc7ide/windows_shared_memory_mapping_test.vcproj b/proj/vc7ide/windows_shared_memory_mapping_test.vcproj index 67d5880..e488012 100644 --- a/proj/vc7ide/windows_shared_memory_mapping_test.vcproj +++ b/proj/vc7ide/windows_shared_memory_mapping_test.vcproj @@ -13,7 +13,7 @@ @@ -67,7 +67,7 @@ #include "node_pool_test.hpp" #include diff --git a/test/allocator_v1.hpp b/test/allocator_v1.hpp index d52a039..3974046 100644 --- a/test/allocator_v1.hpp +++ b/test/allocator_v1.hpp @@ -18,10 +18,12 @@ #include #include +#include + #include -#include +#include #include -#include +#include #include #include #include @@ -49,10 +51,10 @@ class allocator_v1 typedef typename segment_manager::void_pointer aux_pointer_t; typedef typename - detail::pointer_to_other + boost::pointer_to_other ::type cvoid_ptr; - typedef typename detail::pointer_to_other + typedef typename boost::pointer_to_other ::type alloc_ptr_t; template @@ -64,9 +66,9 @@ class allocator_v1 public: typedef T value_type; - typedef typename detail::pointer_to_other + typedef typename boost::pointer_to_other ::type pointer; - typedef typename detail:: + typedef typename boost:: pointer_to_other::type const_pointer; typedef typename detail::add_reference ::type reference; diff --git a/test/check_equal_containers.hpp b/test/check_equal_containers.hpp index dd68998..fb15530 100644 --- a/test/check_equal_containers.hpp +++ b/test/check_equal_containers.hpp @@ -32,10 +32,12 @@ bool CheckEqualContainers(MyShmCont *shmcont, MyStdCont *stdcont) typename MyShmCont::iterator itshm(shmcont->begin()), itshmend(shmcont->end()); typename MyStdCont::iterator itstd(stdcont->begin()); - if((typename MyStdCont::size_type)std::distance(itshm, itshmend) != shmcont->size()){ + typename MyStdCont::size_type dist = (typename MyStdCont::size_type)std::distance(itshm, itshmend); + if(dist != shmcont->size()){ return false; } - for(; itshm != itshmend; ++itshm, ++itstd){ + std::size_t i = 0; + for(; itshm != itshmend; ++itshm, ++itstd, ++i){ value_type val(*itstd); const value_type &v = *itshm; if(v != val) diff --git a/test/data_test.cpp b/test/data_test.cpp index 66bb0dc..5c5f15a 100644 --- a/test/data_test.cpp +++ b/test/data_test.cpp @@ -17,7 +17,6 @@ #include #include #include -#include //std::remove #include "print_container.hpp" #include "get_process_id_name.hpp" @@ -29,8 +28,6 @@ int main () std::string process_name; test::get_process_id_name(process_name); const char *const shMemName = process_name.c_str(); - std::string filename (test::get_process_id_name()); - filename += "_file"; try{ shared_memory_object::remove(shMemName); @@ -90,12 +87,9 @@ int main () res = (0 == segment.find(allocName).first); if(!res) return 1; - - std::remove(filename.c_str()); } } catch(...){ - std::remove(filename.c_str()); shared_memory_object::remove(shMemName); throw; } diff --git a/test/deque_test.cpp b/test/deque_test.cpp index 3046d46..94e1763 100644 --- a/test/deque_test.cpp +++ b/test/deque_test.cpp @@ -26,7 +26,6 @@ #include #include "allocator_v1.hpp" #include -#include #include #include #include @@ -67,12 +66,12 @@ bool copyable_only(V1 *shmdeque, V2 *stddeque, detail::true_type) { IntType move_me(1); stddeque->insert(stddeque->begin()+size/2, 50, 1); - shmdeque->insert(shmdeque->begin()+size/2, 50, detail::move_impl(move_me)); + shmdeque->insert(shmdeque->begin()+size/2, 50, boost::interprocess::move(move_me)); if(!test::CheckEqualContainers(shmdeque, stddeque)) return false; } { IntType move_me(2); - shmdeque->assign(shmdeque->size()/2, detail::move_impl(move_me)); + shmdeque->assign(shmdeque->size()/2, boost::interprocess::move(move_me)); stddeque->assign(stddeque->size()/2, 2); if(!test::CheckEqualContainers(shmdeque, stddeque)) return false; } @@ -81,13 +80,13 @@ bool copyable_only(V1 *shmdeque, V2 *stddeque, detail::true_type) stddeque->clear(); shmdeque->clear(); stddeque->insert(stddeque->begin(), 50, 1); - shmdeque->insert(shmdeque->begin(), 50, detail::move_impl(move_me)); + shmdeque->insert(shmdeque->begin(), 50, boost::interprocess::move(move_me)); if(!test::CheckEqualContainers(shmdeque, stddeque)) return false; stddeque->insert(stddeque->begin()+20, 50, 1); - shmdeque->insert(shmdeque->begin()+20, 50, detail::move_impl(move_me)); + shmdeque->insert(shmdeque->begin()+20, 50, boost::interprocess::move(move_me)); if(!test::CheckEqualContainers(shmdeque, stddeque)) return false; stddeque->insert(stddeque->begin()+20, 20, 1); - shmdeque->insert(shmdeque->begin()+20, 20, detail::move_impl(move_me)); + shmdeque->insert(shmdeque->begin()+20, 20, boost::interprocess::move(move_me)); if(!test::CheckEqualContainers(shmdeque, stddeque)) return false; } { @@ -95,13 +94,13 @@ bool copyable_only(V1 *shmdeque, V2 *stddeque, detail::true_type) stddeque->clear(); shmdeque->clear(); stddeque->insert(stddeque->end(), 50, 1); - shmdeque->insert(shmdeque->end(), 50, detail::move_impl(move_me)); + shmdeque->insert(shmdeque->end(), 50, boost::interprocess::move(move_me)); if(!test::CheckEqualContainers(shmdeque, stddeque)) return false; stddeque->insert(stddeque->end()-20, 50, 1); - shmdeque->insert(shmdeque->end()-20, 50, detail::move_impl(move_me)); + shmdeque->insert(shmdeque->end()-20, 50, boost::interprocess::move(move_me)); if(!test::CheckEqualContainers(shmdeque, stddeque)) return false; stddeque->insert(stddeque->end()-20, 20, 1); - shmdeque->insert(shmdeque->end()-20, 20, detail::move_impl(move_me)); + shmdeque->insert(shmdeque->end()-20, 20, boost::interprocess::move(move_me)); if(!test::CheckEqualContainers(shmdeque, stddeque)) return false; } @@ -127,10 +126,9 @@ bool do_test() { //Now test move semantics deque original; - deque move_ctor(detail::move_impl(original)); + deque move_ctor(boost::interprocess::move(original)); deque move_assign; - move_assign = detail::move_impl(move_ctor); - move_assign.swap(detail::move_impl(original)); + move_assign = boost::interprocess::move(move_ctor); move_assign.swap(original); } @@ -174,7 +172,7 @@ bool do_test() int i; for(i = 0; i < max*100; ++i){ IntType move_me(i); - shmdeque->insert(shmdeque->end(), detail::move_impl(move_me)); + shmdeque->insert(shmdeque->end(), boost::interprocess::move(move_me)); stddeque->insert(stddeque->end(), i); } if(!test::CheckEqualContainers(shmdeque, stddeque)) return false; @@ -184,7 +182,7 @@ bool do_test() for(i = 0; i < max*100; ++i){ IntType move_me(i); - shmdeque->push_back(detail::move_impl(move_me)); + shmdeque->push_back(boost::interprocess::move(move_me)); stddeque->push_back(i); } if(!test::CheckEqualContainers(shmdeque, stddeque)) return false; @@ -194,7 +192,7 @@ bool do_test() for(i = 0; i < max*100; ++i){ IntType move_me(i); - shmdeque->push_front(detail::move_impl(move_me)); + shmdeque->push_front(boost::interprocess::move(move_me)); stddeque->push_front(i); } if(!test::CheckEqualContainers(shmdeque, stddeque)) return false; @@ -215,7 +213,7 @@ bool do_test() IntType aux_vect[50]; for(int i = 0; i < 50; ++i){ IntType move_me (-1); - aux_vect[i] = detail::move_impl(move_me); + aux_vect[i] = boost::interprocess::move(move_me); } int aux_vect2[50]; for(int i = 0; i < 50; ++i){ @@ -223,8 +221,8 @@ bool do_test() } shmdeque->insert(shmdeque->end() - ,detail::make_move_iterator(&aux_vect[0]) - ,detail::make_move_iterator(aux_vect + 50)); + ,boost::interprocess::make_move_iterator(&aux_vect[0]) + ,boost::interprocess::make_move_iterator(aux_vect + 50)); stddeque->insert(stddeque->end(), aux_vect2, aux_vect2 + 50); if(!test::CheckEqualContainers(shmdeque, stddeque)) return false; @@ -238,21 +236,21 @@ bool do_test() IntType aux_vect[50]; for(int i = 0; i < 50; ++i){ IntType move_me(-1); - aux_vect[i] = detail::move_impl(move_me); + aux_vect[i] = boost::interprocess::move(move_me); } int aux_vect2[50]; for(int i = 0; i < 50; ++i){ aux_vect2[i] = -1; } shmdeque->insert(shmdeque->begin() - ,detail::make_move_iterator(&aux_vect[0]) - ,detail::make_move_iterator(aux_vect + 50)); + ,boost::interprocess::make_move_iterator(&aux_vect[0]) + ,boost::interprocess::make_move_iterator(aux_vect + 50)); stddeque->insert(stddeque->begin(), aux_vect2, aux_vect2 + 50); if(!test::CheckEqualContainers(shmdeque, stddeque)) return false; } if(!copyable_only(shmdeque, stddeque - ,detail::bool_::value>())){ + ,detail::bool_::value>())){ return false; } @@ -263,7 +261,7 @@ bool do_test() for(i = 0; i < max; ++i){ IntType move_me(i); - shmdeque->insert(shmdeque->begin(), detail::move_impl(move_me)); + shmdeque->insert(shmdeque->begin(), boost::interprocess::move(move_me)); stddeque->insert(stddeque->begin(), i); } if(!test::CheckEqualContainers(shmdeque, stddeque)) return false; diff --git a/test/dummy_test_allocator.hpp b/test/dummy_test_allocator.hpp index e8466f0..8a7af64 100644 --- a/test/dummy_test_allocator.hpp +++ b/test/dummy_test_allocator.hpp @@ -19,10 +19,10 @@ #include #include -#include +#include #include #include -#include +#include #include #include #include @@ -64,7 +64,7 @@ class dummy_test_allocator typedef std::size_t size_type; typedef std::ptrdiff_t difference_type; -// typedef detail::version_type version; +// typedef boost::interprocess::version_type version; template struct rebind @@ -111,7 +111,7 @@ class dummy_test_allocator //Experimental version 2 dummy_test_allocator functions std::pair - allocation_command(allocation_type, + allocation_command(boost::interprocess::allocation_type, size_type, size_type, size_type &, const pointer & = 0) diff --git a/test/emplace_test.hpp b/test/emplace_test.hpp index 103d8da..ba27eab 100644 --- a/test/emplace_test.hpp +++ b/test/emplace_test.hpp @@ -29,27 +29,18 @@ class EmplaceInt EmplaceInt& operator=(const EmplaceInt &o); public: + BOOST_INTERPROCESS_ENABLE_MOVE_EMULATION(EmplaceInt) + EmplaceInt(int a = 0, int b = 0, int c = 0, int d = 0, int e = 0) : a_(a), b_(b), c_(c), d_(d), e_(e) {} - #ifdef BOOST_INTERPROCESS_RVALUE_REFERENCE - EmplaceInt(EmplaceInt &&o) + EmplaceInt(BOOST_INTERPROCESS_RV_REF(EmplaceInt) o) : a_(o.a_), b_(o.b_), c_(o.c_), d_(o.d_), e_(o.e_) - #else - EmplaceInt(detail::moved_object mo) - : a_(mo.get().a_), b_(mo.get().b_), c_(mo.get().c_), d_(mo.get().d_), e_(mo.get().e_) - #endif {} - #ifdef BOOST_INTERPROCESS_RVALUE_REFERENCE - EmplaceInt& operator=(EmplaceInt &&o) + EmplaceInt& operator=(BOOST_INTERPROCESS_RV_REF(EmplaceInt) o) { - #else - EmplaceInt& operator=(detail::moved_object mo) - { - EmplaceInt &o = mo.get(); - #endif this->a_ = o.a_; this->b_ = o.b_; this->c_ = o.c_; @@ -93,12 +84,6 @@ class EmplaceInt } //namespace test { -template<> -struct is_movable -{ - static const bool value = true; -}; - namespace test { enum EmplaceOptions{ diff --git a/test/expand_bwd_test_allocator.hpp b/test/expand_bwd_test_allocator.hpp index 0a62b33..a773cee 100644 --- a/test/expand_bwd_test_allocator.hpp +++ b/test/expand_bwd_test_allocator.hpp @@ -19,10 +19,10 @@ #include #include -#include +#include #include #include -#include +#include #include #include #include @@ -64,7 +64,7 @@ class expand_bwd_test_allocator typedef std::size_t size_type; typedef std::ptrdiff_t difference_type; - typedef detail::version_type version; + typedef boost::interprocess::version_type version; template struct rebind @@ -118,14 +118,14 @@ class expand_bwd_test_allocator //Experimental version 2 expand_bwd_test_allocator functions std::pair - allocation_command(allocation_type command, + allocation_command(boost::interprocess::allocation_type command, size_type limit_size, size_type preferred_size, size_type &received_size, const pointer &reuse = 0) { (void)preferred_size; (void)reuse; (void)command; //This allocator only expands backwards! - assert(m_allocations == 0 || (command & expand_bwd)); + assert(m_allocations == 0 || (command & boost::interprocess::expand_bwd)); received_size = limit_size; diff --git a/test/file_lock_test.cpp b/test/file_lock_test.cpp index cc0c84c..e689256 100644 --- a/test/file_lock_test.cpp +++ b/test/file_lock_test.cpp @@ -11,12 +11,13 @@ #include #include #include +#include #include #include "mutex_test_template.hpp" #include "sharable_mutex_test_template.hpp" #include "get_process_id_name.hpp" #include -#include +#include //std::remove using namespace boost::interprocess; //This wrapper is necessary to have a default constructor @@ -49,16 +50,15 @@ int main () { scoped_lock sl(flock, test::delay(1)); } - }/* + } { //Now test move semantics file_lock mapping(test::get_process_id_name()); - file_lock move_ctor(detail::move_impl(mapping)); + file_lock move_ctor(boost::interprocess::move(mapping)); file_lock move_assign; - move_assign = detail::move_impl(move_ctor); - mapping.swap(detail::move_impl(move_assign)); + move_assign = boost::interprocess::move(move_ctor); mapping.swap(move_assign); - }*/ + } //test::test_all_lock(); //test::test_all_mutex(); diff --git a/test/file_mapping_test.cpp b/test/file_mapping_test.cpp index 2aa7e3f..1151fd1 100644 --- a/test/file_mapping_test.cpp +++ b/test/file_mapping_test.cpp @@ -16,12 +16,17 @@ #include #include //std::auto_ptr #include //std::exception -#include //std::remove #include //std::size_t #include "get_process_id_name.hpp" using namespace boost::interprocess; +file_mapping get_file_mapping() +{ + file_mapping f; + return file_mapping(boost::interprocess::move(f)); +} + int main () { try{ @@ -125,19 +130,19 @@ int main () { //Now test move semantics file_mapping mapping(test::get_process_id_name(), read_only); - file_mapping move_ctor(detail::move_impl(mapping)); + file_mapping move_ctor(boost::interprocess::move(mapping)); file_mapping move_assign; - move_assign = detail::move_impl(move_ctor); - mapping.swap(detail::move_impl(move_assign)); + move_assign = boost::interprocess::move(move_ctor); mapping.swap(move_assign); + file_mapping ret(get_file_mapping()); } } catch(std::exception &exc){ - std::remove(test::get_process_id_name()); + file_mapping::remove(test::get_process_id_name()); std::cout << "Unhandled exception: " << exc.what() << std::endl; throw; } - std::remove(test::get_process_id_name()); + file_mapping::remove(test::get_process_id_name()); return 0; } diff --git a/test/flat_tree_test.cpp b/test/flat_tree_test.cpp index e7ebd77..9bc3ae4 100644 --- a/test/flat_tree_test.cpp +++ b/test/flat_tree_test.cpp @@ -62,7 +62,7 @@ typedef basic_managed_shared_memory , rbtree_best_fit, - flat_map_index + iset_index > my_managed_shared_memory; //Alias allocator type @@ -132,10 +132,49 @@ public: { return a.id_ < b.id_; } }; +//Test recursive structures +class recursive_flat_multiset +{ +public: + int id_; + flat_multiset flat_set_; + friend bool operator< (const recursive_flat_multiset &a, const recursive_flat_set &b) + { return a.id_ < b.id_; } +}; + +class recursive_flat_multimap +{ +public: + int id_; + flat_map map_; + friend bool operator< (const recursive_flat_multimap &a, const recursive_flat_multimap &b) + { return a.id_ < b.id_; } +}; + +template +void test_move() +{ + //Now test move semantics + C original; + C move_ctor(boost::interprocess::move(original)); + C move_assign; + move_assign = boost::interprocess::move(move_ctor); + move_assign.swap(original); +} + int main() { using namespace boost::interprocess::test; + //Now test move semantics + { + test_move >(); + test_move >(); + test_move >(); + test_move >(); + } + + if (0 != set_test, SetOptions>()) return 1; - #endif //!defined(__GNUC__) + //#endif //!defined(__GNUC__) return 0; + } #include diff --git a/test/get_process_id_name.hpp b/test/get_process_id_name.hpp index df3bb8f..330cf58 100644 --- a/test/get_process_id_name.hpp +++ b/test/get_process_id_name.hpp @@ -23,8 +23,8 @@ namespace test{ inline void get_process_id_name(std::string &str) { std::stringstream sstr; - sstr << "process_" << boost::interprocess::detail::get_current_process_id(); - str = sstr.str(); + sstr << "process_" << boost::interprocess::detail::get_current_process_id() << std::ends; + str = sstr.str().c_str(); } inline const char *get_process_id_name() diff --git a/test/heap_allocator_v1.hpp b/test/heap_allocator_v1.hpp new file mode 100644 index 0000000..3e83045 --- /dev/null +++ b/test/heap_allocator_v1.hpp @@ -0,0 +1,159 @@ +/////////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2005-2007. 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. +// +/////////////////////////////////////////////////////////////////////////////// + +#ifndef BOOST_INTERPROCESS_HEAP_ALLOCATOR_V1_HPP +#define BOOST_INTERPROCESS_HEAP_ALLOCATOR_V1_HPP + +#if (defined _MSC_VER) && (_MSC_VER >= 1200) +# pragma once +#endif + +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +//!\file +//!Describes an heap_allocator_v1 that allocates portions of fixed size +//!memory buffer (shared memory, mapped file...) + +namespace boost { +namespace interprocess { +namespace test { + +//!An STL compatible heap_allocator_v1 that uses a segment manager as +//!memory source. The internal pointer type will of the same type (raw, smart) as +//!"typename SegmentManager::void_pointer" type. This allows +//!placing the heap_allocator_v1 in shared memory, memory mapped-files, etc...*/ +template +class heap_allocator_v1 +{ + private: + typedef heap_allocator_v1 self_t; + typedef SegmentManager segment_manager; + typedef typename segment_manager::void_pointer aux_pointer_t; + + typedef typename + boost::pointer_to_other + ::type cvoid_ptr; + + typedef typename boost::pointer_to_other + ::type alloc_ptr_t; + + template + heap_allocator_v1& operator=(const heap_allocator_v1&); + + heap_allocator_v1& operator=(const heap_allocator_v1&); + + alloc_ptr_t mp_mngr; + + public: + typedef T value_type; + typedef typename boost::pointer_to_other + ::type pointer; + typedef typename boost:: + pointer_to_other::type const_pointer; + typedef typename detail::add_reference + ::type reference; + typedef typename detail::add_reference + ::type const_reference; + typedef std::size_t size_type; + typedef std::ptrdiff_t difference_type; + + //!Obtains an heap_allocator_v1 of other type + template + struct rebind + { + typedef heap_allocator_v1 other; + }; + + //!Returns the segment manager. Never throws + segment_manager* get_segment_manager()const + { return detail::get_pointer(mp_mngr); } +/* + //!Returns address of mutable object. Never throws + pointer address(reference value) const + { return pointer(addressof(value)); } + + //!Returns address of non mutable object. Never throws + const_pointer address(const_reference value) const + { return const_pointer(addressof(value)); } +*/ + //!Constructor from the segment manager. Never throws + heap_allocator_v1(segment_manager *segment_mngr) + : mp_mngr(segment_mngr) { } + + //!Constructor from other heap_allocator_v1. Never throws + heap_allocator_v1(const heap_allocator_v1 &other) + : mp_mngr(other.get_segment_manager()){ } + + //!Constructor from related heap_allocator_v1. Never throws + template + heap_allocator_v1(const heap_allocator_v1 &other) + : mp_mngr(other.get_segment_manager()){} + + //!Allocates memory for an array of count elements. + //!Throws boost::interprocess::bad_alloc if there is no enough memory + pointer allocate(size_type count, cvoid_ptr hint = 0) + { (void)hint; return ::new value_type[count]; } + + //!Deallocates memory previously allocated. Never throws + void deallocate(const pointer &ptr, size_type) + { return ::delete[] detail::get_pointer(ptr) ; } + + //!Construct object, calling constructor. + //!Throws if T(const T&) throws + void construct(const pointer &ptr, const_reference value) + { new((void*)detail::get_pointer(ptr)) value_type(value); } + + //!Destroys object. Throws if object's destructor throws + void destroy(const pointer &ptr) + { BOOST_ASSERT(ptr != 0); (*ptr).~value_type(); } + + //!Returns the number of elements that could be allocated. Never throws + size_type max_size() const + { return mp_mngr->get_size(); } + + //!Swap segment manager. Does not throw. If each heap_allocator_v1 is placed in + //!different memory segments, the result is undefined. + friend void swap(self_t &alloc1, self_t &alloc2) + { detail::do_swap(alloc1.mp_mngr, alloc2.mp_mngr); } +}; + +//!Equality test for same type of heap_allocator_v1 +template inline +bool operator==(const heap_allocator_v1 &alloc1, + const heap_allocator_v1 &alloc2) + { return alloc1.get_segment_manager() == alloc2.get_segment_manager(); } + +//!Inequality test for same type of heap_allocator_v1 +template inline +bool operator!=(const heap_allocator_v1 &alloc1, + const heap_allocator_v1 &alloc2) + { return alloc1.get_segment_manager() != alloc2.get_segment_manager(); } + +} //namespace test { +} //namespace interprocess { +} //namespace boost { + +#include + +#endif //BOOST_INTERPROCESS_HEAP_ALLOCATOR_V1_HPP + diff --git a/test/list_test.cpp b/test/list_test.cpp index d7f58dd..2e95d9d 100644 --- a/test/list_test.cpp +++ b/test/list_test.cpp @@ -54,10 +54,9 @@ int main () { //Now test move semantics list original; - list move_ctor(detail::move_impl(original)); + list move_ctor(boost::interprocess::move(original)); list move_assign; - move_assign = detail::move_impl(move_ctor); - move_assign.swap(detail::move_impl(original)); + move_assign = boost::interprocess::move(move_ctor); move_assign.swap(original); } if(test::list_test()) diff --git a/test/list_test.hpp b/test/list_test.hpp index 390f61e..a9de4c8 100644 --- a/test/list_test.hpp +++ b/test/list_test.hpp @@ -19,7 +19,6 @@ #include #include "print_container.hpp" #include -#include #include #include "get_process_id_name.hpp" @@ -36,7 +35,7 @@ struct push_data_function typedef typename MyShmList::value_type IntType; for(int i = 0; i < max; ++i){ IntType move_me(i); - shmlist->push_back(detail::move_impl(move_me)); + shmlist->push_back(boost::interprocess::move(move_me)); stdlist->push_back(i); } if(!CheckEqualContainers(shmlist, stdlist)) @@ -54,7 +53,7 @@ struct push_data_function typedef typename MyShmList::value_type IntType; for(int i = 0; i < max; ++i){ IntType move_me(i); - shmlist->push_front(detail::move_impl(move_me)); + shmlist->push_front(boost::interprocess::move(move_me)); stdlist->push_front(i); } if(!CheckEqualContainers(shmlist, stdlist)) @@ -113,6 +112,7 @@ int list_test (bool copied_allocators_equal = true) MyShmList *shmlist = segment.template construct("MyList") (segment.get_segment_manager()); + MyStdList *stdlist = new MyStdList; if(push_data_t::execute(max, shmlist, stdlist)){ @@ -135,14 +135,14 @@ int list_test (bool copied_allocators_equal = true) IntType aux_vect[50]; for(int i = 0; i < 50; ++i){ IntType move_me(-1); - aux_vect[i] = detail::move_impl(move_me); + aux_vect[i] = boost::interprocess::move(move_me); } int aux_vect2[50]; for(int i = 0; i < 50; ++i){ aux_vect2[i] = -1; } - shmlist->assign(detail::make_move_iterator(&aux_vect[0]) - ,detail::make_move_iterator(&aux_vect[50])); + shmlist->assign(boost::interprocess::make_move_iterator(&aux_vect[0]) + ,boost::interprocess::make_move_iterator(&aux_vect[50])); stdlist->assign(&aux_vect2[0], &aux_vect2[50]); if(!CheckEqualContainers(shmlist, stdlist)) return 1; } @@ -165,15 +165,15 @@ int list_test (bool copied_allocators_equal = true) IntType aux_vect[50]; for(int i = 0; i < 50; ++i){ IntType move_me(-1); - aux_vect[i] = detail::move_impl(move_me); + aux_vect[i] = boost::interprocess::move(move_me); } int aux_vect2[50]; for(int i = 0; i < 50; ++i){ aux_vect2[i] = -1; } shmlist->insert(shmlist->begin() - ,detail::make_move_iterator(&aux_vect[0]) - ,detail::make_move_iterator(&aux_vect[50])); + ,boost::interprocess::make_move_iterator(&aux_vect[0]) + ,boost::interprocess::make_move_iterator(&aux_vect[50])); stdlist->insert(stdlist->begin(), &aux_vect2[0], &aux_vect2[50]); } diff --git a/test/managed_mapped_file_test.cpp b/test/managed_mapped_file_test.cpp index cebbfe5..f0b3f6e 100644 --- a/test/managed_mapped_file_test.cpp +++ b/test/managed_mapped_file_test.cpp @@ -31,7 +31,7 @@ int main () { //Remove the file it is already created - std::remove(FileName); + file_mapping::remove(FileName); const int max = 100; void *array[max]; @@ -52,7 +52,7 @@ int main () { //Remove the file it is already created - std::remove(FileName); + file_mapping::remove(FileName); //Named allocate capable memory mapped file managed memory class managed_mapped_file mfile(create_only, FileName, FileSize); @@ -203,15 +203,14 @@ int main () { //Now test move semantics managed_mapped_file original(open_only, FileName); - managed_mapped_file move_ctor(detail::move_impl(original)); + managed_mapped_file move_ctor(boost::interprocess::move(original)); managed_mapped_file move_assign; - move_assign = detail::move_impl(move_ctor); - move_assign.swap(detail::move_impl(original)); + move_assign = boost::interprocess::move(move_ctor); move_assign.swap(original); } } - std::remove(FileName); + file_mapping::remove(FileName); return 0; } diff --git a/test/managed_shared_memory_test.cpp b/test/managed_shared_memory_test.cpp index 1314038..f19fabe 100644 --- a/test/managed_shared_memory_test.cpp +++ b/test/managed_shared_memory_test.cpp @@ -199,10 +199,9 @@ int main () { //Now test move semantics managed_shared_memory original(open_only, ShmemName); - managed_shared_memory move_ctor(detail::move_impl(original)); + managed_shared_memory move_ctor(boost::interprocess::move(original)); managed_shared_memory move_assign; - move_assign = detail::move_impl(move_ctor); - move_assign.swap(detail::move_impl(original)); + move_assign = boost::interprocess::move(move_ctor); move_assign.swap(original); } } diff --git a/test/managed_windows_shared_memory_test.cpp b/test/managed_windows_shared_memory_test.cpp index f02868f..cdb1d68 100644 --- a/test/managed_windows_shared_memory_test.cpp +++ b/test/managed_windows_shared_memory_test.cpp @@ -9,8 +9,9 @@ ////////////////////////////////////////////////////////////////////////////// #include +#include -#ifdef BOOST_WINDOWS +#ifdef BOOST_INTERPROCESS_WINDOWS #include #include @@ -130,9 +131,9 @@ int main () //Now test move semantics managed_windows_shared_memory original(open_only, MemName); - managed_windows_shared_memory move_ctor(detail::move_impl(original)); + managed_windows_shared_memory move_ctor(boost::interprocess::move(original)); managed_windows_shared_memory move_assign; - move_assign = detail::move_impl(move_ctor); + move_assign = boost::interprocess::move(move_ctor); } } diff --git a/test/map_test.hpp b/test/map_test.hpp index 13363bf..c4e88f7 100644 --- a/test/map_test.hpp +++ b/test/map_test.hpp @@ -17,9 +17,8 @@ #include #include #include "print_container.hpp" -#include #include -#include +#include #include #include "get_process_id_name.hpp" @@ -41,7 +40,7 @@ template IntPairType; + typedef boost::interprocess::pair IntPairType; typedef typename MyStdMap::value_type StdPairType; const int memsize = 65536; const char *const shMemName = test::get_process_id_name(); @@ -73,7 +72,9 @@ int map_test () //This is really nasty, but we have no other simple choice IntPairType aux_vect[50]; for(int i = 0; i < 50; ++i){ - new(&aux_vect[i])IntPairType(IntType(i/2), IntType(i/2)); + IntType i1(i/2); + IntType i2(i/2); + new(&aux_vect[i])IntPairType(boost::interprocess::move(i1), boost::interprocess::move(i2)); } typedef typename MyStdMap::value_type StdValueType; @@ -86,21 +87,23 @@ int map_test () IntPairType aux_vect3[50]; for(int i = 0; i < 50; ++i){ - new(&aux_vect3[i])IntPairType(IntType(i/2), IntType(i/2)); + IntType i1(i/2); + IntType i2(i/2); + new(&aux_vect3[i])IntPairType(boost::interprocess::move(i1), boost::interprocess::move(i2)); } MyShmMap *shmmap2 = segment.template construct("MyShmMap2") - (detail::make_move_iterator(&aux_vect[0]) - , detail::make_move_iterator(aux_vect + 50) + (boost::interprocess::make_move_iterator(&aux_vect[0]) + , boost::interprocess::make_move_iterator(aux_vect + 50) , std::less(), segment.get_segment_manager()); MyStdMap *stdmap2 = new MyStdMap(aux_vect2, aux_vect2 + 50); MyShmMultiMap *shmmultimap2 = segment.template construct("MyShmMultiMap2") - (detail::make_move_iterator(&aux_vect3[0]) - , detail::make_move_iterator(aux_vect3 + 50) + (boost::interprocess::make_move_iterator(&aux_vect3[0]) + , boost::interprocess::make_move_iterator(aux_vect3 + 50) , std::less(), segment.get_segment_manager()); MyStdMultiMap *stdmultimap2 = new MyStdMultiMap(aux_vect2, aux_vect2 + 50); @@ -112,71 +115,89 @@ int map_test () delete stdmap2; delete stdmultimap2; } + { + //This is really nasty, but we have no other simple choice + IntPairType aux_vect[max]; + for(int i = 0; i < max; ++i){ + IntType i1(i); + IntType i2(i); + new(&aux_vect[i])IntPairType(boost::interprocess::move(i1), boost::interprocess::move(i2)); + } + IntPairType aux_vect3[max]; + for(int i = 0; i < max; ++i){ + IntType i1(i); + IntType i2(i); + new(&aux_vect3[i])IntPairType(boost::interprocess::move(i1), boost::interprocess::move(i2)); + } - int i, j; - for(i = 0; i < max; ++i){ - shmmap->insert(detail::move_impl(IntPairType (detail::move_impl(IntType(i)), detail::move_impl(IntType(i))))); - stdmap->insert(StdPairType(i, i)); - shmmultimap->insert(detail::move_impl(IntPairType(detail::move_impl(IntType(i)), detail::move_impl(IntType(i))))); - stdmultimap->insert(StdPairType(i, i)); + for(int i = 0; i < max; ++i){ + shmmap->insert(boost::interprocess::move(aux_vect[i])); + stdmap->insert(StdPairType(i, i)); + shmmultimap->insert(boost::interprocess::move(aux_vect3[i])); + stdmultimap->insert(StdPairType(i, i)); + } + + if(!CheckEqualPairContainers(shmmap, stdmap)) return 1; + if(!CheckEqualPairContainers(shmmultimap, stdmultimap)) return 1; + + typename MyShmMap::iterator it; + typename MyShmMap::const_iterator cit = it; + + shmmap->erase(shmmap->begin()++); + stdmap->erase(stdmap->begin()++); + shmmultimap->erase(shmmultimap->begin()++); + stdmultimap->erase(stdmultimap->begin()++); + if(!CheckEqualPairContainers(shmmap, stdmap)) return 1; + if(!CheckEqualPairContainers(shmmultimap, stdmultimap)) return 1; + + shmmap->erase(shmmap->begin()); + stdmap->erase(stdmap->begin()); + shmmultimap->erase(shmmultimap->begin()); + stdmultimap->erase(stdmultimap->begin()); + if(!CheckEqualPairContainers(shmmap, stdmap)) return 1; + if(!CheckEqualPairContainers(shmmultimap, stdmultimap)) return 1; + + //Swapping test + std::less lessfunc; + MyShmMap tmpshmemap2 (lessfunc, segment.get_segment_manager()); + MyStdMap tmpstdmap2; + MyShmMultiMap tmpshmemultimap2(lessfunc, segment.get_segment_manager()); + MyStdMultiMap tmpstdmultimap2; + shmmap->swap(tmpshmemap2); + stdmap->swap(tmpstdmap2); + shmmultimap->swap(tmpshmemultimap2); + stdmultimap->swap(tmpstdmultimap2); + shmmap->swap(tmpshmemap2); + stdmap->swap(tmpstdmap2); + shmmultimap->swap(tmpshmemultimap2); + stdmultimap->swap(tmpstdmultimap2); + if(!CheckEqualPairContainers(shmmap, stdmap)) return 1; + if(!CheckEqualPairContainers(shmmultimap, stdmultimap)) return 1; } - - if(!CheckEqualPairContainers(shmmap, stdmap)) return 1; - if(!CheckEqualPairContainers(shmmultimap, stdmultimap)) return 1; - - typename MyShmMap::iterator it; - typename MyShmMap::const_iterator cit = it; - - shmmap->erase(shmmap->begin()++); - stdmap->erase(stdmap->begin()++); - shmmultimap->erase(shmmultimap->begin()++); - stdmultimap->erase(stdmultimap->begin()++); - if(!CheckEqualPairContainers(shmmap, stdmap)) return 1; - if(!CheckEqualPairContainers(shmmultimap, stdmultimap)) return 1; - - shmmap->erase(shmmap->begin()); - stdmap->erase(stdmap->begin()); - shmmultimap->erase(shmmultimap->begin()); - stdmultimap->erase(stdmultimap->begin()); - if(!CheckEqualPairContainers(shmmap, stdmap)) return 1; - if(!CheckEqualPairContainers(shmmultimap, stdmultimap)) return 1; - - //Swapping test - std::less lessfunc; - MyShmMap tmpshmemap2 (lessfunc, segment.get_segment_manager()); - MyStdMap tmpstdmap2; - MyShmMultiMap tmpshmemultimap2(lessfunc, segment.get_segment_manager()); - MyStdMultiMap tmpstdmultimap2; - shmmap->swap(tmpshmemap2); - stdmap->swap(tmpstdmap2); - shmmultimap->swap(tmpshmemultimap2); - stdmultimap->swap(tmpstdmultimap2); - shmmap->swap(tmpshmemap2); - stdmap->swap(tmpstdmap2); - shmmultimap->swap(tmpshmemultimap2); - stdmultimap->swap(tmpstdmultimap2); - if(!CheckEqualPairContainers(shmmap, stdmap)) return 1; - if(!CheckEqualPairContainers(shmmultimap, stdmultimap)) return 1; - //Insertion from other container //Initialize values { //This is really nasty, but we have no other simple choice IntPairType aux_vect[50]; for(int i = 0; i < 50; ++i){ - new(&aux_vect[i])IntPairType(IntType(-1), IntType(-1)); + IntType i1(-1); + IntType i2(-1); + new(&aux_vect[i])IntPairType(boost::interprocess::move(i1), boost::interprocess::move(i2)); } IntPairType aux_vect3[50]; for(int i = 0; i < 50; ++i){ - new(&aux_vect3[i])IntPairType(IntType(-1), IntType(-1)); + IntType i1(-1); + IntType i2(-1); + new(&aux_vect3[i])IntPairType(boost::interprocess::move(i1), boost::interprocess::move(i2)); } - shmmap->insert(detail::make_move_iterator(&aux_vect[0]), detail::make_move_iterator(aux_vect + 50)); - StdPairType stdpairtype(-1, -1); - constant_iterator constant_beg(stdpairtype, 50), constant_end; - stdmap->insert(constant_beg, constant_end); - shmmultimap->insert(detail::make_move_iterator(&aux_vect3[0]), detail::make_move_iterator(aux_vect3 + 50)); - stdmultimap->insert(constant_beg, constant_end); + shmmap->insert(boost::interprocess::make_move_iterator(&aux_vect[0]), boost::interprocess::make_move_iterator(aux_vect + 50)); + shmmultimap->insert(boost::interprocess::make_move_iterator(&aux_vect3[0]), boost::interprocess::make_move_iterator(aux_vect3 + 50)); + for(std::size_t i = 0; i != 50; ++i){ + StdPairType stdpairtype(-1, -1); + stdmap->insert(stdpairtype); + stdmultimap->insert(stdpairtype); + } if(!CheckEqualPairContainers(shmmap, stdmap)) return 1; if(!CheckEqualPairContainers(shmmultimap, stdmultimap)) return 1; @@ -192,34 +213,44 @@ int map_test () { IntPairType aux_vect[50]; for(int i = 0; i < 50; ++i){ - new(&aux_vect[i])IntPairType(IntType(-1), IntType(-1)); + IntType i1(-1); + IntType i2(-1); + new(&aux_vect[i])IntPairType(boost::interprocess::move(i1), boost::interprocess::move(i2)); } IntPairType aux_vect3[50]; for(int i = 0; i < 50; ++i){ - new(&aux_vect3[i])IntPairType(IntType(-1), IntType(-1)); + IntType i1(-1); + IntType i2(-1); + new(&aux_vect3[i])IntPairType(boost::interprocess::move(i1), boost::interprocess::move(i2)); } IntPairType aux_vect4[50]; for(int i = 0; i < 50; ++i){ - new(&aux_vect4[i])IntPairType(IntType(-1), IntType(-1)); + IntType i1(-1); + IntType i2(-1); + new(&aux_vect4[i])IntPairType(boost::interprocess::move(i1), boost::interprocess::move(i2)); } IntPairType aux_vect5[50]; for(int i = 0; i < 50; ++i){ - new(&aux_vect5[i])IntPairType(IntType(-1), IntType(-1)); + IntType i1(-1); + IntType i2(-1); + new(&aux_vect5[i])IntPairType(boost::interprocess::move(i1), boost::interprocess::move(i2)); } - shmmap->insert(detail::make_move_iterator(&aux_vect[0]), detail::make_move_iterator(aux_vect + 50)); - shmmap->insert(detail::make_move_iterator(&aux_vect3[0]), detail::make_move_iterator(aux_vect3 + 50)); - StdPairType stdpairtype(-1, -1); - constant_iterator constant_beg(stdpairtype, 50), constant_end; - stdmap->insert(constant_beg, constant_end); - stdmap->insert(constant_beg, constant_end); - shmmultimap->insert(detail::make_move_iterator(&aux_vect4[0]), detail::make_move_iterator(aux_vect4 + 50)); - shmmultimap->insert(detail::make_move_iterator(&aux_vect5[0]), detail::make_move_iterator(aux_vect5 + 50)); - stdmultimap->insert(constant_beg, constant_end); - stdmultimap->insert(constant_beg, constant_end); + shmmap->insert(boost::interprocess::make_move_iterator(&aux_vect[0]), boost::interprocess::make_move_iterator(aux_vect + 50)); + shmmap->insert(boost::interprocess::make_move_iterator(&aux_vect3[0]), boost::interprocess::make_move_iterator(aux_vect3 + 50)); + shmmultimap->insert(boost::interprocess::make_move_iterator(&aux_vect4[0]), boost::interprocess::make_move_iterator(aux_vect4 + 50)); + shmmultimap->insert(boost::interprocess::make_move_iterator(&aux_vect5[0]), boost::interprocess::make_move_iterator(aux_vect5 + 50)); + + for(std::size_t i = 0; i != 50; ++i){ + StdPairType stdpairtype(-1, -1); + stdmap->insert(stdpairtype); + stdmultimap->insert(stdpairtype); + stdmap->insert(stdpairtype); + stdmultimap->insert(stdpairtype); + } if(!CheckEqualPairContainers(shmmap, stdmap)) return 1; if(!CheckEqualPairContainers(shmmultimap, stdmultimap)) return 1; @@ -231,84 +262,158 @@ int map_test () if(!CheckEqualPairContainers(shmmultimap, stdmultimap)) return 1; } - for(i = 0; i < max; ++i){ - shmmap->insert(detail::move_impl(IntPairType(detail::move_impl(IntType(i)), detail::move_impl(IntType(i))))); - stdmap->insert(StdPairType(i, i)); - shmmultimap->insert(detail::move_impl(IntPairType(detail::move_impl(IntType(i)), detail::move_impl(IntType(i))))); - stdmultimap->insert(StdPairType(i, i)); - } - - if(!CheckEqualPairContainers(shmmap, stdmap)) return 1; - if(!CheckEqualPairContainers(shmmultimap, stdmultimap)) return 1; - - for(i = 0; i < max; ++i){ - shmmap->insert(shmmap->begin(), detail::move_impl(IntPairType(detail::move_impl(IntType(i)), detail::move_impl(IntType(i))))); - stdmap->insert(stdmap->begin(), StdPairType(i, i)); - //PrintContainers(shmmap, stdmap); - shmmultimap->insert(shmmultimap->begin(), detail::move_impl(IntPairType(detail::move_impl(IntType(i)), detail::move_impl(IntType(i))))); - stdmultimap->insert(stdmultimap->begin(), StdPairType(i, i)); - //PrintContainers(shmmultimap, stdmultimap); - if(!CheckEqualPairContainers(shmmap, stdmap)) - return 1; - if(!CheckEqualPairContainers(shmmultimap, stdmultimap)) - return 1; - - shmmap->insert(shmmap->end(), detail::move_impl(IntPairType(detail::move_impl(IntType(i)), detail::move_impl(IntType(i))))); - stdmap->insert(stdmap->end(), StdPairType(i, i)); - shmmultimap->insert(shmmultimap->end(), detail::move_impl(IntPairType(detail::move_impl(IntType(i)), detail::move_impl(IntType(i))))); - stdmultimap->insert(stdmultimap->end(), StdPairType(i, i)); - if(!CheckEqualPairContainers(shmmap, stdmap)) - return 1; - if(!CheckEqualPairContainers(shmmultimap, stdmultimap)) - return 1; - - shmmap->insert(shmmap->lower_bound(IntType(i)), detail::move_impl(IntPairType(detail::move_impl(IntType(i)), detail::move_impl(IntType(i))))); - stdmap->insert(stdmap->lower_bound(i), StdPairType(i, i)); - //PrintContainers(shmmap, stdmap); - shmmultimap->insert(shmmultimap->lower_bound(IntType(i)), detail::move_impl(IntPairType(detail::move_impl(IntType(i)), detail::move_impl(IntType(i))))); - stdmultimap->insert(stdmultimap->lower_bound(i), StdPairType(i, i)); - //PrintContainers(shmmultimap, stdmultimap); - if(!CheckEqualPairContainers(shmmap, stdmap)) - return 1; - if(!CheckEqualPairContainers(shmmultimap, stdmultimap)) - return 1; - shmmap->insert(shmmap->upper_bound(IntType(i)), detail::move_impl(IntPairType(detail::move_impl(IntType(i)), detail::move_impl(IntType(i))))); - stdmap->insert(stdmap->upper_bound(i), StdPairType(i, i)); - //PrintContainers(shmmap, stdmap); - shmmultimap->insert(shmmultimap->upper_bound(IntType(i)), detail::move_impl(IntPairType(detail::move_impl(IntType(i)), detail::move_impl(IntType(i))))); - stdmultimap->insert(stdmultimap->upper_bound(i), StdPairType(i, i)); - //PrintContainers(shmmultimap, stdmultimap); - if(!CheckEqualPairContainers(shmmap, stdmap)) - return 1; - if(!CheckEqualPairContainers(shmmultimap, stdmultimap)) - return 1; - } - - //Compare count with std containers - for(i = 0; i < max; ++i){ - if(shmmap->count(IntType(i)) != stdmap->count(i)){ - return -1; + { + //This is really nasty, but we have no other simple choice + IntPairType aux_vect[max]; + for(int i = 0; i < max; ++i){ + IntType i1(i); + IntType i2(i); + new(&aux_vect[i])IntPairType(boost::interprocess::move(i1), boost::interprocess::move(i2)); + } + IntPairType aux_vect3[max]; + for(int i = 0; i < max; ++i){ + IntType i1(i); + IntType i2(i); + new(&aux_vect3[i])IntPairType(boost::interprocess::move(i1), boost::interprocess::move(i2)); } - if(shmmultimap->count(IntType(i)) != stdmultimap->count(i)){ - return -1; + for(int i = 0; i < max; ++i){ + shmmap->insert(boost::interprocess::move(aux_vect[i])); + stdmap->insert(StdPairType(i, i)); + shmmultimap->insert(boost::interprocess::move(aux_vect3[i])); + stdmultimap->insert(StdPairType(i, i)); } - } - //Now do count exercise - shmmap->erase(shmmap->begin(), shmmap->end()); - shmmultimap->erase(shmmultimap->begin(), shmmultimap->end()); - shmmap->clear(); - shmmultimap->clear(); + if(!CheckEqualPairContainers(shmmap, stdmap)) return 1; + if(!CheckEqualPairContainers(shmmultimap, stdmultimap)) return 1; - for(j = 0; j < 3; ++j) - for(i = 0; i < 100; ++i){ - shmmap->insert(detail::move_impl(IntPairType(detail::move_impl(IntType(i)), detail::move_impl(IntType(i))))); - shmmultimap->insert(detail::move_impl(IntPairType(detail::move_impl(IntType(i)), detail::move_impl(IntType(i))))); - if(shmmap->count(IntType(i)) != typename MyShmMultiMap::size_type(1)) - return 1; - if(shmmultimap->count(IntType(i)) != typename MyShmMultiMap::size_type(j+1)) - return 1; + for(int i = 0; i < max; ++i){ + IntPairType intpair; + { + IntType i1(i); + IntType i2(i); + new(&intpair)IntPairType(boost::interprocess::move(i1), boost::interprocess::move(i2)); + } + shmmap->insert(shmmap->begin(), boost::interprocess::move(intpair)); + stdmap->insert(stdmap->begin(), StdPairType(i, i)); + //PrintContainers(shmmap, stdmap); + { + IntType i1(i); + IntType i2(i); + new(&intpair)IntPairType(boost::interprocess::move(i1), boost::interprocess::move(i2)); + } + shmmultimap->insert(shmmultimap->begin(), boost::interprocess::move(intpair)); + stdmultimap->insert(stdmultimap->begin(), StdPairType(i, i)); + //PrintContainers(shmmultimap, stdmultimap); + if(!CheckEqualPairContainers(shmmap, stdmap)) + return 1; + if(!CheckEqualPairContainers(shmmultimap, stdmultimap)) + return 1; + { + IntType i1(i); + IntType i2(i); + new(&intpair)IntPairType(boost::interprocess::move(i1), boost::interprocess::move(i2)); + } + shmmap->insert(shmmap->end(), boost::interprocess::move(intpair)); + stdmap->insert(stdmap->end(), StdPairType(i, i)); + { + IntType i1(i); + IntType i2(i); + new(&intpair)IntPairType(boost::interprocess::move(i1), boost::interprocess::move(i2)); + } + shmmultimap->insert(shmmultimap->end(), boost::interprocess::move(intpair)); + stdmultimap->insert(stdmultimap->end(), StdPairType(i, i)); + if(!CheckEqualPairContainers(shmmap, stdmap)) + return 1; + if(!CheckEqualPairContainers(shmmultimap, stdmultimap)) + return 1; + { + IntType i1(i); + IntType i2(i); + new(&intpair)IntPairType(boost::interprocess::move(i1), boost::interprocess::move(i2)); + } + shmmap->insert(shmmap->lower_bound(IntType(i)), boost::interprocess::move(intpair)); + stdmap->insert(stdmap->lower_bound(i), StdPairType(i, i)); + //PrintContainers(shmmap, stdmap); + { + IntType i1(i); + IntType i2(i); + new(&intpair)IntPairType(boost::interprocess::move(i1), boost::interprocess::move(i2)); + } + { + IntType i1(i); + shmmultimap->insert(shmmultimap->lower_bound(boost::interprocess::move(i1)), boost::interprocess::move(intpair)); + stdmultimap->insert(stdmultimap->lower_bound(i), StdPairType(i, i)); + } + + //PrintContainers(shmmultimap, stdmultimap); + if(!CheckEqualPairContainers(shmmap, stdmap)) + return 1; + if(!CheckEqualPairContainers(shmmultimap, stdmultimap)) + return 1; + { + IntType i1(i); + IntType i2(i); + new(&intpair)IntPairType(boost::interprocess::move(i1), boost::interprocess::move(i2)); + } + { + IntType i1(i); + shmmap->insert(shmmap->upper_bound(boost::interprocess::move(i1)), boost::interprocess::move(intpair)); + stdmap->insert(stdmap->upper_bound(i), StdPairType(i, i)); + } + //PrintContainers(shmmap, stdmap); + { + IntType i1(i); + IntType i2(i); + new(&intpair)IntPairType(boost::interprocess::move(i1), boost::interprocess::move(i2)); + } + { + IntType i1(i); + shmmultimap->insert(shmmultimap->upper_bound(boost::interprocess::move(i1)), boost::interprocess::move(intpair)); + stdmultimap->insert(stdmultimap->upper_bound(i), StdPairType(i, i)); + } + //PrintContainers(shmmultimap, stdmultimap); + if(!CheckEqualPairContainers(shmmap, stdmap)) + return 1; + if(!CheckEqualPairContainers(shmmultimap, stdmultimap)) + return 1; + } + + //Compare count with std containers + for(int i = 0; i < max; ++i){ + if(shmmap->count(IntType(i)) != stdmap->count(i)){ + return -1; + } + + if(shmmultimap->count(IntType(i)) != stdmultimap->count(i)){ + return -1; + } + } + + //Now do count exercise + shmmap->erase(shmmap->begin(), shmmap->end()); + shmmultimap->erase(shmmultimap->begin(), shmmultimap->end()); + shmmap->clear(); + shmmultimap->clear(); + + for(int j = 0; j < 3; ++j) + for(int i = 0; i < 100; ++i){ + IntPairType intpair; + { + IntType i1(i), i2(i); + new(&intpair)IntPairType(boost::interprocess::move(i1), boost::interprocess::move(i2)); + } + shmmap->insert(boost::interprocess::move(intpair)); + { + IntType i1(i), i2(i); + new(&intpair)IntPairType(boost::interprocess::move(i1), boost::interprocess::move(i2)); + } + shmmultimap->insert(boost::interprocess::move(intpair)); + if(shmmap->count(IntType(i)) != typename MyShmMultiMap::size_type(1)) + return 1; + if(shmmultimap->count(IntType(i)) != typename MyShmMultiMap::size_type(j+1)) + return 1; + } } segment.template destroy("MyShmMap"); @@ -337,7 +442,7 @@ template IntPairType; + typedef boost::interprocess::pair IntPairType; typedef typename MyStdMap::value_type StdPairType; const int memsize = 65536; @@ -367,10 +472,18 @@ int map_test_copyable () int i; for(i = 0; i < max; ++i){ - shmmap->insert(detail::move_impl(IntPairType(detail::move_impl(IntType(i)), detail::move_impl(IntType(i))))); + { + IntType i1(i), i2(i); + IntPairType intpair1(boost::interprocess::move(i1), boost::interprocess::move(i2)); + shmmap->insert(boost::interprocess::move(intpair1)); stdmap->insert(StdPairType(i, i)); - shmmultimap->insert(detail::move_impl(IntPairType(detail::move_impl(IntType(i)), detail::move_impl(IntType(i))))); + } + { + IntType i1(i), i2(i); + IntPairType intpair2(boost::interprocess::move(i1), boost::interprocess::move(i2)); + shmmultimap->insert(boost::interprocess::move(intpair2)); stdmultimap->insert(StdPairType(i, i)); + } } if(!CheckEqualContainers(shmmap, stdmap)) return 1; if(!CheckEqualContainers(shmmultimap, stdmultimap)) return 1; diff --git a/test/mapped_file_test.cpp b/test/mapped_file_test.cpp index 75bb9eb..d2f6aba 100644 --- a/test/mapped_file_test.cpp +++ b/test/mapped_file_test.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include "named_creation_template.hpp" #include @@ -29,7 +30,7 @@ struct file_destroyer ~file_destroyer() { //The last destructor will destroy the file - std::remove(FileName); + file_mapping::remove(FileName); } }; @@ -60,7 +61,7 @@ int main () { typedef boost::interprocess::detail::managed_open_or_create_impl mapped_file; - std::remove(FileName); + file_mapping::remove(FileName); test::test_named_creation(); //Create and get name, size and address @@ -76,11 +77,11 @@ int main () std::memset(file1.get_user_address(), 0, file1.get_user_size()); //Now test move semantics - mapped_file move_ctor(detail::move_impl(file1)); + mapped_file move_ctor(boost::interprocess::move(file1)); mapped_file move_assign; - move_assign = detail::move_impl(move_ctor); + move_assign = boost::interprocess::move(move_ctor); } - std::remove(FileName); + file_mapping::remove(FileName); return 0; } diff --git a/test/memory_algorithm_test_template.hpp b/test/memory_algorithm_test_template.hpp index f7216d4..08436af 100644 --- a/test/memory_algorithm_test_template.hpp +++ b/test/memory_algorithm_test_template.hpp @@ -17,7 +17,7 @@ #include #include #include //std::memset -#include //std::remove +#include namespace boost { namespace interprocess { namespace test { @@ -107,7 +107,7 @@ bool test_allocation_shrink(Allocator &a) ; ++i){ std::size_t received_size; if(a.template allocation_command - ( shrink_in_place | nothrow_allocation, i*2 + ( boost::interprocess::shrink_in_place | boost::interprocess::nothrow_allocation, i*2 , i, received_size, static_cast(buffers[i])).first){ if(received_size > std::size_t(i*2)){ return false; @@ -159,7 +159,7 @@ bool test_allocation_expand(Allocator &a) preferred_size = min_size > preferred_size ? min_size : preferred_size; while(a.template allocation_command - ( expand_fwd | nothrow_allocation, min_size + ( boost::interprocess::expand_fwd | boost::interprocess::nothrow_allocation, min_size , preferred_size, received_size, static_cast(buffers[i])).first){ //Check received size is bigger than minimum if(received_size < min_size){ @@ -197,10 +197,10 @@ bool test_allocation_shrink_and_expand(Allocator &a) for(int i = 0; true; ++i){ std::size_t received_size; void *ptr = a.template allocation_command - ( allocate_new | nothrow_allocation, i, i*2, received_size).first; + ( boost::interprocess::allocate_new | boost::interprocess::nothrow_allocation, i, i*2, received_size).first; if(!ptr){ ptr = a.template allocation_command - ( allocate_new | nothrow_allocation, 1, i*2, received_size).first; + ( boost::interprocess::allocate_new | boost::interprocess::nothrow_allocation, 1, i*2, received_size).first; if(!ptr) break; } @@ -214,7 +214,7 @@ bool test_allocation_shrink_and_expand(Allocator &a) ; ++i){ std::size_t received_size; if(a.template allocation_command - ( shrink_in_place | nothrow_allocation, received_sizes[i] + ( boost::interprocess::shrink_in_place | boost::interprocess::nothrow_allocation, received_sizes[i] , i, received_size, static_cast(buffers[i])).first){ if(received_size > std::size_t(received_sizes[i])){ return false; @@ -233,7 +233,7 @@ bool test_allocation_shrink_and_expand(Allocator &a) std::size_t received_size; std::size_t request_size = received_sizes[i]; if(a.template allocation_command - ( expand_fwd | nothrow_allocation, request_size + ( boost::interprocess::expand_fwd | boost::interprocess::nothrow_allocation, request_size , request_size, received_size, static_cast(buffers[i])).first){ if(received_size != received_sizes[i]){ return false; @@ -298,7 +298,7 @@ bool test_allocation_deallocation_expand(Allocator &a) preferred_size = min_size > preferred_size ? min_size : preferred_size; while(a.template allocation_command - ( expand_fwd | nothrow_allocation, min_size + ( boost::interprocess::expand_fwd | boost::interprocess::nothrow_allocation, min_size , preferred_size, received_size, static_cast(buffers[i])).first){ //Check received size is bigger than minimum if(received_size < min_size){ @@ -368,7 +368,7 @@ bool test_allocation_with_reuse(Allocator &a) std::size_t min_size = (received_size + 1); std::size_t prf_size = (received_size + (i+1)*2); std::pair ret = a.raw_allocation_command - ( expand_bwd | nothrow_allocation, min_size + ( boost::interprocess::expand_bwd | boost::interprocess::nothrow_allocation, min_size , prf_size, received_size, static_cast(ptr), sizeof_object); if(!ret.first) break; @@ -631,7 +631,6 @@ bool test_grow_shrink_to_fit(Allocator &a) template bool test_many_equal_allocation(Allocator &a) { - typedef typename Allocator::multiallocation_iterator multiallocation_iterator; for( deallocation_type t = DirectDeallocation ; t != EndDeallocationType ; t = (deallocation_type)((int)t + 1)){ @@ -665,16 +664,17 @@ bool test_many_equal_allocation(Allocator &a) if(!a.check_sanity()) return false; + typedef typename Allocator::multiallocation_chain multiallocation_chain; std::vector buffers; for(int i = 0; true; ++i){ - multiallocation_iterator it = a.allocate_many(i+1, (i+1)*2, std::nothrow); - if(!it) + multiallocation_chain chain(a.allocate_many(i+1, (i+1)*2, std::nothrow)); + if(chain.empty()) break; - multiallocation_iterator itend; - std::size_t n = 0; - for(; it != itend; ++n){ - buffers.push_back(&*it++); + std::size_t n = chain.size(); + while(!chain.empty()){ + buffers.push_back(detail::get_pointer(chain.front())); + chain.pop_front(); } if(n != std::size_t((i+1)*2)) return false; @@ -740,7 +740,7 @@ bool test_many_equal_allocation(Allocator &a) template bool test_many_different_allocation(Allocator &a) { - typedef typename Allocator::multiallocation_iterator multiallocation_iterator; + typedef typename Allocator::multiallocation_chain multiallocation_chain; const std::size_t ArraySize = 11; std::size_t requested_sizes[ArraySize]; for(std::size_t i = 0; i < ArraySize; ++i){ @@ -777,13 +777,13 @@ bool test_many_different_allocation(Allocator &a) std::vector buffers; for(int i = 0; true; ++i){ - multiallocation_iterator it = a.allocate_many(requested_sizes, ArraySize, 1, std::nothrow); - if(!it) + multiallocation_chain chain(a.allocate_many(requested_sizes, ArraySize, 1, std::nothrow)); + if(chain.empty()) break; - multiallocation_iterator itend; - std::size_t n = 0; - for(; it != itend; ++n){ - buffers.push_back(&*it++); + std::size_t n = chain.size(); + while(!chain.empty()){ + buffers.push_back(detail::get_pointer(chain.front())); + chain.pop_front(); } if(n != ArraySize) return false; @@ -846,9 +846,9 @@ bool test_many_different_allocation(Allocator &a) template bool test_many_deallocation(Allocator &a) { - typedef typename Allocator::multiallocation_iterator multiallocation_iterator; + typedef typename Allocator::multiallocation_chain multiallocation_chain; const std::size_t ArraySize = 11; - std::vector buffers; + vector buffers; std::size_t requested_sizes[ArraySize]; for(std::size_t i = 0; i < ArraySize; ++i){ requested_sizes[i] = 4*i; @@ -857,13 +857,13 @@ bool test_many_deallocation(Allocator &a) { for(int i = 0; true; ++i){ - multiallocation_iterator it = a.allocate_many(requested_sizes, ArraySize, 1, std::nothrow); - if(!it) + multiallocation_chain chain = a.allocate_many(requested_sizes, ArraySize, 1, std::nothrow); + if(chain.empty()) break; - buffers.push_back(it); + buffers.push_back(boost::interprocess::move(chain)); } for(int i = 0, max = (int)buffers.size(); i != max; ++i){ - a.deallocate_many(buffers[i]); + a.deallocate_many(boost::interprocess::move(buffers[i])); } buffers.clear(); bool ok = free_memory == a.get_free_memory() && @@ -873,13 +873,13 @@ bool test_many_deallocation(Allocator &a) { for(int i = 0; true; ++i){ - multiallocation_iterator it = a.allocate_many(i*4, ArraySize, std::nothrow); - if(!it) + multiallocation_chain chain(a.allocate_many(i*4, ArraySize, std::nothrow)); + if(chain.empty()) break; - buffers.push_back(it); + buffers.push_back(boost::interprocess::move(chain)); } for(int i = 0, max = (int)buffers.size(); i != max; ++i){ - a.deallocate_many(buffers[i]); + a.deallocate_many(boost::interprocess::move(buffers[i])); } buffers.clear(); diff --git a/test/movable_int.hpp b/test/movable_int.hpp index 2ac7fb8..ee62582 100644 --- a/test/movable_int.hpp +++ b/test/movable_int.hpp @@ -21,10 +21,11 @@ namespace test { class movable_int { - movable_int(const movable_int&); - movable_int &operator= (const movable_int&); + movable_int(movable_int&); + movable_int &operator= (movable_int&); public: + BOOST_INTERPROCESS_ENABLE_MOVE_EMULATION(movable_int) movable_int() : m_int(0) @@ -34,23 +35,12 @@ class movable_int : m_int(a) {} - #ifndef BOOST_INTERPROCESS_RVALUE_REFERENCE - movable_int(detail::moved_object mmi) - : m_int(mmi.get().m_int) - { mmi.get().m_int = 0; } - #else - movable_int(movable_int &&mmi) + movable_int(BOOST_INTERPROCESS_RV_REF(movable_int) mmi) : m_int(mmi.m_int) { mmi.m_int = 0; } - #endif - #ifndef BOOST_INTERPROCESS_RVALUE_REFERENCE - movable_int & operator= (detail::moved_object mmi) - { this->m_int = mmi.get().m_int; mmi.get().m_int = 0; return *this; } - #else - movable_int & operator= (movable_int &&mmi) + movable_int & operator= (BOOST_INTERPROCESS_RV_REF(movable_int) mmi) { this->m_int = mmi.m_int; mmi.m_int = 0; return *this; } - #endif movable_int & operator= (int i) { this->m_int = i; return *this; } @@ -92,6 +82,7 @@ std::basic_ostream & operator<< class movable_and_copyable_int { public: + BOOST_INTERPROCESS_ENABLE_MOVE_EMULATION(movable_and_copyable_int) movable_and_copyable_int() : m_int(0) @@ -108,23 +99,12 @@ class movable_and_copyable_int movable_and_copyable_int &operator= (const movable_and_copyable_int& mi) { this->m_int = mi.m_int; return *this; } - #ifndef BOOST_INTERPROCESS_RVALUE_REFERENCE - movable_and_copyable_int(detail::moved_object mmi) - : m_int(mmi.get().m_int) - { mmi.get().m_int = 0; } - #else - movable_and_copyable_int(movable_and_copyable_int &&mmi) + movable_and_copyable_int(BOOST_INTERPROCESS_RV_REF(movable_and_copyable_int) mmi) : m_int(mmi.m_int) { mmi.m_int = 0; } - #endif - #ifndef BOOST_INTERPROCESS_RVALUE_REFERENCE - movable_and_copyable_int & operator= (detail::moved_object mmi) - { this->m_int = mmi.get().m_int; mmi.get().m_int = 0; return *this; } - #else - movable_and_copyable_int & operator= (movable_and_copyable_int &&mmi) + movable_and_copyable_int & operator= (BOOST_INTERPROCESS_RV_REF(movable_and_copyable_int) mmi) { this->m_int = mmi.m_int; mmi.m_int = 0; return *this; } - #endif movable_and_copyable_int & operator= (int i) { this->m_int = i; return *this; } @@ -167,26 +147,6 @@ std::basic_ostream & operator<< } //namespace interprocess { } //namespace boost { -namespace boost{ -namespace interprocess{ - -template<> -struct is_movable -{ - public: - enum { value = true }; -}; - -template<> -struct is_movable -{ - public: - enum { value = true }; -}; - -} //namespace interprocess{ -} //namespace boost{ - #include #endif //#ifndef BOOST_INTERPROCESS_TEST_MOVABLE_INT_HEADER diff --git a/test/multi_index_test.cpp b/test/multi_index_test.cpp index 40ce912..ad3e75b 100644 --- a/test/multi_index_test.cpp +++ b/test/multi_index_test.cpp @@ -28,8 +28,8 @@ using namespace boost::interprocess; namespace bmi = boost::multi_index; -typedef managed_shared_memory::allocator::type char_allocator; -typedef basic_string, char_allocator>shm_string; +typedef managed_shared_memory::allocator::type char_allocator; +typedef basic_string, char_allocator> shm_string; //Data to insert in shared memory struct employee @@ -75,33 +75,7 @@ template class bmi::multi_index_container< , BOOST_MULTI_INDEX_MEMBER(employee,int,age)> >, adaptive_pool >; -/* -// Explicit instantiations to catch compile-time errors -template class bmi::multi_index_container< - employee, - bmi::indexed_by< - bmi::ordered_unique - , BOOST_MULTI_INDEX_MEMBER(employee,int,id)>, - bmi::ordered_non_unique< - bmi::tag,BOOST_MULTI_INDEX_MEMBER(employee,shm_string,name)>, - bmi::ordered_non_unique - , BOOST_MULTI_INDEX_MEMBER(employee,int,age)> >, - cached_adaptive_pool ->; -// Explicit instantiations to catch compile-time errors -template class bmi::multi_index_container< - employee, - bmi::indexed_by< - bmi::ordered_unique - , BOOST_MULTI_INDEX_MEMBER(employee,int,id)>, - bmi::ordered_non_unique< - bmi::tag,BOOST_MULTI_INDEX_MEMBER(employee,shm_string,name)>, - bmi::ordered_non_unique - , BOOST_MULTI_INDEX_MEMBER(employee,int,age)> >, - private_adaptive_pool ->; -*/ // Explicit instantiations to catch compile-time errors template class bmi::multi_index_container< employee, @@ -114,33 +88,7 @@ template class bmi::multi_index_container< , BOOST_MULTI_INDEX_MEMBER(employee,int,age)> >, node_allocator >; -/* -// Explicit instantiations to catch compile-time errors -template class bmi::multi_index_container< - employee, - bmi::indexed_by< - bmi::ordered_unique - , BOOST_MULTI_INDEX_MEMBER(employee,int,id)>, - bmi::ordered_non_unique< - bmi::tag,BOOST_MULTI_INDEX_MEMBER(employee,shm_string,name)>, - bmi::ordered_non_unique - , BOOST_MULTI_INDEX_MEMBER(employee,int,age)> >, - cached_node_allocator ->; -// Explicit instantiations to catch compile-time errors -template class bmi::multi_index_container< - employee, - bmi::indexed_by< - bmi::ordered_unique - , BOOST_MULTI_INDEX_MEMBER(employee,int,id)>, - bmi::ordered_non_unique< - bmi::tag,BOOST_MULTI_INDEX_MEMBER(employee,shm_string,name)>, - bmi::ordered_non_unique - , BOOST_MULTI_INDEX_MEMBER(employee,int,age)> >, - private_node_allocator ->; -*/ int main () { return 0; diff --git a/test/set_test.hpp b/test/set_test.hpp index db8766f..00c1d2f 100644 --- a/test/set_test.hpp +++ b/test/set_test.hpp @@ -17,7 +17,7 @@ #include #include #include "print_container.hpp" -#include +#include #include #include "get_process_id_name.hpp" @@ -63,7 +63,7 @@ int set_test () IntType aux_vect[50]; for(int i = 0; i < 50; ++i){ IntType move_me(i/2); - aux_vect[i] = detail::move_impl(move_me); + aux_vect[i] = boost::interprocess::move(move_me); } int aux_vect2[50]; for(int i = 0; i < 50; ++i){ @@ -72,21 +72,21 @@ int set_test () IntType aux_vect3[50]; for(int i = 0; i < 50; ++i){ IntType move_me(i/2); - aux_vect3[i] = detail::move_impl(move_me); + aux_vect3[i] = boost::interprocess::move(move_me); } MyShmSet *shmset2 = segment.template construct("MyShmSet2") - (detail::make_move_iterator(&aux_vect[0]) - , detail::make_move_iterator(aux_vect + 50) + (boost::interprocess::make_move_iterator(&aux_vect[0]) + , boost::interprocess::make_move_iterator(aux_vect + 50) , std::less(), segment.get_segment_manager()); MyStdSet *stdset2 = new MyStdSet(aux_vect2, aux_vect2 + 50); MyShmMultiSet *shmmultiset2 = segment.template construct("MyShmMultiSet2") - (detail::make_move_iterator(&aux_vect3[0]) - , detail::make_move_iterator(aux_vect3 + 50) + (boost::interprocess::make_move_iterator(&aux_vect3[0]) + , boost::interprocess::make_move_iterator(aux_vect3 + 50) , std::less(), segment.get_segment_manager()); MyStdMultiSet *stdmultiset2 = new MyStdMultiSet(aux_vect2, aux_vect2 + 50); @@ -108,20 +108,20 @@ int set_test () int i, j; for(i = 0; i < max; ++i){ IntType move_me(i); - shmset->insert(detail::move_impl(move_me)); + shmset->insert(boost::interprocess::move(move_me)); stdset->insert(i); IntType move_me2(i); - shmmultiset->insert(detail::move_impl(move_me2)); + shmmultiset->insert(boost::interprocess::move(move_me2)); stdmultiset->insert(i); } if(!CheckEqualContainers(shmset, stdset)){ - std::cout << "Error in shmset->insert(detail::move_impl(move_me)" << std::endl; + std::cout << "Error in shmset->insert(boost::interprocess::move(move_me)" << std::endl; return 1; } if(!CheckEqualContainers(shmmultiset, stdmultiset)){ - std::cout << "Error in shmmultiset->insert(detail::move_impl(move_me)" << std::endl; + std::cout << "Error in shmmultiset->insert(boost::interprocess::move(move_me)" << std::endl; return 1; } @@ -183,7 +183,7 @@ int set_test () IntType aux_vect[50]; for(int i = 0; i < 50; ++i){ IntType move_me(-1); - aux_vect[i] = detail::move_impl(move_me); + aux_vect[i] = boost::interprocess::move(move_me); } int aux_vect2[50]; for(int i = 0; i < 50; ++i){ @@ -192,19 +192,19 @@ int set_test () IntType aux_vect3[50]; for(int i = 0; i < 50; ++i){ IntType move_me(-1); - aux_vect3[i] = detail::move_impl(move_me); + aux_vect3[i] = boost::interprocess::move(move_me); } - shmset->insert(detail::make_move_iterator(&aux_vect[0]), detail::make_move_iterator(aux_vect + 50)); + shmset->insert(boost::interprocess::make_move_iterator(&aux_vect[0]), boost::interprocess::make_move_iterator(aux_vect + 50)); stdset->insert(aux_vect2, aux_vect2 + 50); - shmmultiset->insert(detail::make_move_iterator(&aux_vect3[0]), detail::make_move_iterator(aux_vect3 + 50)); + shmmultiset->insert(boost::interprocess::make_move_iterator(&aux_vect3[0]), boost::interprocess::make_move_iterator(aux_vect3 + 50)); stdmultiset->insert(aux_vect2, aux_vect2 + 50); if(!CheckEqualContainers(shmset, stdset)){ - std::cout << "Error in shmset->insert(detail::make_move_iterator(&aux_vect[0])..." << std::endl; + std::cout << "Error in shmset->insert(boost::interprocess::make_move_iterator(&aux_vect[0])..." << std::endl; return 1; } if(!CheckEqualContainers(shmmultiset, stdmultiset)){ - std::cout << "Error in shmmultiset->insert(detail::make_move_iterator(&aux_vect3[0]), ..." << std::endl; + std::cout << "Error in shmmultiset->insert(boost::interprocess::make_move_iterator(&aux_vect3[0]), ..." << std::endl; return 1; } @@ -228,7 +228,7 @@ int set_test () IntType aux_vect[50]; for(int i = 0; i < 50; ++i){ IntType move_me(-1); - aux_vect[i] = detail::move_impl(move_me); + aux_vect[i] = boost::interprocess::move(move_me); } int aux_vect2[50]; for(int i = 0; i < 50; ++i){ @@ -237,35 +237,35 @@ int set_test () IntType aux_vect3[50]; for(int i = 0; i < 50; ++i){ IntType move_me(-1); - aux_vect3[i] = detail::move_impl(move_me); + aux_vect3[i] = boost::interprocess::move(move_me); } IntType aux_vect4[50]; for(int i = 0; i < 50; ++i){ IntType move_me(-1); - aux_vect4[i] = detail::move_impl(move_me); + aux_vect4[i] = boost::interprocess::move(move_me); } IntType aux_vect5[50]; for(int i = 0; i < 50; ++i){ IntType move_me(-1); - aux_vect5[i] = detail::move_impl(move_me); + aux_vect5[i] = boost::interprocess::move(move_me); } - shmset->insert(detail::make_move_iterator(&aux_vect[0]), detail::make_move_iterator(aux_vect + 50)); - shmset->insert(detail::make_move_iterator(&aux_vect3[0]), detail::make_move_iterator(aux_vect3 + 50)); + shmset->insert(boost::interprocess::make_move_iterator(&aux_vect[0]), boost::interprocess::make_move_iterator(aux_vect + 50)); + shmset->insert(boost::interprocess::make_move_iterator(&aux_vect3[0]), boost::interprocess::make_move_iterator(aux_vect3 + 50)); stdset->insert(aux_vect2, aux_vect2 + 50); stdset->insert(aux_vect2, aux_vect2 + 50); - shmmultiset->insert(detail::make_move_iterator(&aux_vect4[0]), detail::make_move_iterator(aux_vect4 + 50)); - shmmultiset->insert(detail::make_move_iterator(&aux_vect5[0]), detail::make_move_iterator(aux_vect5 + 50)); + shmmultiset->insert(boost::interprocess::make_move_iterator(&aux_vect4[0]), boost::interprocess::make_move_iterator(aux_vect4 + 50)); + shmmultiset->insert(boost::interprocess::make_move_iterator(&aux_vect5[0]), boost::interprocess::make_move_iterator(aux_vect5 + 50)); stdmultiset->insert(aux_vect2, aux_vect2 + 50); stdmultiset->insert(aux_vect2, aux_vect2 + 50); if(!CheckEqualContainers(shmset, stdset)){ - std::cout << "Error in shmset->insert(detail::make_move_iterator(&aux_vect3[0])..." << std::endl; + std::cout << "Error in shmset->insert(boost::interprocess::make_move_iterator(&aux_vect3[0])..." << std::endl; return 1; } if(!CheckEqualContainers(shmmultiset, stdmultiset)){ - std::cout << "Error in shmmultiset->insert(detail::make_move_iterator(&aux_vect5[0])..." << std::endl; + std::cout << "Error in shmmultiset->insert(boost::interprocess::make_move_iterator(&aux_vect5[0])..." << std::endl; return 1; } @@ -285,88 +285,88 @@ int set_test () for(i = 0; i < max; ++i){ IntType move_me(i); - shmset->insert(detail::move_impl(move_me)); + shmset->insert(boost::interprocess::move(move_me)); stdset->insert(i); IntType move_me2(i); - shmmultiset->insert(detail::move_impl(move_me2)); + shmmultiset->insert(boost::interprocess::move(move_me2)); stdmultiset->insert(i); } if(!CheckEqualContainers(shmset, stdset)){ - std::cout << "Error in shmset->insert(detail::move_impl(move_me)) try 2" << std::endl; + std::cout << "Error in shmset->insert(boost::interprocess::move(move_me)) try 2" << std::endl; return 1; } if(!CheckEqualContainers(shmmultiset, stdmultiset)){ - std::cout << "Error in shmmultiset->insert(detail::move_impl(move_me2)) try 2" << std::endl; + std::cout << "Error in shmmultiset->insert(boost::interprocess::move(move_me2)) try 2" << std::endl; return 1; } for(i = 0; i < max; ++i){ IntType move_me(i); - shmset->insert(shmset->begin(), detail::move_impl(move_me)); + shmset->insert(shmset->begin(), boost::interprocess::move(move_me)); stdset->insert(stdset->begin(), i); //PrintContainers(shmset, stdset); IntType move_me2(i); - shmmultiset->insert(shmmultiset->begin(), detail::move_impl(move_me2)); + shmmultiset->insert(shmmultiset->begin(), boost::interprocess::move(move_me2)); stdmultiset->insert(stdmultiset->begin(), i); //PrintContainers(shmmultiset, stdmultiset); if(!CheckEqualContainers(shmset, stdset)){ - std::cout << "Error in shmset->insert(shmset->begin(), detail::move_impl(move_me))" << std::endl; + std::cout << "Error in shmset->insert(shmset->begin(), boost::interprocess::move(move_me))" << std::endl; return 1; } if(!CheckEqualContainers(shmmultiset, stdmultiset)){ - std::cout << "Error in shmmultiset->insert(shmmultiset->begin(), detail::move_impl(move_me2))" << std::endl; + std::cout << "Error in shmmultiset->insert(shmmultiset->begin(), boost::interprocess::move(move_me2))" << std::endl; return 1; } IntType move_me3(i); - shmset->insert(shmset->end(), detail::move_impl(move_me3)); + shmset->insert(shmset->end(), boost::interprocess::move(move_me3)); stdset->insert(stdset->end(), i); IntType move_me4(i); - shmmultiset->insert(shmmultiset->end(), detail::move_impl(move_me4)); + shmmultiset->insert(shmmultiset->end(), boost::interprocess::move(move_me4)); stdmultiset->insert(stdmultiset->end(), i); if(!CheckEqualContainers(shmset, stdset)){ - std::cout << "Error in shmset->insert(shmset->end(), detail::move_impl(move_me3))" << std::endl; + std::cout << "Error in shmset->insert(shmset->end(), boost::interprocess::move(move_me3))" << std::endl; return 1; } if(!CheckEqualContainers(shmmultiset, stdmultiset)){ - std::cout << "Error in shmmultiset->insert(shmmultiset->end(), detail::move_impl(move_me4))" << std::endl; + std::cout << "Error in shmmultiset->insert(shmmultiset->end(), boost::interprocess::move(move_me4))" << std::endl; return 1; } { IntType move_me(i); - shmset->insert(shmset->upper_bound(move_me), detail::move_impl(move_me)); + shmset->insert(shmset->upper_bound(move_me), boost::interprocess::move(move_me)); stdset->insert(stdset->upper_bound(i), i); //PrintContainers(shmset, stdset); IntType move_me2(i); - shmmultiset->insert(shmmultiset->upper_bound(move_me2), detail::move_impl(move_me2)); + shmmultiset->insert(shmmultiset->upper_bound(move_me2), boost::interprocess::move(move_me2)); stdmultiset->insert(stdmultiset->upper_bound(i), i); //PrintContainers(shmmultiset, stdmultiset); if(!CheckEqualContainers(shmset, stdset)){ - std::cout << "Error in shmset->insert(shmset->upper_bound(move_me), detail::move_impl(move_me))" << std::endl; + std::cout << "Error in shmset->insert(shmset->upper_bound(move_me), boost::interprocess::move(move_me))" << std::endl; return 1; } if(!CheckEqualContainers(shmmultiset, stdmultiset)){ - std::cout << "Error in shmmultiset->insert(shmmultiset->upper_bound(move_me2), detail::move_impl(move_me2))" << std::endl; + std::cout << "Error in shmmultiset->insert(shmmultiset->upper_bound(move_me2), boost::interprocess::move(move_me2))" << std::endl; return 1; } } { IntType move_me(i); - shmset->insert(shmset->lower_bound(move_me), detail::move_impl(move_me2)); + shmset->insert(shmset->lower_bound(move_me), boost::interprocess::move(move_me2)); stdset->insert(stdset->lower_bound(i), i); //PrintContainers(shmset, stdset); IntType move_me2(i); - shmmultiset->insert(shmmultiset->lower_bound(move_me2), detail::move_impl(move_me2)); + shmmultiset->insert(shmmultiset->lower_bound(move_me2), boost::interprocess::move(move_me2)); stdmultiset->insert(stdmultiset->lower_bound(i), i); //PrintContainers(shmmultiset, stdmultiset); if(!CheckEqualContainers(shmset, stdset)){ - std::cout << "Error in shmset->insert(shmset->lower_bound(move_me), detail::move_impl(move_me2))" << std::endl; + std::cout << "Error in shmset->insert(shmset->lower_bound(move_me), boost::interprocess::move(move_me2))" << std::endl; return 1; } if(!CheckEqualContainers(shmmultiset, stdmultiset)){ - std::cout << "Error in shmmultiset->insert(shmmultiset->lower_bound(move_me2), detail::move_impl(move_me2))" << std::endl; + std::cout << "Error in shmmultiset->insert(shmmultiset->lower_bound(move_me2), boost::interprocess::move(move_me2))" << std::endl; return 1; } } @@ -392,9 +392,9 @@ int set_test () for(j = 0; j < 3; ++j) for(i = 0; i < 100; ++i){ IntType move_me(i); - shmset->insert(detail::move_impl(move_me)); + shmset->insert(boost::interprocess::move(move_me)); IntType move_me2(i); - shmmultiset->insert(detail::move_impl(move_me2)); + shmmultiset->insert(boost::interprocess::move(move_me2)); IntType count_me(i); if(shmset->count(count_me) != typename MyShmMultiSet::size_type(1)){ std::cout << "Error in shmset->count(count_me)" << std::endl; @@ -461,10 +461,10 @@ int set_test_copyable () int i; for(i = 0; i < max; ++i){ IntType move_me(i); - shmset->insert(detail::move_impl(move_me)); + shmset->insert(boost::interprocess::move(move_me)); stdset->insert(i); IntType move_me2(i); - shmmultiset->insert(detail::move_impl(move_me2)); + shmmultiset->insert(boost::interprocess::move(move_me2)); stdmultiset->insert(i); } if(!CheckEqualContainers(shmset, stdset)) return 1; diff --git a/test/shared_memory_mapping_test.cpp b/test/shared_memory_mapping_test.cpp index 6f363f3..d424017 100644 --- a/test/shared_memory_mapping_test.cpp +++ b/test/shared_memory_mapping_test.cpp @@ -19,6 +19,12 @@ using namespace boost::interprocess; +shared_memory_object get_shared_memory_mapping() +{ + shared_memory_object sh; + return shared_memory_object(boost::interprocess::move(sh)); +} + int main () { try{ @@ -139,9 +145,10 @@ int main () { //Now test move semantics shared_memory_object mapping(open_only, test::get_process_id_name(), read_write); - shared_memory_object move_ctor(detail::move_impl(mapping)); + shared_memory_object move_ctor(boost::interprocess::move(mapping)); shared_memory_object move_assign; - move_assign = detail::move_impl(move_ctor); + move_assign = boost::interprocess::move(move_ctor); + shared_memory_object ret(get_shared_memory_mapping()); } } catch(std::exception &exc){ @@ -152,5 +159,3 @@ int main () shared_memory_object::remove(test::get_process_id_name()); return 0; } - -#include diff --git a/test/shared_memory_test.cpp b/test/shared_memory_test.cpp index 976a4a2..8f99380 100644 --- a/test/shared_memory_test.cpp +++ b/test/shared_memory_test.cpp @@ -31,13 +31,14 @@ struct eraser } }; +typedef detail::managed_open_or_create_impl shared_memory; + //This wrapper is necessary to have a common constructor //in generic named_creation_template functions class shared_memory_creation_test_wrapper : public eraser - , public detail::managed_open_or_create_impl + , public shared_memory { - typedef detail::managed_open_or_create_impl shared_memory; public: shared_memory_creation_test_wrapper(create_only_t) @@ -56,8 +57,6 @@ class shared_memory_creation_test_wrapper int main () { - typedef detail::managed_open_or_create_impl shared_memory; - try{ shared_memory_object::remove(ShmName); test::test_named_creation(); @@ -76,9 +75,9 @@ int main () std::memset(shm1.get_user_address(), 0, shm1.get_user_size()); //Now test move semantics - shared_memory move_ctor(detail::move_impl(shm1)); + shared_memory move_ctor(boost::interprocess::move(shm1)); shared_memory move_assign; - move_assign = detail::move_impl(move_ctor); + move_assign = boost::interprocess::move(move_ctor); } } catch(std::exception &ex){ diff --git a/test/shared_ptr_test.cpp b/test/shared_ptr_test.cpp index 38c08d1..877a00e 100644 --- a/test/shared_ptr_test.cpp +++ b/test/shared_ptr_test.cpp @@ -25,6 +25,10 @@ #include #include "get_process_id_name.hpp" + +#include +#include + using namespace boost::interprocess; class base_class @@ -613,7 +617,6 @@ void test_alias() shared_memory_object::remove(process_name.c_str()); } - int main() { if(0 != simple_test()) @@ -626,8 +629,7 @@ int main() return 1; test_alias(); - - return 0; } #include + diff --git a/test/slist_test.cpp b/test/slist_test.cpp index 5944f35..a184eba 100644 --- a/test/slist_test.cpp +++ b/test/slist_test.cpp @@ -7,7 +7,6 @@ // See http://www.boost.org/libs/interprocess for documentation. // ////////////////////////////////////////////////////////////////////////////// - #include #include #include @@ -54,10 +53,9 @@ int main () { //Now test move semantics slist original; - slist move_ctor(detail::move_impl(original)); + slist move_ctor(boost::interprocess::move(original)); slist move_assign; - move_assign = detail::move_impl(move_ctor); - move_assign.swap(detail::move_impl(original)); + move_assign = boost::interprocess::move(move_ctor); move_assign.swap(original); } @@ -79,8 +77,7 @@ int main () if(!boost::interprocess::test::test_emplace < slist, Options>()) return 1; - - return 0; } #include + diff --git a/test/stable_vector_test.cpp b/test/stable_vector_test.cpp new file mode 100644 index 0000000..5af0bcf --- /dev/null +++ b/test/stable_vector_test.cpp @@ -0,0 +1,97 @@ +////////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2004-2007. 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 +#include +#include +#include +#include +#include + +#include +#include +#include +#include "allocator_v1.hpp" +#include "heap_allocator_v1.hpp" +#include "check_equal_containers.hpp" +#include "movable_int.hpp" +#include "expand_bwd_test_allocator.hpp" +#include "expand_bwd_test_template.hpp" +#include "dummy_test_allocator.hpp" +#include "vector_test.hpp" + +using namespace boost::interprocess; + +//Explicit instantiation to detect compilation errors +//template class stable_vector >; + +class recursive_vector +{ + public: + int id_; + stable_vector vector_; +}; + +void recursive_vector_test()//Test for recursive types +{ + stable_vector recursive_vector_vector; +} + +int main() +{ + recursive_vector_test(); + { + //Now test move semantics + stable_vector original; + stable_vector move_ctor(boost::interprocess::move(original)); + stable_vector move_assign; + move_assign = boost::interprocess::move(move_ctor); + move_assign.swap(original); + } + typedef allocator ShmemAllocator; + typedef stable_vector MyVector; + + typedef test::allocator_v1 ShmemV1Allocator; + typedef stable_vector MyV1Vector; + + typedef test::heap_allocator_v1 ShmemHeapV1Allocator; + typedef stable_vector MyHeapV1Vector; + + typedef allocator ShmemMoveAllocator; + typedef stable_vector MyMoveVector; + + typedef allocator ShmemCopyMoveAllocator; + typedef stable_vector MyCopyMoveVector; + + if(test::vector_test()) + return 1; + + if(test::vector_test()) + return 1; + + if(test::vector_test()) + return 1; + + if(test::vector_test()) + return 1; + + if(test::vector_test()) + return 1; + + const test::EmplaceOptions Options = (test::EmplaceOptions)(test::EMPLACE_BACK | test::EMPLACE_BEFORE); + if(!boost::interprocess::test::test_emplace + < stable_vector, Options>()) + return 1; + + return 0; +} + +#include diff --git a/test/string_test.cpp b/test/string_test.cpp index 62318bb..747900b 100644 --- a/test/string_test.cpp +++ b/test/string_test.cpp @@ -127,7 +127,7 @@ int string_test() std::sprintf(buffer, "%i", i); auxShmString += buffer; auxStdString += buffer; - shmStringVect->push_back(detail::move_impl(auxShmString)); + shmStringVect->push_back(boost::interprocess::move(auxShmString)); stdStringVect->push_back(auxStdString); } @@ -157,7 +157,7 @@ int string_test() std::sprintf(buffer, "%i", i); auxShmString += buffer; auxStdString += buffer; - shmStringVect->insert(shmStringVect->begin(), detail::move_impl(auxShmString)); + shmStringVect->insert(shmStringVect->begin(), boost::interprocess::move(auxShmString)); stdStringVect->insert(stdStringVect->begin(), auxStdString); } diff --git a/test/tree_test.cpp b/test/tree_test.cpp index 21b4668..ff60dce 100644 --- a/test/tree_test.cpp +++ b/test/tree_test.cpp @@ -7,7 +7,6 @@ // See http://www.boost.org/libs/interprocess for documentation. // ////////////////////////////////////////////////////////////////////////////// - #include #include #include @@ -33,32 +32,7 @@ /////////////////////////////////////////////////////////////////// using namespace boost::interprocess; -/* -//Explicit instantiation to detect compilation errors -template class boost::interprocess::set - - ,test::dummy_test_allocator >; -template class boost::interprocess::map - - ,test::dummy_test_allocator > >; - -template class boost::interprocess::multiset - - ,test::dummy_test_allocator >; - -template class boost::interprocess::multimap - - ,test::dummy_test_allocator > >; -*/ //Customize managed_shared_memory class typedef basic_managed_shared_memory -void test_move_semantics() +void test_move() { //Now test move semantics C original; - C move_ctor(detail::move_impl(original)); + C move_ctor(boost::interprocess::move(original)); C move_assign; - move_assign = detail::move_impl(move_ctor); - move_assign.swap(detail::move_impl(original)); + move_assign = boost::interprocess::move(move_ctor); move_assign.swap(original); } @@ -181,10 +154,10 @@ int main () } //Now test move semantics { - test_move_semantics >(); - test_move_semantics >(); - test_move_semantics >(); - test_move_semantics >(); + test_move >(); + test_move >(); + test_move >(); + test_move >(); } using namespace boost::interprocess::detail; @@ -221,6 +194,7 @@ int main () return 1; } + if (0 != test::map_test, MapOptions>()) return 1; + return 0; } diff --git a/test/unique_ptr_test.cpp b/test/unique_ptr_test.cpp index be43789..35d63bb 100644 --- a/test/unique_ptr_test.cpp +++ b/test/unique_ptr_test.cpp @@ -70,14 +70,14 @@ int main() //Test some copy constructors my_unique_ptr_class my_ptr3(0, segment.get_deleter()); - my_unique_ptr_class my_ptr4(detail::move_impl(my_ptr3)); + my_unique_ptr_class my_ptr4(boost::interprocess::move(my_ptr3)); //Construct a list and fill MyList list(segment.get_segment_manager()); //Insert from my_unique_ptr_class - list.push_front(detail::move_impl(my_ptr)); - list.push_back(detail::move_impl(my_ptr2)); + list.push_front(boost::interprocess::move(my_ptr)); + list.push_back(boost::interprocess::move(my_ptr2)); //Check pointers assert(my_ptr.get() == 0); @@ -85,20 +85,13 @@ int main() assert(list.begin()->get() == ptr1); assert(list.rbegin()->get() == ptr2); - //MyList list2(detail::move_impl(list)); - //list2.swap(detail::move_impl(MyList(segment.get_segment_manager()))); - //list.swap(detail::move_impl(MyList(segment.get_segment_manager()))); - - assert(list.begin()->get() == ptr1); - assert(list.rbegin()->get() == ptr2); - //Construct a set and fill typedef std::less set_less_t; MySet set(set_less_t(), segment.get_segment_manager()); //Insert in set from list passing ownership - set.insert(detail::move_impl(*list.begin())); - set.insert(detail::move_impl(*list.rbegin())); + set.insert(boost::interprocess::move(*list.begin())); + set.insert(boost::interprocess::move(*list.rbegin())); //Check pointers assert(list.begin()->get() == 0); @@ -120,12 +113,12 @@ int main() //Insert from my_unique_ptr_class if(ptr1 < ptr2){ - vector.insert(vector.begin(), detail::move_impl(*set.begin())); - vector.insert(vector.end(), detail::move_impl(*set.rbegin())); + vector.insert(vector.begin(), boost::interprocess::move(*set.begin())); + vector.insert(vector.end(), boost::interprocess::move(*set.rbegin())); } else{ - vector.insert(vector.begin(), detail::move_impl(*set.rbegin())); - vector.insert(vector.end(), detail::move_impl(*set.begin())); + vector.insert(vector.begin(), boost::interprocess::move(*set.rbegin())); + vector.insert(vector.end(), boost::interprocess::move(*set.begin())); } //Check pointers @@ -134,14 +127,14 @@ int main() assert(vector.begin()->get() == ptr1); assert(vector.rbegin()->get() == ptr2); - MyVector vector2(detail::move_impl(vector)); + MyVector vector2(boost::interprocess::move(vector)); vector2.swap(vector); assert(vector.begin()->get() == ptr1); assert(vector.rbegin()->get() == ptr2); my_unique_ptr_class a(0, segment.get_deleter()), b(0, segment.get_deleter()); - a = detail::move_impl(b); + a = boost::interprocess::move(b); } shared_memory_object::remove(process_name.c_str()); return 0; diff --git a/test/upgradable_mutex_test.cpp b/test/upgradable_mutex_test.cpp index 846743a..238196b 100644 --- a/test/upgradable_mutex_test.cpp +++ b/test/upgradable_mutex_test.cpp @@ -35,135 +35,135 @@ int main () //Conversions to scoped_lock { scoped_lock lock(mut); - scoped_lock e_lock(detail::move_impl(lock)); - lock.swap(detail::move_impl(e_lock)); + scoped_lock e_lock(boost::interprocess::move(lock)); + lock.swap(e_lock); } { scoped_lock lock(mut); scoped_lock e_lock(mut2); - e_lock = detail::move_impl(lock); + e_lock = boost::interprocess::move(lock); } { upgradable_lock u_lock(mut); //This calls unlock_upgradable_and_lock() - scoped_lock e_lock(detail::move_impl(u_lock)); + scoped_lock e_lock(boost::interprocess::move(u_lock)); } { upgradable_lock u_lock(mut); //This calls unlock_upgradable_and_lock() scoped_lock e_lock(mut2); - scoped_lock moved(detail::move_impl(u_lock)); - e_lock = detail::move_impl(moved); + scoped_lock moved(boost::interprocess::move(u_lock)); + e_lock = boost::interprocess::move(moved); } { upgradable_lock u_lock(mut); //This calls try_unlock_upgradable_and_lock() - scoped_lock e_lock(detail::move_impl(u_lock), try_to_lock); + scoped_lock e_lock(boost::interprocess::move(u_lock), try_to_lock); } { upgradable_lock u_lock(mut); //This calls try_unlock_upgradable_and_lock() scoped_lock e_lock(mut2); - scoped_lock moved(detail::move_impl(u_lock), try_to_lock); - e_lock = detail::move_impl(moved); + scoped_lock moved(boost::interprocess::move(u_lock), try_to_lock); + e_lock = boost::interprocess::move(moved); } { boost::posix_time::ptime t = test::delay(100); upgradable_lock u_lock(mut); //This calls timed_unlock_upgradable_and_lock() - scoped_lock e_lock(detail::move_impl(u_lock), t); + scoped_lock e_lock(boost::interprocess::move(u_lock), t); } { boost::posix_time::ptime t = test::delay(100); upgradable_lock u_lock(mut); //This calls timed_unlock_upgradable_and_lock() scoped_lock e_lock(mut2); - scoped_lock moved(detail::move_impl(u_lock), t); - e_lock = detail::move_impl(moved); + scoped_lock moved(boost::interprocess::move(u_lock), t); + e_lock = boost::interprocess::move(moved); } { sharable_lock s_lock(mut); //This calls try_unlock_sharable_and_lock() - scoped_lock e_lock(detail::move_impl(s_lock), try_to_lock); + scoped_lock e_lock(boost::interprocess::move(s_lock), try_to_lock); } { sharable_lock s_lock(mut); //This calls try_unlock_sharable_and_lock() scoped_lock e_lock(mut2); - scoped_lock moved(detail::move_impl(s_lock), try_to_lock); - e_lock = detail::move_impl(moved); + scoped_lock moved(boost::interprocess::move(s_lock), try_to_lock); + e_lock = boost::interprocess::move(moved); } //Conversions to upgradable_lock { upgradable_lock lock(mut); - upgradable_lock u_lock(detail::move_impl(lock)); - lock.swap(detail::move_impl(u_lock)); + upgradable_lock u_lock(boost::interprocess::move(lock)); + lock.swap(u_lock); } { upgradable_lock lock(mut); upgradable_lock u_lock(mut2); - upgradable_lock moved(detail::move_impl(lock)); - u_lock = detail::move_impl(moved); + upgradable_lock moved(boost::interprocess::move(lock)); + u_lock = boost::interprocess::move(moved); } { sharable_lock s_lock(mut); //This calls unlock_sharable_and_lock_upgradable() - upgradable_lock u_lock(detail::move_impl(s_lock), try_to_lock); + upgradable_lock u_lock(boost::interprocess::move(s_lock), try_to_lock); } { sharable_lock s_lock(mut); //This calls unlock_sharable_and_lock_upgradable() upgradable_lock u_lock(mut2); - upgradable_lock moved(detail::move_impl(s_lock), try_to_lock); - u_lock = detail::move_impl(moved); + upgradable_lock moved(boost::interprocess::move(s_lock), try_to_lock); + u_lock = boost::interprocess::move(moved); } { scoped_lock e_lock(mut); //This calls unlock_and_lock_upgradable() - upgradable_lock u_lock(detail::move_impl(e_lock)); + upgradable_lock u_lock(boost::interprocess::move(e_lock)); } { scoped_lock e_lock(mut); //This calls unlock_and_lock_upgradable() upgradable_lock u_lock(mut2); - upgradable_lock moved(detail::move_impl(e_lock)); - u_lock = detail::move_impl(moved); + upgradable_lock moved(boost::interprocess::move(e_lock)); + u_lock = boost::interprocess::move(moved); } //Conversions to sharable_lock { sharable_lock lock(mut); - sharable_lock s_lock(detail::move_impl(lock)); - lock.swap(detail::move_impl(s_lock)); + sharable_lock s_lock(boost::interprocess::move(lock)); + lock.swap(s_lock); } { sharable_lock lock(mut); sharable_lock s_lock(mut2); - sharable_lock moved(detail::move_impl(lock)); - s_lock = detail::move_impl(moved); + sharable_lock moved(boost::interprocess::move(lock)); + s_lock = boost::interprocess::move(moved); } { upgradable_lock u_lock(mut); //This calls unlock_upgradable_and_lock_sharable() - sharable_lock s_lock(detail::move_impl(u_lock)); + sharable_lock s_lock(boost::interprocess::move(u_lock)); } { upgradable_lock u_lock(mut); //This calls unlock_upgradable_and_lock_sharable() sharable_lock s_lock(mut2); - sharable_lock moved(detail::move_impl(u_lock)); - s_lock = detail::move_impl(moved); + sharable_lock moved(boost::interprocess::move(u_lock)); + s_lock = boost::interprocess::move(moved); } { scoped_lock e_lock(mut); //This calls unlock_and_lock_sharable() - sharable_lock s_lock(detail::move_impl(e_lock)); + sharable_lock s_lock(boost::interprocess::move(e_lock)); } { scoped_lock e_lock(mut); //This calls unlock_and_lock_sharable() sharable_lock s_lock(mut2); - sharable_lock moved(detail::move_impl(e_lock)); - s_lock = detail::move_impl(moved); + sharable_lock moved(boost::interprocess::move(e_lock)); + s_lock = boost::interprocess::move(moved); } } diff --git a/test/user_buffer_test.cpp b/test/user_buffer_test.cpp index fdcab2d..13e7b0a 100644 --- a/test/user_buffer_test.cpp +++ b/test/user_buffer_test.cpp @@ -59,19 +59,17 @@ int main () { //Now test move semantics managed_heap_memory original(memsize); - managed_heap_memory move_ctor(detail::move_impl(original)); + managed_heap_memory move_ctor(boost::interprocess::move(original)); managed_heap_memory move_assign; - move_assign = detail::move_impl(move_ctor); - original.swap(detail::move_impl(move_assign)); + move_assign = boost::interprocess::move(move_ctor); original.swap(move_assign); } { //Now test move semantics managed_external_buffer original(create_only, static_buffer, memsize); - managed_external_buffer move_ctor(detail::move_impl(original)); + managed_external_buffer move_ctor(boost::interprocess::move(original)); managed_external_buffer move_assign; - move_assign = detail::move_impl(move_ctor); - original.swap(detail::move_impl(move_assign)); + move_assign = boost::interprocess::move(move_ctor); original.swap(move_assign); } @@ -84,13 +82,13 @@ int main () //Test move semantics { wmanaged_external_buffer user_default; - wmanaged_external_buffer temp_external(detail::move_impl(user_buffer)); - user_default = detail::move_impl(temp_external); - user_buffer = detail::move_impl(user_default); + wmanaged_external_buffer temp_external(boost::interprocess::move(user_buffer)); + user_default = boost::interprocess::move(temp_external); + user_buffer = boost::interprocess::move(user_default); wmanaged_heap_memory heap_default; - wmanaged_heap_memory temp_heap(detail::move_impl(heap_buffer)); - heap_default = detail::move_impl(temp_heap); - heap_buffer = detail::move_impl(heap_default); + wmanaged_heap_memory temp_heap(boost::interprocess::move(heap_buffer)); + heap_default = boost::interprocess::move(temp_heap); + heap_buffer = boost::interprocess::move(heap_default); } //Initialize memory diff --git a/test/vector_test.cpp b/test/vector_test.cpp index afb1e12..d78974f 100644 --- a/test/vector_test.cpp +++ b/test/vector_test.cpp @@ -44,16 +44,7 @@ int test_expand_bwd() if(!test::test_all_expand_bwd()) return 1; -/* - //First raw volatile ints - typedef test::expand_bwd_test_allocator - volatile_int_allocator_type; - typedef vector - volatile_int_vector; - if(!test::test_all_expand_bwd()) - return 1; -*/ //Now user defined wrapped int typedef test::expand_bwd_test_allocator int_holder_allocator_type; @@ -94,17 +85,16 @@ int main() { //Now test move semantics vector original; - vector move_ctor(detail::move_impl(original)); + vector move_ctor(boost::interprocess::move(original)); vector move_assign; - move_assign = detail::move_impl(move_ctor); - move_assign.swap(detail::move_impl(original)); + move_assign = boost::interprocess::move(move_ctor); move_assign.swap(original); } typedef allocator ShmemAllocator; typedef vector MyVector; - //typedef allocator ShmemVolatileAllocator; - //typedef vector MyVolatileVector; + typedef test::allocator_v1 ShmemV1Allocator; + typedef vector MyV1Vector; typedef allocator ShmemMoveAllocator; typedef vector MyMoveVector; @@ -115,8 +105,8 @@ int main() if(test::vector_test()) return 1; - //if(test::vector_test()) - //return 1; + if(test::vector_test()) + return 1; if(test::vector_test()) return 1; diff --git a/test/vector_test.hpp b/test/vector_test.hpp index dd3e46f..e4c891d 100644 --- a/test/vector_test.hpp +++ b/test/vector_test.hpp @@ -17,8 +17,8 @@ #include #include -#include #include +#include #include "print_container.hpp" #include "check_equal_containers.hpp" #include "movable_int.hpp" @@ -32,14 +32,14 @@ namespace interprocess{ namespace test{ template -bool copyable_only(V1 *, V2 *, detail::false_type) +bool copyable_only(V1 *, V2 *, boost::interprocess::detail::false_type) { return true; } //Function to check if both sets are equal template -bool copyable_only(V1 *shmvector, V2 *stdvector, detail::true_type) +bool copyable_only(V1 *shmvector, V2 *stdvector, boost::interprocess::detail::true_type) { typedef typename V1::value_type IntType; std::size_t size = shmvector->size(); @@ -50,18 +50,18 @@ bool copyable_only(V1 *shmvector, V2 *stdvector, detail::true_type) { IntType move_me(1); stdvector->insert(stdvector->begin()+size/2, 50, 1); - shmvector->insert(shmvector->begin()+size/2, 50, detail::move_impl(move_me)); + shmvector->insert(shmvector->begin()+size/2, 50, boost::interprocess::move(move_me)); if(!test::CheckEqualContainers(shmvector, stdvector)) return false; } { IntType move_me(2); - shmvector->assign(shmvector->size()/2, detail::move_impl(move_me)); + shmvector->assign(shmvector->size()/2, boost::interprocess::move(move_me)); stdvector->assign(stdvector->size()/2, 2); if(!test::CheckEqualContainers(shmvector, stdvector)) return false; } { IntType move_me(3); - shmvector->assign(shmvector->size()*3-1, detail::move_impl(move_me)); + shmvector->assign(shmvector->size()*3-1, boost::interprocess::move(move_me)); stdvector->assign(stdvector->size()*3-1, 3); if(!test::CheckEqualContainers(shmvector, stdvector)) return false; } @@ -111,8 +111,9 @@ int vector_test() for(int i = 0; i < max; ++i){ IntType new_int(i); - shmvector->insert(shmvector->end(), detail::move_impl(new_int)); + shmvector->insert(shmvector->end(), boost::interprocess::move(new_int)); stdvector->insert(stdvector->end(), i); + if(!test::CheckEqualContainers(shmvector, stdvector)) return 1; } if(!test::CheckEqualContainers(shmvector, stdvector)) return 1; @@ -133,7 +134,8 @@ int vector_test() IntType aux_vect[50]; for(int i = 0; i < 50; ++i){ IntType new_int(-1); - aux_vect[i] = detail::move_impl(new_int); + BOOST_STATIC_ASSERT((boost::interprocess::is_movable::value == true)); + aux_vect[i] = boost::interprocess::move(new_int); } int aux_vect2[50]; for(int i = 0; i < 50; ++i){ @@ -141,8 +143,8 @@ int vector_test() } shmvector->insert(shmvector->end() - ,detail::make_move_iterator(&aux_vect[0]) - ,detail::make_move_iterator(aux_vect + 50)); + ,boost::interprocess::make_move_iterator(&aux_vect[0]) + ,boost::interprocess::make_move_iterator(aux_vect + 50)); stdvector->insert(stdvector->end(), aux_vect2, aux_vect2 + 50); if(!test::CheckEqualContainers(shmvector, stdvector)) return 1; @@ -156,15 +158,15 @@ int vector_test() IntType aux_vect[50]; for(int i = 0; i < 50; ++i){ IntType new_int(-1); - aux_vect[i] = detail::move_impl(new_int); + aux_vect[i] = boost::interprocess::move(new_int); } int aux_vect2[50]; for(int i = 0; i < 50; ++i){ aux_vect2[i] = -1; } shmvector->insert(shmvector->begin() - ,detail::make_move_iterator(&aux_vect[0]) - ,detail::make_move_iterator(aux_vect + 50)); + ,boost::interprocess::make_move_iterator(&aux_vect[0]) + ,boost::interprocess::make_move_iterator(aux_vect + 50)); stdvector->insert(stdvector->begin(), aux_vect2, aux_vect2 + 50); if(!test::CheckEqualContainers(shmvector, stdvector)) return 1; } @@ -174,7 +176,7 @@ int vector_test() if(!test::CheckEqualContainers(shmvector, stdvector)) return 1; IntType push_back_this(1); - shmvector->push_back(detail::move_impl(push_back_this)); + shmvector->push_back(boost::interprocess::move(push_back_this)); stdvector->push_back(int(1)); if(!test::CheckEqualContainers(shmvector, stdvector)) return 1; @@ -189,7 +191,7 @@ int vector_test() for(int i = 0; i < max; ++i){ IntType insert_this(i); - shmvector->insert(shmvector->begin(), detail::move_impl(insert_this)); + shmvector->insert(shmvector->begin(), boost::interprocess::move(insert_this)); stdvector->insert(stdvector->begin(), i); } if(!test::CheckEqualContainers(shmvector, stdvector)) return 1; @@ -204,6 +206,18 @@ int vector_test() stdvector->assign(l.begin(), l.end()); if(!test::CheckEqualContainers(shmvector, stdvector)) return 1; } +/* + std::size_t cap = shmvector->capacity(); + shmvector->reserve(cap*2); + stdvector->reserve(cap*2); + if(!test::CheckEqualContainers(shmvector, stdvector)) return 1; + shmvector->resize(0); + stdvector->resize(0); + if(!test::CheckEqualContainers(shmvector, stdvector)) return 1; + shmvector->resize(cap*2); + stdvector->resize(cap*2); + if(!test::CheckEqualContainers(shmvector, stdvector)) return 1; +*/ delete stdvector; segment.template destroy("MyShmVector"); diff --git a/test/windows_shared_memory_mapping_test.cpp b/test/windows_shared_memory_mapping_test.cpp index 8bd4f10..0135367 100644 --- a/test/windows_shared_memory_mapping_test.cpp +++ b/test/windows_shared_memory_mapping_test.cpp @@ -10,7 +10,7 @@ #include -#ifdef BOOST_WINDOWS +#ifdef BOOST_INTERPROCESS_WINDOWS #include #include diff --git a/test/windows_shared_memory_test.cpp b/test/windows_shared_memory_test.cpp index 2f8512e..ae5ac7f 100644 --- a/test/windows_shared_memory_test.cpp +++ b/test/windows_shared_memory_test.cpp @@ -11,7 +11,7 @@ #include #include -#ifdef BOOST_WINDOWS +#ifdef BOOST_INTERPROCESS_WINDOWS #include #include @@ -32,16 +32,14 @@ static const char *name_initialization_routine() } static const std::size_t ShmSize = 1000; +typedef detail::managed_open_or_create_impl + windows_shared_memory_t; //This wrapper is necessary to have a common constructor //in generic named_creation_template functions class shared_memory_creation_test_wrapper - : public detail::managed_open_or_create_impl - + : public windows_shared_memory_t { - typedef detail::managed_open_or_create_impl - windows_shared_memory_t; - public: shared_memory_creation_test_wrapper(create_only_t) : windows_shared_memory_t(create_only, name_initialization_routine(), ShmSize) @@ -59,8 +57,6 @@ class shared_memory_creation_test_wrapper int main () { - typedef detail::managed_open_or_create_impl windows_shared_memory_t; - try{ test::test_named_creation(); } @@ -79,6 +75,6 @@ int main() return 0; } -#endif //#ifdef BOOST_WINDOWS +#endif //#ifdef BOOST_INTERPROCESS_WINDOWS #include