General Purpose library for Freestanding C++ and POSIX systems
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

42 rindas
962 B

pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
  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. }