|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r53957 - sandbox/monotonic/boost/monotonic
From: christian.schladetsch_at_[hidden]
Date: 2009-06-15 22:32:03
Author: cschladetsch
Date: 2009-06-15 22:32:02 EDT (Mon, 15 Jun 2009)
New Revision: 53957
URL: http://svn.boost.org/trac/boost/changeset/53957
Log:
temp hax
Text files modified:
sandbox/monotonic/boost/monotonic/chained_storage.h | 61 ++++++++++++++++++++++++++-------------
1 files changed, 40 insertions(+), 21 deletions(-)
Modified: sandbox/monotonic/boost/monotonic/chained_storage.h
==============================================================================
--- sandbox/monotonic/boost/monotonic/chained_storage.h (original)
+++ sandbox/monotonic/boost/monotonic/chained_storage.h 2009-06-15 22:32:02 EDT (Mon, 15 Jun 2009)
@@ -29,6 +29,9 @@
size_t capacity, cursor;
char *buffer;
CharAllocator alloc;
+ Link() : capacity(0), cursor(0), buffer(0)
+ {
+ }
Link(Allocator const &al, size_t cap)
: capacity(cap), cursor(0), buffer(0), alloc(al)
{
@@ -47,56 +50,69 @@
{
return capacity - cursor >= num_bytes;
}
- void *Allocate(size_t num_bytes, size_t alignment)
+ inline void *Allocate(size_t num_bytes, size_t alignment)
{
size_t extra = cursor & (alignment - 1);
if (extra > 0)
extra = alignment - extra;
size_t required = num_bytes + extra;
- if (!CanAllocate(required))
- {
+ if (capacity - cursor < required)
return 0;
- }
- char *ptr = &buffer[cursor];
+ char *ptr = buffer + cursor;
cursor += required;
return ptr + extra;
}
};
- typedef std::list<Link, Al> Chain;
+ //typedef std::list<Link, Al> Chain;
+ typedef boost::array<Link, 200> Chain;
private:
storage<N> fixed; // the inline storage
Chain chain; // heap-based storage
Allocator alloc; // allocator for heap-based storage
+ size_t next_link;
public:
- chained_storage()
+ chained_storage()
+ : next_link(0)
{
}
chained_storage(Allocator const &A)
- : alloc(A)
+ : alloc(A), next_link(0)
{
}
void reset()
{
fixed.reset();
- chain.clear();
+ //chain.clear();
+ chain = Chain();
+ next_link = 0;
}
void *allocate(size_t num_bytes, size_t alignment)
{
- if (void *ptr = fixed.allocate(num_bytes, alignment))
- {
+ //if (void *ptr = fixed.allocate(num_bytes, alignment))
+ //{
+ // return ptr;
+ //}
+ void *ptr;
+ ptr = chain[0].Allocate(num_bytes, alignment);
+ if (ptr)
return ptr;
- }
- BOOST_FOREACH(Link &link, chain)
- {
- if (void *ptr = link.Allocate(num_bytes, alignment))
- {
- return ptr;
- }
- }
+ ptr = chain[1].Allocate(num_bytes, alignment);
+ if (ptr)
+ return ptr;
+ ptr = chain[2].Allocate(num_bytes, alignment);
+ if (ptr)
+ return ptr;
+ //BOOST_FOREACH(Link &link, chain)
+ //{
+ // if (void *ptr = link.Allocate(num_bytes, alignment))
+ // {
+ // return ptr;
+ // }
+ //}
size_t size = max(MinLinkSize, num_bytes*2);
return AddLink(size).Allocate(num_bytes, alignment);
}
@@ -132,8 +148,11 @@
private:
Link &AddLink(size_t size)
{
- chain.push_back(Link(alloc, size));
- Link &link = chain.back();
+ //chain.push_back(Link(alloc, size));
+ //Link &link = chain.back();
+ //link.Construct();
+ Link &link = chain[next_link++];
+ link = Link(alloc, size);
link.Construct();
return link;
}
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