alloc.h 589 B

123456789101112131415161718192021222324252627
  1. #pragma once
  2. #include <memory>
  3. template <class Allocator, class T>
  4. using TReboundAllocator = typename std::allocator_traits<Allocator>::template rebind_alloc<T>;
  5. class IAllocator {
  6. public:
  7. struct TBlock {
  8. void* Data;
  9. size_t Len;
  10. };
  11. virtual ~IAllocator() = default;
  12. virtual TBlock Allocate(size_t len) = 0;
  13. virtual void Release(const TBlock& block) = 0;
  14. };
  15. class TDefaultAllocator: public IAllocator {
  16. public:
  17. TBlock Allocate(size_t len) override;
  18. void Release(const TBlock& block) override;
  19. static IAllocator* Instance() noexcept;
  20. };