General Purpose library for Freestanding C++ and POSIX systems
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
962 B

преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 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. }