35 namespace perception {
44 mem =
new (std::nothrow) T[memory_size];
53 if (mem !=
nullptr && *mem !=
nullptr) {
64 mem =
new (std::nothrow) T[m * n];
68 head =
new (std::nothrow) T *[m];
69 if (head ==
nullptr) {
73 IMakeReference<T>(mem, head, m, n);
80 if (A !=
nullptr && *A !=
nullptr) {
89 inline T ***
IAlloc3(
int l,
int m,
int n) {
93 mem =
new (std::nothrow) T[l * m * n];
97 head =
new (std::nothrow) T **[l];
98 if (head ==
nullptr) {
102 for (i = 0; i < l; i++) {
103 head[i] =
new (std::nothrow) T *[m];
104 if (head[i] ==
nullptr) {
105 for (j = 0; j < i; j++) {
118 template <
typename T>
120 if (memory_size <= 0) {
121 return (reinterpret_cast<T *>(NULL));
123 int actual_alignment_power = (alignment_power >= 0) ? alignment_power : 0;
124 std::size_t memory_size_in_byte =
125 static_cast<size_t>(memory_size) *
sizeof(T);
126 std::size_t mask =
static_cast<size_t>((1 << actual_alignment_power) - 1);
127 std::size_t pointer_size_in_byte =
sizeof(
char *);
128 char *mem_begin =
new (
129 std::nothrow)
char[memory_size_in_byte + mask + pointer_size_in_byte];
131 return (reinterpret_cast<T *>(NULL));
133 char *mem_actual =
reinterpret_cast<char *
>(
134 (
reinterpret_cast<size_t>(mem_begin) + mask + pointer_size_in_byte) &
136 (
reinterpret_cast<char **
>(mem_actual))[-1] = mem_begin;
137 return (reinterpret_cast<T *>(mem_actual));
141 template <
typename T>
143 if (mem !=
nullptr && *mem !=
nullptr) {
144 delete[](
reinterpret_cast<char **
>(*mem))[-1];
149 template <
typename T>
151 std::size_t mask =
static_cast<size_t>((1 << alignment_power) - 1);
152 if (((
size_t)mem) & mask) {
int IVerifyAlignment(const T *mem, int alignment_power=4)
Definition: i_alloc.h:150
void IMakeReference(T *a, T **p, int m, int n)
Definition: i_basic.h:357
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
T * IAllocAligned(int memory_size, int alignment_power=4)
Definition: i_alloc.h:119
const size_t A
Definition: util.h:160
T * IAlloc(int memory_size)
Definition: i_alloc.h:39
T *** IAlloc3(int l, int m, int n)
Definition: i_alloc.h:89
T ** IAlloc2(int m, int n)
Definition: i_alloc.h:61
void IFree2(T ***A)
Definition: i_alloc.h:79
void IFree(T **mem)
Definition: i_alloc.h:52
void IFreeAligned(T **mem)
Definition: i_alloc.h:142