File indexing completed on 2025-01-18 10:13:51
0001 #ifndef ALIGNMENT_ALLOCATOR_H
0002 #define ALIGNMENT_ALLOCATOR_H
0003
0004 #include <stdlib.h>
0005
0006
0007
0008
0009 template <typename T, std::size_t N = 16>
0010 class AlignmentAllocator {
0011 public:
0012 typedef T value_type;
0013 typedef std::size_t size_type;
0014 typedef std::ptrdiff_t difference_type;
0015
0016 typedef T *pointer;
0017 typedef const T *const_pointer;
0018
0019 typedef T &reference;
0020 typedef const T &const_reference;
0021
0022 public:
0023 inline AlignmentAllocator() throw() {}
0024
0025 template <typename T2>
0026 inline AlignmentAllocator(const AlignmentAllocator<T2, N> &) throw()
0027 {
0028 }
0029
0030 inline ~AlignmentAllocator() throw() {}
0031
0032 inline pointer adress(reference r) { return &r; }
0033
0034 inline const_pointer adress(const_reference r) const { return &r; }
0035
0036 inline pointer allocate(size_type n) { return (pointer) vecCore::AlignedAlloc(N, n * sizeof(value_type)); }
0037
0038 inline void deallocate(pointer p, size_type) { vecCore::AlignedFree(p); }
0039
0040 inline void construct(pointer p, const value_type &wert) { new (p) value_type(wert); }
0041
0042 inline void destroy(pointer p) { p->~value_type(); }
0043
0044 inline size_type max_size() const throw() { return size_type(-1) / sizeof(value_type); }
0045
0046 template <typename T2>
0047 struct rebind {
0048 typedef AlignmentAllocator<T2, N> other;
0049 };
0050
0051 bool operator!=(const AlignmentAllocator<T, N> &other) const { return !(*this == other); }
0052
0053
0054
0055
0056 bool operator==(const AlignmentAllocator<T, N> & ) const { return true; }
0057 };
0058
0059 #endif