allocator.h 955 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*
  2. * Copyright (c) 2012-2014 Daniele Bartolini and individual contributors.
  3. * License: https://github.com/taylor001/crown/blob/master/LICENSE
  4. */
  5. #pragma once
  6. #include "types.h"
  7. namespace crown
  8. {
  9. /// Base class for memory allocators.
  10. ///
  11. /// @ingroup Memory
  12. class Allocator
  13. {
  14. public:
  15. Allocator() {}
  16. virtual ~Allocator() {}
  17. /// Allocates @a size bytes of memory aligned to the specified
  18. /// @a align byte and returns a pointer to the first allocated byte.
  19. virtual void* allocate(size_t size, size_t align = DEFAULT_ALIGN) = 0;
  20. /// Deallocates a previously allocated block of memory pointed by @a data.
  21. virtual void deallocate(void* data) = 0;
  22. /// Returns the total number of bytes allocated.
  23. virtual size_t allocated_size() = 0;
  24. /// Default memory alignment in bytes.
  25. static const size_t DEFAULT_ALIGN = 4;
  26. private:
  27. // Disable copying
  28. Allocator(const Allocator&);
  29. Allocator& operator=(const Allocator&);
  30. };
  31. } // namespace crown