2022-10-09 05:13:17 +00:00
|
|
|
#ifndef _RSTL_RMEMORY_ALLOCATOR
|
|
|
|
#define _RSTL_RMEMORY_ALLOCATOR
|
2022-04-10 00:17:06 +00:00
|
|
|
|
|
|
|
#include "types.h"
|
|
|
|
|
2022-07-18 22:42:58 +00:00
|
|
|
#include "Kyoto/Alloc/CMemory.hpp"
|
2022-04-10 00:17:06 +00:00
|
|
|
|
|
|
|
namespace rstl {
|
|
|
|
struct rmemory_allocator {
|
2022-10-08 08:44:58 +00:00
|
|
|
rmemory_allocator() {}
|
|
|
|
rmemory_allocator(const rmemory_allocator&) {}
|
2023-10-12 21:52:29 +00:00
|
|
|
|
2022-04-10 00:17:06 +00:00
|
|
|
template < typename T >
|
2022-10-04 00:00:46 +00:00
|
|
|
static void allocate(T*& out, int count) {
|
|
|
|
int size = count * sizeof(T);
|
|
|
|
if (size == 0) {
|
|
|
|
out = nullptr;
|
|
|
|
} else {
|
2023-10-12 12:14:12 +00:00
|
|
|
out = reinterpret_cast< T* >(rs_new uchar[size]);
|
2022-10-04 00:00:46 +00:00
|
|
|
}
|
|
|
|
}
|
2023-10-12 21:52:29 +00:00
|
|
|
|
2022-04-10 00:17:06 +00:00
|
|
|
template < typename T >
|
|
|
|
static void deallocate(T* ptr) {
|
2022-10-01 06:19:09 +00:00
|
|
|
if (ptr != nullptr) {
|
2022-10-09 05:37:23 +00:00
|
|
|
delete[] reinterpret_cast< uchar* >(ptr);
|
2022-10-01 06:19:09 +00:00
|
|
|
}
|
2022-04-10 00:17:06 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
} // namespace rstl
|
|
|
|
|
2022-10-09 05:13:17 +00:00
|
|
|
#endif // _RSTL_RMEMORY_ALLOCATOR
|