Files
ss/include/nw4r/lyt/lyt_layout.h
T
2023-12-24 11:35:03 -05:00

58 lines
1.1 KiB
C++

#ifndef NW4R_LYT_LAYOUT_H
#define NW4R_LYT_LAYOUT_H
#include "types_nw4r.h"
#include <new>
#include <rvl/MEM/mem_allocator.h>
namespace nw4r {
namespace lyt {
struct Layout {
// TO-DO: Class members
static void FreeMemory(void *p) {
MEMFreeToAllocator(mspAllocator, p);
}
static void *AllocMemory(size_t n) {
return MEMAllocFromAllocator(mspAllocator, n);
}
template <typename T>
static void DeleteArray(T *p, size_t n) {
for (size_t i = 0; i < n; i++) {
p[i].~T();
}
FreeMemory(p);
}
template <typename T>
static T *NewArray(size_t n) {
T *array = (T *)AllocMemory(n * sizeof(T));
for (size_t i = 0; i < n; i++) {
new (&array[i]) T();
}
return array;
}
template <typename T>
static void DeleteObj(T *t) {
t->~T();
FreeMemory(t);
}
template <typename T>
static T *NewObj() {
T *obj = (T *)AllocMemory(sizeof(T));
return new (obj) T();
}
static MEMAllocator *mspAllocator;
};
} // namespace lyt
} // namespace nw4r
#endif