|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r54052 - in sandbox/monotonic: boost/monotonic libs/monotonic/test
From: christian.schladetsch_at_[hidden]
Date: 2009-06-18 06:00:06
Author: cschladetsch
Date: 2009-06-18 06:00:05 EDT (Thu, 18 Jun 2009)
New Revision: 54052
URL: http://svn.boost.org/trac/boost/changeset/54052
Log:
fixed ordering of links in storage
Text files modified:
sandbox/monotonic/boost/monotonic/storage.hpp | 21 +++++++++++++--------
sandbox/monotonic/libs/monotonic/test/main.cpp | 4 ++--
sandbox/monotonic/libs/monotonic/test/test_map_list.cpp | 26 +++++++++++---------------
3 files changed, 26 insertions(+), 25 deletions(-)
Modified: sandbox/monotonic/boost/monotonic/storage.hpp
==============================================================================
--- sandbox/monotonic/boost/monotonic/storage.hpp (original)
+++ sandbox/monotonic/boost/monotonic/storage.hpp 2009-06-18 06:00:05 EDT (Thu, 18 Jun 2009)
@@ -37,6 +37,7 @@
Link(Allocator const &al, size_t cap)
: capacity(cap), cursor(0), buffer(0), alloc(al)
{
+ Construct();
}
void Construct()
{
@@ -44,6 +45,10 @@
if (buffer == 0)
capacity = 0;
}
+ size_t remaining() const
+ {
+ return capacity - cursor;
+ }
void reset()
{
cursor = 0;
@@ -74,7 +79,7 @@
}
friend bool operator<(Link const &A, Link const &B)
{
- return A.capacity < B.capacity;
+ return A.remaining() < B.remaining();
}
};
typedef std::vector<Link, Al> Chain; // maintained a priority-queue
@@ -134,8 +139,11 @@
return ptr;
}
}
- size_t size = std::max(MinHeapIncrement, num_bytes*2);
- return AddLink(size).Allocate(num_bytes, alignment);
+ AddLink(std::max(MinHeapIncrement, num_bytes*2));
+ void *ptr = chain.front().Allocate(num_bytes, alignment);
+ if (ptr == 0)
+ throw std::bad_alloc();
+ return ptr;
}
size_t max_size() const
@@ -162,13 +170,10 @@
}
private:
- Link &AddLink(size_t size)
+ void AddLink(size_t size)
{
chain.push_back(Link(alloc, size));
- Link &link = chain.back();
- link.Construct();
- std::make_heap(chain.begin(), chain.end());
- return link;
+ std::push_heap(chain.begin(), chain.end());
}
};
Modified: sandbox/monotonic/libs/monotonic/test/main.cpp
==============================================================================
--- sandbox/monotonic/libs/monotonic/test/main.cpp (original)
+++ sandbox/monotonic/libs/monotonic/test/main.cpp 2009-06-18 06:00:05 EDT (Thu, 18 Jun 2009)
@@ -370,8 +370,8 @@
#endif
//test_chained_storage();
- //test_map_list_heap_stack();
- compare_memory_pool();
+ test_map_list_heap_stack();
+ //compare_memory_pool();
//test_mono_map();
//test_mono_map();
//test_static_storage();
Modified: sandbox/monotonic/libs/monotonic/test/test_map_list.cpp
==============================================================================
--- sandbox/monotonic/libs/monotonic/test/test_map_list.cpp (original)
+++ sandbox/monotonic/libs/monotonic/test/test_map_list.cpp 2009-06-18 06:00:05 EDT (Thu, 18 Jun 2009)
@@ -7,21 +7,17 @@
for (size_t n = 0; n < count; ++n)
{
int random = rand() % mod;
- typename Map::iterator iter = map.find(random);
- if (iter == map.end())
- {
- map.insert(make_pair(random, List(map.get_allocator())));
- }
- else
- {
- iter->second.push_back(n);
- }
+ map[random].push_back(n);
}
+ //BOOST_FOREACH(typename Map::value_type &val, map)
+ //{
+ // val.second.sort();
+ //}
}
struct Result
{
- double mono;
+ double local;
double standard;
double static_monotonic;
};
@@ -45,7 +41,7 @@
}
storage.reset();
}
- result.mono = timer.elapsed();
+ result.local = timer.elapsed();
}
// use standard allocator
@@ -79,7 +75,7 @@
}
- cout << "test_map_list: " << inner_loops << ": " << result.mono << ", " << result.static_monotonic << ", " << result.standard << endl;
+ cout << "test_map_list: " << inner_loops << ": " << result.local << ", " << result.static_monotonic << ", " << result.standard << endl;
return result;
}
@@ -91,18 +87,18 @@
typedef std::map<size_t, Result > Results;
Results results;
- monotonic::local<> storage;
+ monotonic::local<monotonic::storage<1000000, 0> > storage;
for (size_t inner = 100; inner < inner_loops; inner += 1000)
{
results[inner] = test_map_list(outter_loops, inner, storage);
}
cout << "test_map_list" << endl;
- cout << "count\t" << "mono\t" << "mono_static\t" << "std\t" << "std/mono\t" << "std/mono_static" << endl;
+ cout << "count\t" << "local\t" << "mono_static\t" << "std\t" << "std/local\t" << "std/mono_static" << endl;
BOOST_FOREACH(Results::value_type const &iter, results)
{
Result const &result = iter.second;
- double mono_time = result.mono;
+ double mono_time = result.local;
double std_time = result.standard;
double static_time = result.static_monotonic;
double perc1 = 100.*std_time/mono_time;
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