General Purpose library for Freestanding C++ and POSIX systems
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 

43 linhas
962 B

#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;
};
}