#include "shared_data.h" #include "memory_tracker.h" #include #include namespace NActors { static constexpr char MemoryLabelSharedData[] = "Tablet/TSharedData/Buffers"; char* TSharedData::Allocate(size_t size) { char* data = nullptr; if (size > 0) { if (size >= MaxDataSize) { throw std::length_error("Allocate size overflow"); } auto allocSize = OverheadSize + size; char* raw = reinterpret_cast(y_allocate(allocSize)); auto* privateHeader = reinterpret_cast(raw); privateHeader->AllocSize = allocSize; NActors::NMemory::TLabel::Add(allocSize); auto* header = reinterpret_cast(raw + PrivateHeaderSize); header->RefCount = 1; header->Owner = nullptr; data = raw + OverheadSize; NSan::Poison(data, size); } return data; } void TSharedData::Deallocate(char* data) noexcept { if (data) { char* raw = data - OverheadSize; auto* privateHeader = reinterpret_cast(raw); NActors::NMemory::TLabel::Sub(privateHeader->AllocSize); auto* header = reinterpret_cast(raw + PrivateHeaderSize); Y_VERIFY_DEBUG(header->Owner == nullptr); y_deallocate(raw); } } }