proxy_allocator.cpp 771 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*
  2. * Copyright (c) 2012-2014 Daniele Bartolini and individual contributors.
  3. * License: https://github.com/taylor001/crown/blob/master/LICENSE
  4. */
  5. #include "proxy_allocator.h"
  6. #include "assert.h"
  7. namespace crown
  8. {
  9. ProxyAllocator::ProxyAllocator(const char* name, Allocator& allocator)
  10. : _allocator(allocator)
  11. , _name(name)
  12. , _total_allocated(0)
  13. {
  14. CE_ASSERT(name != NULL, "Name must be != NULL");
  15. }
  16. void* ProxyAllocator::allocate(size_t size, size_t align)
  17. {
  18. _total_allocated += size;
  19. return _allocator.allocate(size, align);
  20. }
  21. void ProxyAllocator::deallocate(void* data)
  22. {
  23. _allocator.deallocate(data);
  24. }
  25. size_t ProxyAllocator::allocated_size()
  26. {
  27. return _total_allocated;
  28. }
  29. const char* ProxyAllocator::name() const
  30. {
  31. return _name;
  32. }
  33. } // namespace crown