diff options
| author | Jonathan Bradley <jcb@pikum.xyz> | 2024-11-14 14:46:23 -0500 |
|---|---|---|
| committer | Jonathan Bradley <jcb@pikum.xyz> | 2024-11-14 14:46:23 -0500 |
| commit | b2548ba4ce295fcd94a50123fb543fac2ef2bc33 (patch) | |
| tree | 444a32abb4a094c4fa2f7bc9a95aa86963ad4110 /src/memory-allocator.hpp | |
| parent | b1d926361b9d613ad712ad161f9a8b7ccab4551d (diff) | |
add pk.h and major pkmem refactor
Completely replaces the memory module with pkmem
pkmem is a newer implementation of the same
bucket memory structure.
Also includes replacing pkstr.h with pk.h's pkstr
Diffstat (limited to 'src/memory-allocator.hpp')
| -rw-r--r-- | src/memory-allocator.hpp | 54 |
1 files changed, 0 insertions, 54 deletions
diff --git a/src/memory-allocator.hpp b/src/memory-allocator.hpp deleted file mode 100644 index c14304a..0000000 --- a/src/memory-allocator.hpp +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef PKE_MEMORY_ALLOCATOR_HPP -#define PKE_MEMORY_ALLOCATOR_HPP - -#include "memory.hpp" - -template <typename T, std::size_t SZ = DEFAULT_BUCKET_SIZE> class PkeTransAllocator { -public: - typedef T value_type; - MemBucket *transientBucket = nullptr; - - PkeTransAllocator() : transientBucket(Pke_BeginTransientBucket(SZ)) { - } - ~PkeTransAllocator() { - Pke_EndTransientBucket(this->transientBucket); - } - - template <class U> struct rebind {typedef PkeTransAllocator<U, SZ> other;}; - template <typename U> explicit PkeTransAllocator(const PkeTransAllocator<U> &other) { - (void)other; - } - - T *allocate(std::size_t n) { - auto *ptr = reinterpret_cast<T *>(Pke_New(sizeof(T) * n, this->transientBucket)); - if (ptr) return ptr; - throw "Pke-Allocator Failed to allocate"; - } - - void deallocate(const T *ptr, std::size_t n) { - Pke_Delete(ptr, sizeof(T) * n, this->transientBucket); - } -}; - -template <typename T> class PkeAllocator { -public: - typedef T value_type; - - PkeAllocator() = default; - - template <typename U> explicit PkeAllocator(const PkeAllocator<U> &other) { - (void)other; - } - - T *allocate(std::size_t n) { - auto *ptr = Pke_New<T>(n); - if (ptr) return ptr; - throw "Pke-Allocator Failed to allocate"; - } - - void deallocate(const T *ptr, std::size_t n) { - Pke_Delete<T>(ptr, n); - } -}; - -#endif /* PKE_MEMORY_ALLOCATOR_HPP */ |
