chunked_memory_allocator-inl.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #ifndef CHUNKED_MEMORY_ALLOCATOR_INL_H_
  2. #error "Direct inclusion of this file is not allowed, include chunked_memory_allocator.h"
  3. // For the sake of sane code completion.
  4. #include "chunked_memory_allocator.h"
  5. #endif
  6. #include "serialize.h"
  7. #include <util/system/align.h>
  8. namespace NYT {
  9. ////////////////////////////////////////////////////////////////////////////////
  10. inline TSharedMutableRef TChunkedMemoryAllocator::AllocateUnaligned(i64 size)
  11. {
  12. // Fast path.
  13. if (FreeZoneEnd_ >= FreeZoneBegin_ + size) {
  14. FreeZoneEnd_ -= size;
  15. return Chunk_.Slice(FreeZoneEnd_, FreeZoneEnd_ + size);
  16. }
  17. // Slow path.
  18. return AllocateUnalignedSlow(size);
  19. }
  20. inline TSharedMutableRef TChunkedMemoryAllocator::AllocateAligned(i64 size, int align)
  21. {
  22. // NB: This can lead to FreeZoneBegin_ >= FreeZoneEnd_ in which case the chunk is full.
  23. FreeZoneBegin_ = AlignUp(FreeZoneBegin_, align);
  24. // Fast path.
  25. if (FreeZoneBegin_ + size <= FreeZoneEnd_) {
  26. FreeZoneBegin_ += size;
  27. return Chunk_.Slice(FreeZoneBegin_ - size, FreeZoneBegin_);
  28. }
  29. // Slow path.
  30. return AllocateAlignedSlow(size, align);
  31. }
  32. ////////////////////////////////////////////////////////////////////////////////
  33. } // namespace NYT