35 #ifndef ALLOCATORS_ALIGNED_H 36 #define ALLOCATORS_ALIGNED_H 39 #include <boost/cstdint.hpp> 55 const int pointerSize =
sizeof(
void*);
56 const int requestedSize = size + alignment - 1 + pointerSize;
57 void* raw = std::malloc(requestedSize);
64 void* start = (uint8_t*)raw + pointerSize;
65 void* aligned = (
void*)(((uintptr_t)((uint8_t*)start+alignment-1)) & ~(alignment-1));
66 *(
void**)((uint8_t*)aligned-pointerSize) = raw;
81 void* raw = *(
void**)((uint8_t*)aligned -
sizeof(
void*));
88 template<
size_t align>
109 template<
class T,
size_t align>
139 const_pointer
address(const_reference r)
const 145 return ~size_type(0);
152 throw std::bad_alloc();
155 return static_cast<pointer
>(mem);
174 #endif // ALLOCATORS_ALIGNED_H
AlignedAllocator< U, align > other
pointer address(reference r) const
AlignedAllocator< U, align > other
const void * const_pointer
An stl-compatible aligned allocator.
const_pointer address(const_reference r) const
ptrdiff_t difference_type
const T & const_reference
void deallocate(pointer p, size_type n)
void * alignedMalloc(size_t size, size_t alignment)
Allocate memory aligned at on a value. Memory allocated through alignedMalloc() must be freed through...
size_type max_size() const
void alignedFree(void *aligned)
Free memory allocated through alignedMalloc()
void construct(pointer p, const_reference val)
pointer allocate(size_type n, typename AlignedAllocator< void, align >::const_pointer hint=0)