1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
| template <class T , int Alignment=16>
class aligned_allocator
{
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef T* pointer;
typedef const T* const_pointer;
typedef T& reference;
typedef const T& const_reference;
typedef T value_type;
template <class U>
struct rebind
{
typedef aligned_allocator<U> other;
};
pointer address (reference value) const
{
return &value;
};
const_pointer address (const_reference value) const
{
return &value;
};
aligned_allocator() throw()
{
};
aligned_allocator(const aligned_allocator&) throw()
{
};
template <class U>
aligned_allocator (const aligned_allocator<U>&) throw()
{
};
~aligned_allocator() throw()
{
};
//max capacity
size_type max_size () const throw()
{
return 268435455;
};
pointer allocate (size_type num, const_pointer *hint = 0)
{
return (pointer) _aligned_malloc( num*sizeof(T),Alignment);
};
void construct (pointer p, const T& value)
{
// memcpy( p, &value, sizeof T );
*p=value;
// new ( (void *) p ) T ( value );
};
void destroy (pointer p)
{
p->~T();
};
void deallocate (pointer p, size_type num)
{
_aligned_free( p );
};
}; |