|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r54463 - sandbox/monotonic/boost/heterogenous
From: christian.schladetsch_at_[hidden]
Date: 2009-06-28 05:50:13
Author: cschladetsch
Date: 2009-06-28 05:50:12 EDT (Sun, 28 Jun 2009)
New Revision: 54463
URL: http://svn.boost.org/trac/boost/changeset/54463
Log:
temp hax for alignment
Text files modified:
sandbox/monotonic/boost/heterogenous/make_clone_allocator.hpp | 25 +++++++++++++++----------
1 files changed, 15 insertions(+), 10 deletions(-)
Modified: sandbox/monotonic/boost/heterogenous/make_clone_allocator.hpp
==============================================================================
--- sandbox/monotonic/boost/heterogenous/make_clone_allocator.hpp (original)
+++ sandbox/monotonic/boost/heterogenous/make_clone_allocator.hpp 2009-06-28 05:50:12 EDT (Sun, 28 Jun 2009)
@@ -24,24 +24,29 @@
clone_allocator() { }
clone_allocator(Alloc &a) : Alloc(a) { }
+ struct header
+ {
+ header *allocated_ptr;
+ size_t num_bytes;
+ };
+
abstract_allocator::pointer allocate_bytes(size_t num_bytes, size_t alignment)
{
CharAlloc alloc(*this);
- size_t required = num_bytes;
- if (num_bytes < alignment)
- required = alignment;
- else
- required = num_bytes + alignment; // TODO: don't really need this much
- abstract_allocator::pointer ptr = alloc.allocate(required);
- size_t extra = calc_padding(ptr, alignment);
- return ptr + extra;
+ header head;
+ head.num_bytes = sizeof(header) + num_bytes + alignment; // don't need this much, but will do for now
+ head.allocated_ptr = (header *)alloc.allocate(head.num_bytes);
+ *head.allocated_ptr = head;
+ pointer base = head.allocated_ptr + sizeof(header);
+ base += calc_padding(base, alignment);
+ return base;
}
void deallocate_bytes(abstract_allocator::pointer ptr, size_t alignment)
{
CharAlloc alloc(*this);
- size_t extra = calc_padding(ptr, alignment);
- alloc.deallocate(ptr - extra, 1);
+ header *head = ptr - sizeof(head);
+ alloc.deallocate(head->allocated_ptr, head->num_bytes);
}
};
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