summaryrefslogtreecommitdiffstats
path: root/library/cpp/yt/memory/ref.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'library/cpp/yt/memory/ref.cpp')
-rw-r--r--library/cpp/yt/memory/ref.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/library/cpp/yt/memory/ref.cpp b/library/cpp/yt/memory/ref.cpp
index fc153bb02e3..5a6ca1e3373 100644
--- a/library/cpp/yt/memory/ref.cpp
+++ b/library/cpp/yt/memory/ref.cpp
@@ -171,6 +171,44 @@ public:
////////////////////////////////////////////////////////////////////////////////
+class TCustomAlignedAllocationHolder
+ : public TAllocationHolderBase<TCustomAlignedAllocationHolder>
+{
+public:
+ TCustomAlignedAllocationHolder(
+ size_t size,
+ size_t alignment,
+ TSharedMutableRefAllocateOptions options,
+ TRefCountedTypeCookie cookie)
+ : Begin_(static_cast<char*>(::aligned_malloc(size, alignment)))
+ , Alignment_(alignment)
+ {
+ Initialize(size, options, cookie);
+ }
+
+ ~TCustomAlignedAllocationHolder()
+ {
+ ::free(Begin_);
+ }
+
+ char* GetBegin()
+ {
+ return Begin_;
+ }
+
+ // TSharedRangeHolder overrides.
+ std::optional<size_t> GetTotalByteSize() const override
+ {
+ return AlignUp(Size_, Alignment_);
+ }
+
+private:
+ char* const Begin_;
+ size_t Alignment_;
+};
+
+////////////////////////////////////////////////////////////////////////////////
+
class TPageAlignedAllocationHolder
: public TAllocationHolderBase<TPageAlignedAllocationHolder>
{
@@ -311,6 +349,13 @@ TSharedMutableRef TSharedMutableRef::AllocatePageAligned(size_t size, TSharedMut
return TSharedMutableRef(ref, std::move(holder));
}
+TSharedMutableRef TSharedMutableRef::AllocateAligned(size_t size, size_t alignment, TSharedMutableRefAllocateOptions options, TRefCountedTypeCookie tagCookie)
+{
+ auto holder = New<TCustomAlignedAllocationHolder>(size, alignment, options, tagCookie);
+ auto ref = holder->GetRef();
+ return TSharedMutableRef(ref, std::move(holder));
+}
+
TSharedMutableRef TSharedMutableRef::FromBlob(TBlob&& blob)
{
auto ref = TMutableRef::FromBlob(blob);