prime/include/rstl/rmemory_allocator.hpp

41 lines
931 B
C++
Raw Permalink Normal View History

#ifndef _RSTL_RMEMORY_ALLOCATOR
#define _RSTL_RMEMORY_ALLOCATOR
#include "types.h"
2022-07-18 22:42:58 +00:00
#include "Kyoto/Alloc/CMemory.hpp"
namespace rstl {
struct rmemory_allocator {
rmemory_allocator() {}
rmemory_allocator(const rmemory_allocator&) {}
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 {
out = reinterpret_cast< T* >(new uchar[size]);
2022-10-04 00:00:46 +00:00
}
}
// TODO: this fixes a regswap in vector::reserve
template < typename T >
static T* allocate2(int count) {
int size = count * sizeof(T);
if (size == 0) {
return nullptr;
} else {
return reinterpret_cast< T* >(new uchar[size]);
2022-10-04 00:00:46 +00:00
}
}
template < typename T >
static void deallocate(T* ptr) {
2022-10-01 06:19:09 +00:00
if (ptr != nullptr) {
delete[] reinterpret_cast< uchar* >(ptr);
2022-10-01 06:19:09 +00:00
}
}
};
} // namespace rstl
#endif // _RSTL_RMEMORY_ALLOCATOR