Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r54237 - in sandbox/monotonic: boost/monotonic libs/monotonic/test libs/monotonic/test/Tests
From: christian.schladetsch_at_[hidden]
Date: 2009-06-22 18:41:15


Author: cschladetsch
Date: 2009-06-22 18:41:14 EDT (Mon, 22 Jun 2009)
New Revision: 54237
URL: http://svn.boost.org/trac/boost/changeset/54237

Log:
added monotonic::region_allocator<T, Region>

Added:
   sandbox/monotonic/libs/monotonic/test/Tests/ (props changed)
   sandbox/monotonic/libs/monotonic/test/Tests/Tests.vcproj (contents, props changed)
   sandbox/monotonic/libs/monotonic/test/Tests/tests.cpp (contents, props changed)
Removed:
   sandbox/monotonic/libs/monotonic/test/basic_tests.cpp
Text files modified:
   sandbox/monotonic/boost/monotonic/config.hpp | 3 ++
   sandbox/monotonic/boost/monotonic/forward_declarations.hpp | 2
   sandbox/monotonic/boost/monotonic/region_allocator.hpp | 53 ++++++++++++++++++++++++++++++++++++---
   sandbox/monotonic/boost/monotonic/static_storage.hpp | 10 +++++++
   sandbox/monotonic/libs/monotonic/test/monotonic.sln | 9 ++++++
   sandbox/monotonic/libs/monotonic/test/monotonic.vcproj | 28 ---------------------
   6 files changed, 70 insertions(+), 35 deletions(-)

Modified: sandbox/monotonic/boost/monotonic/config.hpp
==============================================================================
--- sandbox/monotonic/boost/monotonic/config.hpp (original)
+++ sandbox/monotonic/boost/monotonic/config.hpp 2009-06-22 18:41:14 EDT (Mon, 22 Jun 2009)
@@ -21,6 +21,9 @@
                                 StaticInlineSize = 1*1024*1024, ///< inline size for a global store. this goes into your BSS
                                 StaticMinHeapIncrement = 32*1024*1024,
                                 MinPoolSize = 8,
+
+ RegionInlineSize = 8*1024,
+ MaxRegions = 200,
                         };
                 };
 

Modified: sandbox/monotonic/boost/monotonic/forward_declarations.hpp
==============================================================================
--- sandbox/monotonic/boost/monotonic/forward_declarations.hpp (original)
+++ sandbox/monotonic/boost/monotonic/forward_declarations.hpp 2009-06-22 18:41:14 EDT (Mon, 22 Jun 2009)
@@ -67,7 +67,7 @@
                 struct allocator;
 
                 /// a monotonic region allocator uses a specified storage
- template <size_t RegionNumber, class T>
+ template <class T, size_t Region = 0>
                 struct region_allocator;
 
                 /// a monotonic shared_allocator has a shared storage buffer and a no-op deallocate() method

Modified: sandbox/monotonic/boost/monotonic/region_allocator.hpp
==============================================================================
--- sandbox/monotonic/boost/monotonic/region_allocator.hpp (original)
+++ sandbox/monotonic/boost/monotonic/region_allocator.hpp 2009-06-22 18:41:14 EDT (Mon, 22 Jun 2009)
@@ -12,8 +12,8 @@
 {
         namespace monotonic
         {
- template <>
- struct region_allocator<void>
+ template <size_t N>
+ struct region_allocator<void, N>
                 {
                         typedef void* pointer;
                         typedef const void* const_pointer;
@@ -22,16 +22,59 @@
                         template <class U>
                         struct rebind
                         {
- typedef region_allocator<U> other;
+ typedef region_allocator<U, N> other;
                         };
                 };
 
                 storage_base &get_storage();
                 storage_base *set_storage(storage_base &);
 
- template <size_t Region, class T>
- struct region_allocator : allocator_base<T, region_allocator<T> >
+ /// each region is distinct from other regions
+ template <class T, size_t Region>
+ struct region_allocator : allocator_base<T, region_allocator<T, Region> >
                 {
+ typedef allocator_base<T, region_allocator<T, Region> > Parent;
+ using typename Parent::size_type;
+ using typename Parent::difference_type;
+ using typename Parent::pointer;
+ using typename Parent::const_pointer;
+ using typename Parent::reference;
+ using typename Parent::const_reference;
+ using typename Parent::value_type;
+
+ template <class U>
+ struct rebind
+ {
+ typedef region_allocator<U, Region> other;
+ };
+
+ region_allocator() throw()
+ : Parent(boost::monotonic::get_region_storage<Region>()) { }
+
+ public:
+ //private:
+ template <class Storage> struct local;
+
+ region_allocator(storage_base &store) throw()
+ : Parent(store) { }
+
+ public:
+ region_allocator(const region_allocator& alloc) throw()
+ : Parent(alloc) { }
+
+ template <class U, size_t N>
+ region_allocator(const region_allocator<U,N> &alloc) throw()
+ : Parent(alloc) { }
+
+ friend bool operator==(region_allocator<T,Region> const &A, region_allocator<T,Region> const &B)
+ {
+ return static_cast<Parent const &>(A) == static_cast<Parent const &>(B);
+ }
+
+ friend bool operator!=(region_allocator<T,Region> const &A, region_allocator<T,Region> const &B)
+ {
+ return static_cast<Parent const &>(A) != static_cast<Parent const &>(B);
+ }
                 };
 
         } // namespace monotonic

Modified: sandbox/monotonic/boost/monotonic/static_storage.hpp
==============================================================================
--- sandbox/monotonic/boost/monotonic/static_storage.hpp (original)
+++ sandbox/monotonic/boost/monotonic/static_storage.hpp 2009-06-22 18:41:14 EDT (Mon, 22 Jun 2009)
@@ -59,6 +59,16 @@
                 extern static_storage_base<> default_static_storage;
                 extern storage_base *static_storage;
 
+ extern storage_base *static_storage;
+
+ extern boost::array<storage<DefaultSizes::RegionInlineSize>, DefaultSizes::MaxRegions> static_region_storage;
+
+ template <size_t Region>
+ inline storage_base &get_region_storage()
+ {
+ return static_region_storage[Region];
+ }
+
                 inline storage_base &get_storage()
                 {
                         return static_storage ? *static_storage : default_static_storage;

Added: sandbox/monotonic/libs/monotonic/test/Tests/Tests.vcproj
==============================================================================
--- (empty file)
+++ sandbox/monotonic/libs/monotonic/test/Tests/Tests.vcproj 2009-06-22 18:41:14 EDT (Mon, 22 Jun 2009)
@@ -0,0 +1,194 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="9.00"
+ Name="Tests"
+ ProjectGUID="{D4779B0F-266B-46D3-8BCF-0E14EF8B817B}"
+ RootNamespace="Tests"
+ Keyword="Win32Proj"
+ TargetFrameworkVersion="196613"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+ IntermediateDirectory="$(ConfigurationName)"
+ ConfigurationType="1"
+ CharacterSet="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ AdditionalIncludeDirectories="$(ProjectDir)/../../../..;C:\Lib\tbb21_20080605oss\include"
+ PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
+ MinimalRebuild="true"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="3"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ LinkIncremental="2"
+ GenerateDebugInformation="true"
+ SubSystem="1"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+ IntermediateDirectory="$(ConfigurationName)"
+ ConfigurationType="1"
+ CharacterSet="1"
+ WholeProgramOptimization="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="2"
+ EnableIntrinsicFunctions="true"
+ PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
+ RuntimeLibrary="2"
+ EnableFunctionLevelLinking="true"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ LinkIncremental="1"
+ GenerateDebugInformation="true"
+ SubSystem="1"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
+ UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
+ >
+ <File
+ RelativePath=".\tests.cpp"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl;inc;xsd"
+ UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
+ >
+ </Filter>
+ <Filter
+ Name="Resource Files"
+ Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
+ UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
+ >
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>

Added: sandbox/monotonic/libs/monotonic/test/Tests/tests.cpp
==============================================================================
--- (empty file)
+++ sandbox/monotonic/libs/monotonic/test/Tests/tests.cpp 2009-06-22 18:41:14 EDT (Mon, 22 Jun 2009)
@@ -0,0 +1,243 @@
+#define BOOST_TEST_DYN_LINK
+#define BOOST_TEST_MAIN
+
+#include <boost/monotonic/extra/string.hpp>
+#include <boost/monotonic/extra/vector.hpp>
+#include <boost/monotonic/extra/list.hpp>
+#include <boost/monotonic/extra/set.hpp>
+#include <boost/monotonic/extra/map.hpp>
+#include <boost/monotonic/region_allocator.hpp>
+
+#define BOOST_TEST_MODULE basic_test test
+#include <boost/test/unit_test.hpp>
+
+using namespace std;
+using namespace boost;
+
+#ifdef WIN32
+// warning C4996: 'std::fill_n': Function call with parameters that may be unsafe
+#pragma warning(disable:4996)
+#endif
+
+
+BOOST_AUTO_TEST_CASE(test_region_allocator)
+{
+ typedef std::list<int, monotonic::region_allocator<int, 0> > List;
+ {
+ List list;
+ generate_n(back_inserter(list), 10, rand);
+ list.sort();
+ }
+}
+
+
+BOOST_AUTO_TEST_CASE(test_local_storage)
+{
+ monotonic::storage<10*1024> storage;
+ {
+ storage.allocate_bytes(123);
+ BOOST_ASSERT(storage.fixed_used() == 123);
+ BOOST_ASSERT(storage.heap_used() == 0);
+ BOOST_ASSERT(storage.used() == 123);
+
+ storage.reset();
+ BOOST_ASSERT(storage.fixed_used() == 0);
+ BOOST_ASSERT(storage.heap_used() == 0);
+ BOOST_ASSERT(storage.used() == 0);
+
+ // test alignment
+ storage.reset();
+ storage.allocate_bytes(12, 16);
+ BOOST_ASSERT(storage.fixed_used() == 16);
+
+ storage.allocate_bytes(12, 64);
+ BOOST_ASSERT(storage.fixed_used() == 64 + 12);
+ storage.reset();
+ }
+}
+
+BOOST_AUTO_TEST_CASE(test_local_storage_to_heap)
+{
+ monotonic::storage<16> storage;
+ {
+ storage.allocate_bytes(16);
+ BOOST_ASSERT(storage.fixed_used() == 16);
+ BOOST_ASSERT(storage.heap_used() == 0);
+
+ storage.allocate_bytes(200);
+ BOOST_ASSERT(storage.fixed_used() == 16);
+ BOOST_ASSERT(storage.heap_used() == 200);
+
+ storage.release();
+
+ BOOST_ASSERT(storage.used() == 0);
+ storage.allocate_bytes<2000>();
+ BOOST_ASSERT(storage.fixed_used() == 0);
+ BOOST_ASSERT(storage.heap_used() == 2000);
+
+ storage.allocate_bytes<10>();
+ BOOST_ASSERT(storage.fixed_used() == 10);
+ BOOST_ASSERT(storage.heap_used() == 2000);
+ }
+}
+
+BOOST_AUTO_TEST_CASE(test_local_storage_iter)
+{
+ size_t length = 4;
+ // storage starts on the stack (in this case, 10k of it), then merges into the heap as needed
+ monotonic::storage<10*1024> storage;
+ for (size_t n = 0; n < length; ++n)
+ {
+ // create a new int from storage
+ int &n0 = storage.create<int>();
+
+ // create a new string (uses correct alignment)
+ string const &s1 = storage.create<string>("foo");
+ BOOST_ASSERT(s1 == "foo");
+
+ // allocate 37 bytes with alignment 1
+ char *array0 = storage.allocate_bytes(37);
+ fill_n(array0, 37, 42);
+
+ // allocate 2537 bytes with 64-byte alignment
+ char *array1 = storage.allocate_bytes(2537, 64);
+ fill_n(array1, 2537, 123);
+
+ // allocate 1283 bytes with machine alignment
+ char *array2 = storage.allocate_bytes<1283>();
+ fill_n(array2, 1283, 42);
+
+ array<int, 42> &array3 = storage.create<array<int, 42> >();
+
+ // destroy objects. this only calls the destructors; it does not release memory
+ storage.destroy(s1);
+
+ //cout << "storage.fixed, heap, total used: " << storage.fixed_used() << ", " << storage.heap_used() << ", " << storage.used() << endl;
+ }
+ // storage is released. if this was only ever on the stack, no work is done
+}
+
+BOOST_AUTO_TEST_CASE(test_ctors)
+{
+ monotonic::storage<> storage;
+ string foo = "foo";
+ {
+ monotonic::vector<char> v1(foo.begin(), foo.end(), storage);
+ BOOST_CHECK(v1.size() == 3);
+ BOOST_CHECK(equal(v1.begin(), v1.end(), "foo"));
+
+ monotonic::vector<char> v2(6, 'x', storage);
+ BOOST_CHECK(v2.size() == 6);
+ BOOST_CHECK(equal(v2.begin(), v2.end(), "xxxxxx"));
+
+ monotonic::set<char> s2(foo.begin(), foo.end(), storage);
+ BOOST_CHECK(s2.size() == 2);
+ BOOST_CHECK(s2.find('f') != s2.end());
+ BOOST_CHECK(s2.find('o') != s2.end());
+
+ monotonic::vector<pair<int, string> > v(storage);
+ v.push_back(make_pair(42,"foo"));
+ v.push_back(make_pair(123,"bar"));
+
+ monotonic::map<int, string> m1(v.begin(), v.end(), storage);
+ BOOST_CHECK(m1.find(42) != m1.end());
+ BOOST_CHECK(m1.find(123) != m1.end());
+
+ monotonic::list<int> l1(foo.begin(), foo.end(), storage);
+ BOOST_CHECK(equal(l1.begin(), l1.end(), "foo"));
+ }
+}
+
+BOOST_AUTO_TEST_CASE( test_copy )
+{
+ monotonic::storage<> storage;
+ monotonic::vector<int> v1(storage);
+
+ for (int n = 0; n < 100; ++n)
+ v1.push_back(n);
+
+ size_t rem1 = storage.fixed_remaining();
+ monotonic::vector<int> v2(v1);
+ size_t rem2 = storage.fixed_remaining();
+
+ //BOOST_CHECK(v2 == v1);
+ //BOOST_CHECK_EQUAL(rem1 - rem2, 12 + 100*sizeof(int));
+}
+
+BOOST_AUTO_TEST_CASE(test_shared_allocators)
+{
+ monotonic::storage<> sa, sb;
+ {
+ monotonic::vector<int> v0(sa), v1(sa);
+ monotonic::vector<int> v2(sb), v3(sb);
+ monotonic::list<int> l0(sa), l1(sb);
+
+ BOOST_CHECK(v0.get_allocator() == v1.get_allocator());
+ BOOST_CHECK(v2.get_allocator() == v3.get_allocator());
+ BOOST_CHECK(v0.get_allocator() != v2.get_allocator());
+ BOOST_CHECK(v3.get_allocator() != v1.get_allocator());
+
+ for (int n = 0; n < 10; ++n)
+ v0.push_back(n);
+
+ v1 = v0;
+ v1.swap(v2); // swap from different allocators means they are copied
+ BOOST_CHECK(v1.empty() && v3.empty() && v1 == v3);
+
+ BOOST_CHECK(v2 == v0); // both are now [0..9]
+
+ v1.swap(v0); // swap from same allocators means no copying
+ BOOST_CHECK(v2 == v1);
+ BOOST_CHECK(v0 == v3);
+
+ //l0.assign(v0.begin(), v0.end());
+ //l1 = l0;
+ //BOOST_CHECK(l0 == l1);
+ }
+}
+
+BOOST_AUTO_TEST_CASE(test_basic)
+{
+ monotonic::storage<> storage;
+ {
+ monotonic::vector<int> v1(storage);
+
+ for(int i = 0; i < 100; ++i)
+ v1.push_back(i);
+
+ monotonic::vector<int> copy(storage);
+ size_t len = storage.used();
+ copy = v1;
+ size_t len2 = storage.used();
+
+ BOOST_CHECK(copy == v1);
+ BOOST_CHECK(len2 - len == 100*sizeof(int));
+
+ // create a list that uses inline, monotonically-increasing storage
+ monotonic::list<int> list(storage);
+ list.push_back(100);
+ list.push_back(400);
+ list.erase(list.begin());
+
+ // a map from the same storage
+ monotonic::map<int, float> map(storage);
+ map[42] = 3.14f;
+ BOOST_CHECK(map[42] == 3.14f);
+
+ // a set...
+ monotonic::set<float> set(storage);
+ set.insert(3.14f);
+ set.insert(-123.f);
+ BOOST_CHECK(set.size() == 2);
+ }
+}
+
+BOOST_AUTO_TEST_CASE(test_string)
+{
+ monotonic::storage<> storage;
+ {
+ monotonic::string str(storage);
+ }
+}
+
+//EOF

Deleted: sandbox/monotonic/libs/monotonic/test/basic_tests.cpp
==============================================================================
--- sandbox/monotonic/libs/monotonic/test/basic_tests.cpp 2009-06-22 18:41:14 EDT (Mon, 22 Jun 2009)
+++ (empty file)
@@ -1,244 +0,0 @@
-#define BOOST_TEST_DYN_LINK
-#define BOOST_TEST_MAIN
-
-#include <boost/monotonic/extra/string.hpp>
-#include <boost/monotonic/extra/vector.hpp>
-#include <boost/monotonic/extra/list.hpp>
-#include <boost/monotonic/extra/set.hpp>
-#include <boost/monotonic/extra/map.hpp>
-
-#define BOOST_TEST_MODULE basic_test test
-#include <boost/test/unit_test.hpp>
-
-using namespace std;
-using namespace boost;
-
-#ifdef WIN32
-// warning C4996: 'std::fill_n': Function call with parameters that may be unsafe
-#pragma warning(disable:4996)
-#endif
-
-
-BOOST_AUTO_TEST_CASE(test_local_allocator)
-{
- monotonic::storage<> storage;
- monotonic::allocator_region<0>(storage);
- typedef std::list<int, monotonic::region_allocator<0, int> > List;
- {
- List list;
- generate_n(back_inserter(list), 10, rand);
- list.sort();
- }
-}
-
-
-BOOST_AUTO_TEST_CASE(test_local_storage)
-{
- monotonic::storage<10*1024> storage;
- {
- storage.allocate_bytes(123);
- BOOST_ASSERT(storage.fixed_used() == 123);
- BOOST_ASSERT(storage.heap_used() == 0);
- BOOST_ASSERT(storage.used() == 123);
-
- storage.reset();
- BOOST_ASSERT(storage.fixed_used() == 0);
- BOOST_ASSERT(storage.heap_used() == 0);
- BOOST_ASSERT(storage.used() == 0);
-
- // test alignment
- storage.reset();
- storage.allocate_bytes(12, 16);
- BOOST_ASSERT(storage.fixed_used() == 16);
-
- storage.allocate_bytes(12, 64);
- BOOST_ASSERT(storage.fixed_used() == 64 + 12);
- storage.reset();
- }
-}
-
-BOOST_AUTO_TEST_CASE(test_local_storage_to_heap)
-{
- monotonic::storage<16> storage;
- {
- storage.allocate_bytes(16);
- BOOST_ASSERT(storage.fixed_used() == 16);
- BOOST_ASSERT(storage.heap_used() == 0);
-
- storage.allocate_bytes(200);
- BOOST_ASSERT(storage.fixed_used() == 16);
- BOOST_ASSERT(storage.heap_used() == 200);
-
- storage.release();
-
- BOOST_ASSERT(storage.used() == 0);
- storage.allocate_bytes<2000>();
- BOOST_ASSERT(storage.fixed_used() == 0);
- BOOST_ASSERT(storage.heap_used() == 2000);
-
- storage.allocate_bytes<10>();
- BOOST_ASSERT(storage.fixed_used() == 10);
- BOOST_ASSERT(storage.heap_used() == 2000);
- }
-}
-
-BOOST_AUTO_TEST_CASE(test_local_storage_iter)
-{
- size_t length = 4;
- // storage starts on the stack (in this case, 10k of it), then merges into the heap as needed
- monotonic::storage<10*1024> storage;
- for (size_t n = 0; n < length; ++n)
- {
- // create a new int from storage
- int &n0 = storage.create<int>();
-
- // create a new string (uses correct alignment)
- string const &s1 = storage.create<string>("foo");
- BOOST_ASSERT(s1 == "foo");
-
- // allocate 37 bytes with alignment 1
- char *array0 = storage.allocate_bytes(37);
- fill_n(array0, 37, 42);
-
- // allocate 2537 bytes with 64-byte alignment
- char *array1 = storage.allocate_bytes(2537, 64);
- fill_n(array1, 2537, 123);
-
- // allocate 1283 bytes with machine alignment
- char *array2 = storage.allocate_bytes<1283>();
- fill_n(array2, 1283, 42);
-
- array<int, 42> &array3 = storage.create<array<int, 42> >();
-
- // destroy objects. this only calls the destructors; it does not release memory
- storage.destroy(s1);
-
- //cout << "storage.fixed, heap, total used: " << storage.fixed_used() << ", " << storage.heap_used() << ", " << storage.used() << endl;
- }
- // storage is released. if this was only ever on the stack, no work is done
-}
-
-BOOST_AUTO_TEST_CASE(test_ctors)
-{
- monotonic::storage<> storage;
- string foo = "foo";
- {
- monotonic::vector<char> v1(foo.begin(), foo.end(), storage);
- BOOST_CHECK(v1.size() == 3);
- BOOST_CHECK(equal(v1.begin(), v1.end(), "foo"));
-
- monotonic::vector<char> v2(6, 'x', storage);
- BOOST_CHECK(v2.size() == 6);
- BOOST_CHECK(equal(v2.begin(), v2.end(), "xxxxxx"));
-
- monotonic::set<char> s2(foo.begin(), foo.end(), storage);
- BOOST_CHECK(s2.size() == 2);
- BOOST_CHECK(s2.find('f') != s2.end());
- BOOST_CHECK(s2.find('o') != s2.end());
-
- monotonic::vector<pair<int, string> > v(storage);
- v.push_back(make_pair(42,"foo"));
- v.push_back(make_pair(123,"bar"));
-
- monotonic::map<int, string> m1(v.begin(), v.end(), storage);
- BOOST_CHECK(m1.find(42) != m1.end());
- BOOST_CHECK(m1.find(123) != m1.end());
-
- monotonic::list<int> l1(foo.begin(), foo.end(), storage);
- BOOST_CHECK(equal(l1.begin(), l1.end(), "foo"));
- }
-}
-
-BOOST_AUTO_TEST_CASE( test_copy )
-{
- monotonic::storage<> storage;
- monotonic::vector<int> v1(storage);
-
- for (int n = 0; n < 100; ++n)
- v1.push_back(n);
-
- size_t rem1 = storage.fixed_remaining();
- monotonic::vector<int> v2(v1);
- size_t rem2 = storage.fixed_remaining();
-
- //BOOST_CHECK(v2 == v1);
- //BOOST_CHECK_EQUAL(rem1 - rem2, 12 + 100*sizeof(int));
-}
-
-BOOST_AUTO_TEST_CASE(test_shared_allocators)
-{
- monotonic::storage<> sa, sb;
- {
- monotonic::vector<int> v0(sa), v1(sa);
- monotonic::vector<int> v2(sb), v3(sb);
- monotonic::list<int> l0(sa), l1(sb);
-
- BOOST_CHECK(v0.get_allocator() == v1.get_allocator());
- BOOST_CHECK(v2.get_allocator() == v3.get_allocator());
- BOOST_CHECK(v0.get_allocator() != v2.get_allocator());
- BOOST_CHECK(v3.get_allocator() != v1.get_allocator());
-
- for (int n = 0; n < 10; ++n)
- v0.push_back(n);
-
- v1 = v0;
- v1.swap(v2); // swap from different allocators means they are copied
- BOOST_CHECK(v1.empty() && v3.empty() && v1 == v3);
-
- BOOST_CHECK(v2 == v0); // both are now [0..9]
-
- v1.swap(v0); // swap from same allocators means no copying
- BOOST_CHECK(v2 == v1);
- BOOST_CHECK(v0 == v3);
-
- //l0.assign(v0.begin(), v0.end());
- //l1 = l0;
- //BOOST_CHECK(l0 == l1);
- }
-}
-
-BOOST_AUTO_TEST_CASE(test_basic)
-{
- monotonic::storage<> storage;
- {
- monotonic::vector<int> v1(storage);
-
- for(int i = 0; i < 100; ++i)
- v1.push_back(i);
-
- monotonic::vector<int> copy(storage);
- size_t len = storage.used();
- copy = v1;
- size_t len2 = storage.used();
-
- BOOST_CHECK(copy == v1);
- BOOST_CHECK(len2 - len == 100*sizeof(int));
-
- // create a list that uses inline, monotonically-increasing storage
- monotonic::list<int> list(storage);
- list.push_back(100);
- list.push_back(400);
- list.erase(list.begin());
-
- // a map from the same storage
- monotonic::map<int, float> map(storage);
- map[42] = 3.14f;
- BOOST_CHECK(map[42] == 3.14f);
-
- // a set...
- monotonic::set<float> set(storage);
- set.insert(3.14f);
- set.insert(-123.f);
- BOOST_CHECK(set.size() == 2);
- }
-}
-
-BOOST_AUTO_TEST_CASE(test_string)
-{
- monotonic::storage<> storage;
- {
- monotonic::string str(storage);
- }
-}
-
-//EOF

Modified: sandbox/monotonic/libs/monotonic/test/monotonic.sln
==============================================================================
--- sandbox/monotonic/libs/monotonic/test/monotonic.sln (original)
+++ sandbox/monotonic/libs/monotonic/test/monotonic.sln 2009-06-22 18:41:14 EDT (Mon, 22 Jun 2009)
@@ -5,6 +5,8 @@
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PoolTime", "PoolTime\PoolTime.vcproj", "{470832FD-33D6-4F31-AD06-BB7838371077}"
 EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Tests", "Tests\Tests.vcproj", "{D4779B0F-266B-46D3-8BCF-0E14EF8B817B}"
+EndProject
 Global
         GlobalSection(SolutionConfigurationPlatforms) = preSolution
                 Debug|Win32 = Debug|Win32
@@ -19,10 +21,15 @@
                 {5688980A-015B-4C7D-8D8D-F5894205FACE}.ReleaseSym|Win32.ActiveCfg = ReleaseSym|Win32
                 {5688980A-015B-4C7D-8D8D-F5894205FACE}.ReleaseSym|Win32.Build.0 = ReleaseSym|Win32
                 {470832FD-33D6-4F31-AD06-BB7838371077}.Debug|Win32.ActiveCfg = Debug|Win32
- {470832FD-33D6-4F31-AD06-BB7838371077}.Debug|Win32.Build.0 = Debug|Win32
                 {470832FD-33D6-4F31-AD06-BB7838371077}.Release|Win32.ActiveCfg = Release|Win32
                 {470832FD-33D6-4F31-AD06-BB7838371077}.ReleaseSym|Win32.ActiveCfg = ReleaseSym|Win32
                 {470832FD-33D6-4F31-AD06-BB7838371077}.ReleaseSym|Win32.Build.0 = ReleaseSym|Win32
+ {D4779B0F-266B-46D3-8BCF-0E14EF8B817B}.Debug|Win32.ActiveCfg = Debug|Win32
+ {D4779B0F-266B-46D3-8BCF-0E14EF8B817B}.Debug|Win32.Build.0 = Debug|Win32
+ {D4779B0F-266B-46D3-8BCF-0E14EF8B817B}.Release|Win32.ActiveCfg = Release|Win32
+ {D4779B0F-266B-46D3-8BCF-0E14EF8B817B}.Release|Win32.Build.0 = Release|Win32
+ {D4779B0F-266B-46D3-8BCF-0E14EF8B817B}.ReleaseSym|Win32.ActiveCfg = Release|Win32
+ {D4779B0F-266B-46D3-8BCF-0E14EF8B817B}.ReleaseSym|Win32.Build.0 = Release|Win32
         EndGlobalSection
         GlobalSection(SolutionProperties) = preSolution
                 HideSolutionNode = FALSE

Modified: sandbox/monotonic/libs/monotonic/test/monotonic.vcproj
==============================================================================
--- sandbox/monotonic/libs/monotonic/test/monotonic.vcproj (original)
+++ sandbox/monotonic/libs/monotonic/test/monotonic.vcproj 2009-06-22 18:41:14 EDT (Mon, 22 Jun 2009)
@@ -409,34 +409,6 @@
>
                 </File>
                 <File
- RelativePath=".\basic_tests.cpp"
- >
- <FileConfiguration
- Name="Debug|Win32"
- ExcludedFromBuild="true"
- >
- <Tool
- Name="VCCLCompilerTool"
- />
- </FileConfiguration>
- <FileConfiguration
- Name="Release|Win32"
- ExcludedFromBuild="true"
- >
- <Tool
- Name="VCCLCompilerTool"
- />
- </FileConfiguration>
- <FileConfiguration
- Name="ReleaseSym|Win32"
- ExcludedFromBuild="true"
- >
- <Tool
- Name="VCCLCompilerTool"
- />
- </FileConfiguration>
- </File>
- <File
                         RelativePath=".\compare_memory_pool.cpp"
>
                         <FileConfiguration


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk