proxy_allocator.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. uint32_t allocated_size(const void* /*ptr*/) { return SIZE_NOT_TRACKED; }
  25. /// @copydoc Allocator::total_allocated()
  26. uint32_t total_allocated() { return SIZE_NOT_TRACKED; }
  27. /// Returns the name of the proxy allocator
  28. const char* name() const;
  29. private:
  30. const char* _name;
  31. Allocator& _allocator;
  32. };
  33. } // namespace crown