proxy_allocator.h 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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 "allocator.h"
  7. namespace crown
  8. {
  9. /// Offers the facility to tag allocators by a string identifier.
  10. /// Proxy allocator is appended to a global linked list when instantiated
  11. /// so that it is possible to later visit that list for debugging purposes.
  12. ///
  13. /// @ingroup Memory
  14. class ProxyAllocator : public Allocator
  15. {
  16. public:
  17. /// Tag all allocations made with @a allocator by the given @a name
  18. ProxyAllocator(const char* name, Allocator& allocator);
  19. /// @copydoc Allocator::allocate()
  20. void* allocate(size_t size, size_t align = Allocator::DEFAULT_ALIGN);
  21. /// @copydoc Allocator::deallocate()
  22. void deallocate(void* data);
  23. /// @copydoc Allocator::allocated_size()
  24. size_t allocated_size();
  25. /// Returns the name of the proxy allocator
  26. const char* name() const;
  27. private:
  28. Allocator& _allocator;
  29. const char* _name;
  30. size_t _total_allocated;
  31. };
  32. } // namespace crown