General Purpose library for Freestanding C++ and POSIX systems
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

42 строки
962 B

4 лет назад
4 лет назад
4 лет назад
4 лет назад
  1. #pragma once
  2. #include <stddef.h>
  3. namespace gp {
  4. /**
  5. * @brief The base for all polymorphic allocators
  6. */
  7. struct allocator{
  8. /**
  9. * @brief Allocates memory
  10. *
  11. * @param sz the amount of bytes to allocate
  12. *
  13. * @return the allocated memory as a pointer on success
  14. * @return nullptr if it failed allocating
  15. */
  16. virtual void* allocate(size_t) = 0;
  17. /**
  18. * @brief Deallocates memory
  19. *
  20. * @param ptr the memory to deallocate
  21. *
  22. * @return true if the memory was successfully deallocated
  23. * @return false if the memory was not deallocated
  24. */
  25. virtual bool deallocate(void*) = 0;
  26. /**
  27. * @brief Tries to reallocate memory
  28. *
  29. * @param ptr The memory to reallocate
  30. * @param sz The new size we want to give the memory
  31. *
  32. * @return true if reallocation was successful
  33. * @return false if the reallocation failed
  34. */
  35. virtual bool try_reallocate(void*, size_t) = 0;
  36. virtual ~allocator() = default;
  37. };
  38. }