proxy_allocator.h 1000 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. * Copyright (c) 2012-2018 Daniele Bartolini and individual contributors.
  3. * License: https://github.com/dbartolini/crown/blob/master/LICENSE
  4. */
  5. #pragma once
  6. #include "core/memory/allocator.h"
  7. namespace crown
  8. {
  9. /// Offers the facility to tag allocators by a string identifier.
  10. ///
  11. /// @ingroup Memory
  12. struct ProxyAllocator : public Allocator
  13. {
  14. Allocator& _allocator;
  15. const char* _name;
  16. /// Tag all allocations made with @a allocator by the given @a name
  17. ProxyAllocator(Allocator& allocator, const char* name);
  18. /// @copydoc Allocator::allocate()
  19. void* allocate(u32 size, u32 align = Allocator::DEFAULT_ALIGN);
  20. /// @copydoc Allocator::deallocate()
  21. void deallocate(void* data);
  22. /// @copydoc Allocator::allocated_size()
  23. u32 allocated_size(const void* /*ptr*/) { return SIZE_NOT_TRACKED; }
  24. /// @copydoc Allocator::total_allocated()
  25. u32 total_allocated() { return SIZE_NOT_TRACKED; }
  26. /// Returns the name of the proxy allocator
  27. const char* name() const;
  28. };
  29. } // namespace crown