General Purpose library for Freestanding C++ and POSIX systems
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 

43 righe
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;
};
}