aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/yt/memory/chunked_memory_allocator-inl.h
diff options
context:
space:
mode:
authorbabenko <babenko@yandex-team.com>2023-01-03 13:23:49 +0300
committerbabenko <babenko@yandex-team.com>2023-01-03 13:23:49 +0300
commit85dbae30a801094e01a9aa5e4ecb1be070420ed4 (patch)
tree1381aac9994baae96382a5231e8b1596d876320f /library/cpp/yt/memory/chunked_memory_allocator-inl.h
parent8ee4eaa91898ce3adcdf302ba33311fc9e627282 (diff)
downloadydb-85dbae30a801094e01a9aa5e4ecb1be070420ed4.tar.gz
More TChunkedMemoryPool, TChunkedMemoryAllocator, TChunkedMemoryPoolOutput to library
More TChunkedMemoryPool, TChunkedMemoryAllocator, TChunkedMemoryPoolOutput to library wip
Diffstat (limited to 'library/cpp/yt/memory/chunked_memory_allocator-inl.h')
-rw-r--r--library/cpp/yt/memory/chunked_memory_allocator-inl.h44
1 files changed, 44 insertions, 0 deletions
diff --git a/library/cpp/yt/memory/chunked_memory_allocator-inl.h b/library/cpp/yt/memory/chunked_memory_allocator-inl.h
new file mode 100644
index 0000000000..fe66060b2d
--- /dev/null
+++ b/library/cpp/yt/memory/chunked_memory_allocator-inl.h
@@ -0,0 +1,44 @@
+#ifndef CHUNKED_MEMORY_ALLOCATOR_INL_H_
+#error "Direct inclusion of this file is not allowed, include chunked_memory_allocator.h"
+// For the sake of sane code completion.
+#include "chunked_memory_allocator.h"
+#endif
+
+#include "serialize.h"
+
+#include <util/system/align.h>
+
+namespace NYT {
+
+////////////////////////////////////////////////////////////////////////////////
+
+inline TSharedMutableRef TChunkedMemoryAllocator::AllocateUnaligned(i64 size)
+{
+ // Fast path.
+ if (FreeZoneEnd_ >= FreeZoneBegin_ + size) {
+ FreeZoneEnd_ -= size;
+ return Chunk_.Slice(FreeZoneEnd_, FreeZoneEnd_ + size);
+ }
+
+ // Slow path.
+ return AllocateUnalignedSlow(size);
+}
+
+inline TSharedMutableRef TChunkedMemoryAllocator::AllocateAligned(i64 size, int align)
+{
+ // NB: This can lead to FreeZoneBegin_ >= FreeZoneEnd_ in which case the chunk is full.
+ FreeZoneBegin_ = AlignUp(FreeZoneBegin_, align);
+
+ // Fast path.
+ if (FreeZoneBegin_ + size <= FreeZoneEnd_) {
+ FreeZoneBegin_ += size;
+ return Chunk_.Slice(FreeZoneBegin_ - size, FreeZoneBegin_);
+ }
+
+ // Slow path.
+ return AllocateAlignedSlow(size, align);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
+} // namespace NYT