|
|
- #pragma once
-
- #include <stddef.h>
-
- namespace gp {
- /**
- * @brief The base for all polymorphic allocators
- */
- struct allocator{
- /**
- * @brief Allocates memory
- *
- * @param sz the amount of bytes to allocate
- *
- * @return the allocated memory as a pointer on success
- * @return nullptr if it failed allocating
- */
- virtual void* allocate(size_t) = 0;
-
- /**
- * @brief Deallocates memory
- *
- * @param ptr the memory to deallocate
- *
- * @return true if the memory was successfully deallocated
- * @return false if the memory was not deallocated
- */
- virtual bool deallocate(void*) = 0;
-
- /**
- * @brief Tries to reallocate memory
- *
- * @param ptr The memory to reallocate
- * @param sz The new size we want to give the memory
- *
- * @return true if reallocation was successful
- * @return false if the reallocation failed
- */
- virtual bool try_reallocate(void*, size_t) = 0;
-
- virtual ~allocator() = default;
- };
- }
|