34 #ifndef __CU_ALIGNED_H__
35 #define __CU_ALIGNED_H__
42 #pragma mark Aligned Arrays Template
67 #pragma mark Constructors
88 _capacity =
size*
sizeof(T)+alignment;
91 _orig = malloc(_capacity);
92 _pntr = (T*)std::align(alignment,_length*
sizeof(T),_orig,_capacity);
101 _capacity = copy._capacity;
102 _length = copy._length;
103 _alignm = copy._alignm;
104 _orig = malloc(_capacity);
105 _pntr = (T*)std::align(_alignm,_length*
sizeof(T),_orig,_capacity);
106 std::memcpy(_pntr,copy._pntr,_length*
sizeof(T));
115 _capacity = other._capacity;
116 _length = other._length;
117 _alignm = other._alignm;
120 other._orig =
nullptr;
121 other._pntr =
nullptr;
133 if (_orig) free(_orig);
148 static std::shared_ptr<Aligned<T>>
alloc(
size_t size,
size_t alignment) {
149 std::shared_ptr<Aligned<T>> result = std::make_shared<Aligned<T>>();
150 return (result->reset(
size,alignment) ? result :
nullptr);
154 #pragma mark Array Methods
164 _capacity =
size*
sizeof(T)+alignment;
168 _orig = malloc(_capacity);
169 _pntr = (T*)std::align(_alignm,
size*
sizeof(T),_orig,_capacity);
177 std::memset(_pntr,0,_length*
sizeof(T));
190 #pragma mark Copy Behavior
199 _capacity = copy._capacity;
200 _length = copy._length;
201 _alignm = copy._alignm;
202 _orig = malloc(_capacity);
203 _pntr = (T*)std::align(_alignm,_length*
sizeof(T),_orig,_capacity);
204 std::memcpy(_pntr,copy._pntr,_length*
sizeof(T));
216 _capacity = other._capacity;
217 _length = other._length;
218 _alignm = other._alignm;
221 other._orig =
nullptr;
222 other._pntr =
nullptr;
227 #pragma mark Pointer Behavior
233 operator T*()
const {