aboutsummaryrefslogtreecommitdiffstats
path: root/util/memory
diff options
context:
space:
mode:
authorAlexander Fokin <apfokin@gmail.com>2022-02-10 16:45:38 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:45:38 +0300
commit863a59a65247c24db7cb06789bc5cf79d04da32f (patch)
tree139dc000c8cd4a40f5659e421b7c75135d080307 /util/memory
parentf64e95a9eb9ab03240599eb9581c5a9102426a96 (diff)
downloadydb-863a59a65247c24db7cb06789bc5cf79d04da32f.tar.gz
Restoring authorship annotation for Alexander Fokin <apfokin@gmail.com>. Commit 1 of 2.
Diffstat (limited to 'util/memory')
-rw-r--r--util/memory/blob.cpp84
-rw-r--r--util/memory/blob.h50
-rw-r--r--util/memory/blob_ut.cpp10
-rw-r--r--util/memory/pool.h108
-rw-r--r--util/memory/pool_ut.cpp150
-rw-r--r--util/memory/segmented_string_pool.h4
6 files changed, 203 insertions, 203 deletions
diff --git a/util/memory/blob.cpp b/util/memory/blob.cpp
index 91da5cadca..f613639d2a 100644
--- a/util/memory/blob.cpp
+++ b/util/memory/blob.cpp
@@ -3,7 +3,7 @@
#include <util/system/yassert.h>
#include <util/system/filemap.h>
-#include <util/system/mlock.h>
+#include <util/system/mlock.h>
#include <util/stream/buffer.h>
#include <util/generic/ptr.h>
#include <util/generic/string.h>
@@ -105,9 +105,9 @@ class TMappedBlobBase: public TBlob::TBase, public TRefCounted<TMappedBlobBase<T
using TRefBase = TRefCounted<TMappedBlobBase<TCounter>, TCounter>;
public:
- inline TMappedBlobBase(const TMemoryMap& map, ui64 offset, size_t len, EMappingMode mode)
+ inline TMappedBlobBase(const TMemoryMap& map, ui64 offset, size_t len, EMappingMode mode)
: Map_(map)
- , Mode_(mode)
+ , Mode_(mode)
{
Y_ENSURE(Map_.IsOpen(), TStringBuf("memory map not open"));
@@ -116,17 +116,17 @@ public:
if (len && !Map_.Ptr()) { // Ptr is 0 for blob of size 0
ythrow yexception() << "can not map(" << offset << ", " << len << ")";
}
-
+
if (Mode_ == EMappingMode::Locked) {
- LockMemory(Data(), Length());
+ LockMemory(Data(), Length());
}
}
~TMappedBlobBase() override {
if (Mode_ == EMappingMode::Locked && Length()) {
- UnlockMemory(Data(), Length());
+ UnlockMemory(Data(), Length());
}
- }
+ }
void Ref() noexcept override {
TRefBase::Ref();
@@ -146,7 +146,7 @@ public:
private:
TFileMap Map_;
- EMappingMode Mode_;
+ EMappingMode Mode_;
};
TBlob TBlob::SubBlob(size_t len) const {
@@ -197,27 +197,27 @@ TBlob TBlob::NoCopy(const void* data, size_t length) {
}
template <class TCounter>
-static inline TBlob ConstructFromMap(const TMemoryMap& map, ui64 offset, size_t length, EMappingMode mode) {
+static inline TBlob ConstructFromMap(const TMemoryMap& map, ui64 offset, size_t length, EMappingMode mode) {
using TBase = TMappedBlobBase<TCounter>;
- THolder<TBase> base(new TBase(map, offset, length, mode));
+ THolder<TBase> base(new TBase(map, offset, length, mode));
TBlob ret(base->Data(), base->Length(), base.Get());
Y_UNUSED(base.Release());
return ret;
}
-template <class TCounter, class T>
-static inline TBlob ConstructAsMap(const T& t, EMappingMode mode) {
+template <class TCounter, class T>
+static inline TBlob ConstructAsMap(const T& t, EMappingMode mode) {
TMemoryMap::EOpenMode openMode = (mode == EMappingMode::Precharged) ? (TMemoryMap::oRdOnly | TMemoryMap::oPrecharge) : TMemoryMap::oRdOnly;
- TMemoryMap map(t, openMode);
+ TMemoryMap map(t, openMode);
const ui64 toMap = map.Length();
if (toMap > Max<size_t>()) {
ythrow yexception() << "can not map whole file(length = " << toMap << ")";
}
- return ConstructFromMap<TCounter>(map, 0, static_cast<size_t>(toMap), mode);
+ return ConstructFromMap<TCounter>(map, 0, static_cast<size_t>(toMap), mode);
}
TBlob TBlob::FromFileSingleThreaded(const TString& path, EMappingMode mode) {
@@ -236,54 +236,54 @@ TBlob TBlob::FromFile(const TFile& file, EMappingMode mode) {
return ConstructAsMap<TAtomicCounter>(file, mode);
}
-TBlob TBlob::FromFileSingleThreaded(const TString& path) {
+TBlob TBlob::FromFileSingleThreaded(const TString& path) {
return ConstructAsMap<TSimpleCounter>(path, EMappingMode::Standard);
}
-TBlob TBlob::FromFile(const TString& path) {
+TBlob TBlob::FromFile(const TString& path) {
return ConstructAsMap<TAtomicCounter>(path, EMappingMode::Standard);
}
-TBlob TBlob::FromFileSingleThreaded(const TFile& file) {
+TBlob TBlob::FromFileSingleThreaded(const TFile& file) {
return ConstructAsMap<TSimpleCounter>(file, EMappingMode::Standard);
}
-TBlob TBlob::FromFile(const TFile& file) {
+TBlob TBlob::FromFile(const TFile& file) {
return ConstructAsMap<TAtomicCounter>(file, EMappingMode::Standard);
}
-TBlob TBlob::PrechargedFromFileSingleThreaded(const TString& path) {
+TBlob TBlob::PrechargedFromFileSingleThreaded(const TString& path) {
return ConstructAsMap<TSimpleCounter>(path, EMappingMode::Precharged);
-}
-
-TBlob TBlob::PrechargedFromFile(const TString& path) {
+}
+
+TBlob TBlob::PrechargedFromFile(const TString& path) {
return ConstructAsMap<TAtomicCounter>(path, EMappingMode::Precharged);
-}
-
-TBlob TBlob::PrechargedFromFileSingleThreaded(const TFile& file) {
+}
+
+TBlob TBlob::PrechargedFromFileSingleThreaded(const TFile& file) {
return ConstructAsMap<TSimpleCounter>(file, EMappingMode::Precharged);
-}
-
-TBlob TBlob::PrechargedFromFile(const TFile& file) {
+}
+
+TBlob TBlob::PrechargedFromFile(const TFile& file) {
return ConstructAsMap<TAtomicCounter>(file, EMappingMode::Precharged);
-}
-
-TBlob TBlob::LockedFromFileSingleThreaded(const TString& path) {
+}
+
+TBlob TBlob::LockedFromFileSingleThreaded(const TString& path) {
return ConstructAsMap<TSimpleCounter>(path, EMappingMode::Locked);
-}
-
-TBlob TBlob::LockedFromFile(const TString& path) {
+}
+
+TBlob TBlob::LockedFromFile(const TString& path) {
return ConstructAsMap<TAtomicCounter>(path, EMappingMode::Locked);
-}
-
-TBlob TBlob::LockedFromFileSingleThreaded(const TFile& file) {
+}
+
+TBlob TBlob::LockedFromFileSingleThreaded(const TFile& file) {
return ConstructAsMap<TSimpleCounter>(file, EMappingMode::Locked);
-}
-
-TBlob TBlob::LockedFromFile(const TFile& file) {
+}
+
+TBlob TBlob::LockedFromFile(const TFile& file) {
return ConstructAsMap<TAtomicCounter>(file, EMappingMode::Locked);
-}
-
+}
+
TBlob TBlob::LockedFromMemoryMapSingleThreaded(const TMemoryMap& map, ui64 offset, size_t length) {
return ConstructFromMap<TSimpleCounter>(map, offset, length, EMappingMode::Locked);
}
diff --git a/util/memory/blob.h b/util/memory/blob.h
index 20c02a68df..f0de873ea1 100644
--- a/util/memory/blob.h
+++ b/util/memory/blob.h
@@ -60,9 +60,9 @@ public:
using const_pointer = const value_type*;
using const_iterator = const_pointer;
- /**
+ /**
* Constructs a null blob (data array points to nullptr).
- */
+ */
TBlob() noexcept
: S_(nullptr, 0, nullptr)
{
@@ -213,43 +213,43 @@ public:
static TBlob FromFile(const TFile& file, EMappingMode);
/// Creates a blob with a single-threaded (non atomic) refcounter. It maps the file on the path as data.
- static TBlob FromFileSingleThreaded(const TString& path);
+ static TBlob FromFileSingleThreaded(const TString& path);
/// Creates a blob with a multi-threaded (atomic) refcounter. It maps the file on the path as data.
- static TBlob FromFile(const TString& path);
+ static TBlob FromFile(const TString& path);
/// Creates a blob with a single-threaded (non atomic) refcounter. It maps the file on the path as data.
- static TBlob FromFileSingleThreaded(const TFile& file);
+ static TBlob FromFileSingleThreaded(const TFile& file);
/// Creates a blob with a multi-threaded (atomic) refcounter. It maps the file on the path as data.
- static TBlob FromFile(const TFile& file);
-
- // TODO: drop Precharged* functions.
+ static TBlob FromFile(const TFile& file);
+ // TODO: drop Precharged* functions.
+
/// Creates a precharged blob with a single-threaded (non atomic) refcounter. It maps the file on the path as data.
- static TBlob PrechargedFromFileSingleThreaded(const TString& path);
+ static TBlob PrechargedFromFileSingleThreaded(const TString& path);
/// Creates a precharged blob with a multi-threaded (atomic) refcounter. It maps the file on the path as data.
- static TBlob PrechargedFromFile(const TString& path);
+ static TBlob PrechargedFromFile(const TString& path);
/// Creates a precharged blob with a single-threaded (non atomic) refcounter. It maps the file content as data.
- static TBlob PrechargedFromFileSingleThreaded(const TFile& file);
+ static TBlob PrechargedFromFileSingleThreaded(const TFile& file);
/// Creates a precharged blob with a multi-threaded (atomic) refcounter. It maps the file content as data.
- static TBlob PrechargedFromFile(const TFile& file);
-
- /// Creates a locked blob with a single-threaded (non atomic) refcounter. It maps the file on the path as data.
- static TBlob LockedFromFileSingleThreaded(const TString& path);
-
- /// Creates a locked blob with a multi-threaded (atomic) refcounter. It maps the file on the path as data.
- static TBlob LockedFromFile(const TString& path);
-
- /// Creates a locked blob with a single-threaded (non atomic) refcounter. It maps the file content as data.
- static TBlob LockedFromFileSingleThreaded(const TFile& file);
-
- /// Creates a locked blob with a multi-threaded (atomic) refcounter. It maps the file content as data.
- static TBlob LockedFromFile(const TFile& file);
-
+ static TBlob PrechargedFromFile(const TFile& file);
+
+ /// Creates a locked blob with a single-threaded (non atomic) refcounter. It maps the file on the path as data.
+ static TBlob LockedFromFileSingleThreaded(const TString& path);
+
+ /// Creates a locked blob with a multi-threaded (atomic) refcounter. It maps the file on the path as data.
+ static TBlob LockedFromFile(const TString& path);
+
+ /// Creates a locked blob with a single-threaded (non atomic) refcounter. It maps the file content as data.
+ static TBlob LockedFromFileSingleThreaded(const TFile& file);
+
+ /// Creates a locked blob with a multi-threaded (atomic) refcounter. It maps the file content as data.
+ static TBlob LockedFromFile(const TFile& file);
+
/// Creates a locked blob with a single-threaded (non atomic) refcounter from the mapped memory.
static TBlob LockedFromMemoryMapSingleThreaded(const TMemoryMap& map, ui64 offset, size_t length);
diff --git a/util/memory/blob_ut.cpp b/util/memory/blob_ut.cpp
index 023f9a0487..cef9bfc38b 100644
--- a/util/memory/blob_ut.cpp
+++ b/util/memory/blob_ut.cpp
@@ -5,7 +5,7 @@
#include <util/system/tempfile.h>
#include <util/folder/path.h>
#include <util/stream/output.h>
-#include <util/stream/file.h>
+#include <util/stream/file.h>
#include <util/generic/buffer.h>
#include <util/generic/array_ref.h>
@@ -53,19 +53,19 @@ Y_UNIT_TEST_SUITE(TBlobTest) {
UNIT_ASSERT_EQUAL(buf.Size(), 0u);
UNIT_ASSERT_EQUAL(b.Size(), sz);
}
-
+
Y_UNIT_TEST(TestFromFile) {
TString path = "testfile";
-
+
TOFStream stream(path);
stream.Write("1234", 4);
stream.Finish();
-
+
auto testMode = [](TBlob blob) {
UNIT_ASSERT_EQUAL(blob.Size(), 4);
UNIT_ASSERT_EQUAL(TStringBuf(static_cast<const char*>(blob.Data()), 4), "1234");
};
-
+
testMode(TBlob::FromFile(path));
testMode(TBlob::PrechargedFromFile(path));
testMode(TBlob::LockedFromFile(path));
diff --git a/util/memory/pool.h b/util/memory/pool.h
index 13c8b6b9ed..37c64e9731 100644
--- a/util/memory/pool.h
+++ b/util/memory/pool.h
@@ -14,15 +14,15 @@
#include <string>
#include <utility>
-/**
- * Memory pool implements a memory allocation scheme that is very fast, but
- * limited in its usage.
- *
- * A common use case is when you want to allocate a bunch of small objects, and
- * then release them all at some point of your program. Using memory pool, you
- * can just drop them off into oblivion without calling any destructors,
- * provided that all associated memory was allocated on the pool.
- */
+/**
+ * Memory pool implements a memory allocation scheme that is very fast, but
+ * limited in its usage.
+ *
+ * A common use case is when you want to allocate a bunch of small objects, and
+ * then release them all at some point of your program. Using memory pool, you
+ * can just drop them off into oblivion without calling any destructors,
+ * provided that all associated memory was allocated on the pool.
+ */
class TMemoryPool {
private:
using TBlock = IAllocator::TBlock;
@@ -50,16 +50,16 @@ private:
}
inline void* Allocate(size_t len, size_t align) noexcept {
- size_t pad = AlignUp(Cur_, align) - Cur_;
-
- void* ret = Allocate(pad + len);
- if (ret) {
- return static_cast<char*>(ret) + pad;
- }
-
+ size_t pad = AlignUp(Cur_, align) - Cur_;
+
+ void* ret = Allocate(pad + len);
+ if (ret) {
+ return static_cast<char*>(ret) + pad;
+ }
+
return nullptr;
- }
-
+ }
+
inline size_t BlockLength() const noexcept {
return (Cur_ + Left_) - (char*)this;
}
@@ -151,30 +151,30 @@ public:
return RawAllocate(AlignUp<size_t>(len, PLATFORM_DATA_ALIGN));
}
- inline void* Allocate(size_t len, size_t align) {
- return RawAllocate(AlignUp<size_t>(len, PLATFORM_DATA_ALIGN), align);
- }
-
+ inline void* Allocate(size_t len, size_t align) {
+ return RawAllocate(AlignUp<size_t>(len, PLATFORM_DATA_ALIGN), align);
+ }
+
template <typename T>
inline T* Allocate() {
return (T*)this->Allocate(sizeof(T), alignof(T));
}
template <typename T>
- inline T* Allocate(size_t align) {
+ inline T* Allocate(size_t align) {
return (T*)this->Allocate(sizeof(T), Max(align, alignof(T)));
- }
-
- template <typename T>
+ }
+
+ template <typename T>
inline T* AllocateArray(size_t count) {
return (T*)this->Allocate(sizeof(T) * count, alignof(T));
}
- template <typename T>
- inline T* AllocateArray(size_t count, size_t align) {
+ template <typename T>
+ inline T* AllocateArray(size_t count, size_t align) {
return (T*)this->Allocate(sizeof(T) * count, Max(align, alignof(T)));
- }
-
+ }
+
template <typename T>
inline T* AllocateZeroArray(size_t count) {
T* ptr = AllocateArray<T>(count);
@@ -219,17 +219,17 @@ public:
}
template <typename TChar>
- inline TBasicStringBuf<TChar> AppendString(const TBasicStringBuf<TChar>& buf) {
- return TBasicStringBuf<TChar>(Append(buf.data(), buf.size()), buf.size());
+ inline TBasicStringBuf<TChar> AppendString(const TBasicStringBuf<TChar>& buf) {
+ return TBasicStringBuf<TChar>(Append(buf.data(), buf.size()), buf.size());
}
template <typename TChar>
- inline TBasicStringBuf<TChar> AppendCString(const TBasicStringBuf<TChar>& buf) {
+ inline TBasicStringBuf<TChar> AppendCString(const TBasicStringBuf<TChar>& buf) {
TChar* ret = static_cast<TChar*>(Allocate((buf.size() + 1) * sizeof(TChar)));
std::char_traits<TChar>::copy(ret, buf.data(), buf.size());
*(ret + buf.size()) = 0;
- return TBasicStringBuf<TChar>(ret, buf.size());
+ return TBasicStringBuf<TChar>(ret, buf.size());
}
inline size_t Available() const noexcept {
@@ -276,19 +276,19 @@ protected:
return Current_->Allocate(len);
}
- inline void* RawAllocate(size_t len, size_t align) {
+ inline void* RawAllocate(size_t len, size_t align) {
Y_ASSERT(align > 0);
- void* ret = Current_->Allocate(len, align);
-
- if (ret) {
- return ret;
- }
-
+ void* ret = Current_->Allocate(len, align);
+
+ if (ret) {
+ return ret;
+ }
+
AddChunk(len + align - 1);
-
- return Current_->Allocate(len, align);
- }
-
+
+ return Current_->Allocate(len, align);
+ }
+
private:
void AddChunk(size_t hint);
void DoClear(bool keepfirst) noexcept;
@@ -373,7 +373,7 @@ public:
}
inline T* allocate(size_t n) {
- return (T*)Pool_->Allocate(n * sizeof(T), alignof(T));
+ return (T*)Pool_->Allocate(n * sizeof(T), alignof(T));
}
inline void deallocate(pointer /*p*/, size_t /*n*/) {
@@ -402,14 +402,14 @@ public:
return Pool_;
}
- inline friend bool operator==(const TPoolAllocBase& l, const TPoolAllocBase& r) {
- return l.Pool_ == r.Pool_;
- }
-
- inline friend bool operator!=(const TPoolAllocBase& l, const TPoolAllocBase& r) {
- return !(l == r);
- }
-
+ inline friend bool operator==(const TPoolAllocBase& l, const TPoolAllocBase& r) {
+ return l.Pool_ == r.Pool_;
+ }
+
+ inline friend bool operator!=(const TPoolAllocBase& l, const TPoolAllocBase& r) {
+ return !(l == r);
+ }
+
private:
TPool* Pool_;
};
diff --git a/util/memory/pool_ut.cpp b/util/memory/pool_ut.cpp
index 1158a8ca42..58bb627b9a 100644
--- a/util/memory/pool_ut.cpp
+++ b/util/memory/pool_ut.cpp
@@ -4,51 +4,51 @@
#include <util/stream/output.h>
-class TCheckedAllocator: public TDefaultAllocator {
-public:
- inline TCheckedAllocator()
- : Alloced_(0)
- , Released_(0)
- , Allocs_(0)
+class TCheckedAllocator: public TDefaultAllocator {
+public:
+ inline TCheckedAllocator()
+ : Alloced_(0)
+ , Released_(0)
+ , Allocs_(0)
, Frees_(0)
{
- }
+ }
TBlock Allocate(size_t len) override {
- Check();
+ Check();
- Alloced_ += len;
- ++Allocs_;
+ Alloced_ += len;
+ ++Allocs_;
- return TDefaultAllocator::Allocate(len);
- }
+ return TDefaultAllocator::Allocate(len);
+ }
void Release(const TBlock& block) override {
- Released_ += block.Len;
- ++Frees_;
+ Released_ += block.Len;
+ ++Frees_;
- Check();
+ Check();
- TDefaultAllocator::Release(block);
- }
+ TDefaultAllocator::Release(block);
+ }
- inline void CheckAtEnd() {
- UNIT_ASSERT_EQUAL(Alloced_, Released_);
- UNIT_ASSERT_EQUAL(Allocs_, Frees_);
- }
+ inline void CheckAtEnd() {
+ UNIT_ASSERT_EQUAL(Alloced_, Released_);
+ UNIT_ASSERT_EQUAL(Allocs_, Frees_);
+ }
-private:
- inline void Check() {
- UNIT_ASSERT(Alloced_ >= Released_);
- UNIT_ASSERT(Allocs_ >= Frees_);
- }
+private:
+ inline void Check() {
+ UNIT_ASSERT(Alloced_ >= Released_);
+ UNIT_ASSERT(Allocs_ >= Frees_);
+ }
-private:
- size_t Alloced_;
- size_t Released_;
- size_t Allocs_;
- size_t Frees_;
-};
+private:
+ size_t Alloced_;
+ size_t Released_;
+ size_t Allocs_;
+ size_t Frees_;
+};
class TErrorOnCopy {
public:
@@ -76,20 +76,20 @@ public:
TNoMove(TNoMove&&) = delete;
};
-class TMemPoolTest: public TTestBase {
- UNIT_TEST_SUITE(TMemPoolTest);
- UNIT_TEST(TestMemPool)
- UNIT_TEST(TestAlign)
+class TMemPoolTest: public TTestBase {
+ UNIT_TEST_SUITE(TMemPoolTest);
+ UNIT_TEST(TestMemPool)
+ UNIT_TEST(TestAlign)
UNIT_TEST(TestZeroArray)
- UNIT_TEST(TestLargeStartingAlign)
+ UNIT_TEST(TestLargeStartingAlign)
UNIT_TEST(TestMoveAlloc)
UNIT_TEST(TestRoundUpToNextPowerOfTwoOption)
- UNIT_TEST_SUITE_END();
-
-private:
- inline void TestMemPool() {
- TCheckedAllocator alloc;
+ UNIT_TEST_SUITE_END();
+private:
+ inline void TestMemPool() {
+ TCheckedAllocator alloc;
+
{
TMemoryPool pool(123, TMemoryPool::TExpGrow::Instance(), &alloc);
@@ -168,18 +168,18 @@ private:
alloc.CheckAtEnd();
}
-
- inline void TestAlign() {
- TMemoryPool pool(1);
-
- void* aligned16 = pool.Allocate(3, 16);
- void* aligned2 = pool.Allocate(3, 2);
- void* aligned128 = pool.Allocate(3, 128);
- void* aligned4 = pool.Allocate(3, 4);
- void* aligned256 = pool.Allocate(3, 256);
- void* aligned8 = pool.Allocate(3, 8);
- void* aligned1024 = pool.Allocate(3, 1024);
-
+
+ inline void TestAlign() {
+ TMemoryPool pool(1);
+
+ void* aligned16 = pool.Allocate(3, 16);
+ void* aligned2 = pool.Allocate(3, 2);
+ void* aligned128 = pool.Allocate(3, 128);
+ void* aligned4 = pool.Allocate(3, 4);
+ void* aligned256 = pool.Allocate(3, 256);
+ void* aligned8 = pool.Allocate(3, 8);
+ void* aligned1024 = pool.Allocate(3, 1024);
+
UNIT_ASSERT_VALUES_UNEQUAL(aligned16, nullptr);
UNIT_ASSERT_VALUES_UNEQUAL(aligned2, nullptr);
UNIT_ASSERT_VALUES_UNEQUAL(aligned128, nullptr);
@@ -188,14 +188,14 @@ private:
UNIT_ASSERT_VALUES_UNEQUAL(aligned8, nullptr);
UNIT_ASSERT_VALUES_UNEQUAL(aligned1024, nullptr);
- UNIT_ASSERT_VALUES_EQUAL(reinterpret_cast<uintptr_t>(aligned2) & 1, 0);
- UNIT_ASSERT_VALUES_EQUAL(reinterpret_cast<uintptr_t>(aligned4) & 3, 0);
- UNIT_ASSERT_VALUES_EQUAL(reinterpret_cast<uintptr_t>(aligned8) & 7, 0);
- UNIT_ASSERT_VALUES_EQUAL(reinterpret_cast<uintptr_t>(aligned16) & 15, 0);
- UNIT_ASSERT_VALUES_EQUAL(reinterpret_cast<uintptr_t>(aligned128) & 127, 0);
- UNIT_ASSERT_VALUES_EQUAL(reinterpret_cast<uintptr_t>(aligned256) & 255, 0);
- UNIT_ASSERT_VALUES_EQUAL(reinterpret_cast<uintptr_t>(aligned1024) & 1023, 0);
- }
+ UNIT_ASSERT_VALUES_EQUAL(reinterpret_cast<uintptr_t>(aligned2) & 1, 0);
+ UNIT_ASSERT_VALUES_EQUAL(reinterpret_cast<uintptr_t>(aligned4) & 3, 0);
+ UNIT_ASSERT_VALUES_EQUAL(reinterpret_cast<uintptr_t>(aligned8) & 7, 0);
+ UNIT_ASSERT_VALUES_EQUAL(reinterpret_cast<uintptr_t>(aligned16) & 15, 0);
+ UNIT_ASSERT_VALUES_EQUAL(reinterpret_cast<uintptr_t>(aligned128) & 127, 0);
+ UNIT_ASSERT_VALUES_EQUAL(reinterpret_cast<uintptr_t>(aligned256) & 255, 0);
+ UNIT_ASSERT_VALUES_EQUAL(reinterpret_cast<uintptr_t>(aligned1024) & 1023, 0);
+ }
void TestZeroArray() {
TMemoryPool pool(1);
@@ -205,24 +205,24 @@ private:
UNIT_ASSERT(intArray[i] == 0);
}
- size_t align = 256;
+ size_t align = 256;
ui8* byteArray = pool.AllocateZeroArray<ui8>(size, align);
UNIT_ASSERT(size_t(byteArray) % align == 0);
for (size_t i = 0; i < size; ++i) {
UNIT_ASSERT(byteArray[i] == 0);
- }
- }
-
- void TestLargeStartingAlign() {
- TMemoryPool pool(1);
-
- void* aligned4k1 = pool.Allocate(1, 4096);
- void* aligned4k2 = pool.Allocate(1, 4096);
- UNIT_ASSERT_VALUES_UNEQUAL(aligned4k1, nullptr);
- UNIT_ASSERT_VALUES_UNEQUAL(aligned4k2, nullptr);
- UNIT_ASSERT_VALUES_EQUAL(reinterpret_cast<uintptr_t>(aligned4k1) & 4095, 0);
- UNIT_ASSERT_VALUES_EQUAL(reinterpret_cast<uintptr_t>(aligned4k2) & 4095, 0);
+ }
}
+
+ void TestLargeStartingAlign() {
+ TMemoryPool pool(1);
+
+ void* aligned4k1 = pool.Allocate(1, 4096);
+ void* aligned4k2 = pool.Allocate(1, 4096);
+ UNIT_ASSERT_VALUES_UNEQUAL(aligned4k1, nullptr);
+ UNIT_ASSERT_VALUES_UNEQUAL(aligned4k2, nullptr);
+ UNIT_ASSERT_VALUES_EQUAL(reinterpret_cast<uintptr_t>(aligned4k1) & 4095, 0);
+ UNIT_ASSERT_VALUES_EQUAL(reinterpret_cast<uintptr_t>(aligned4k2) & 4095, 0);
+ }
template <typename T>
void CheckMoveAlloc() {
diff --git a/util/memory/segmented_string_pool.h b/util/memory/segmented_string_pool.h
index a40aa408f5..ed0b542757 100644
--- a/util/memory/segmented_string_pool.h
+++ b/util/memory/segmented_string_pool.h
@@ -7,14 +7,14 @@
#include <util/generic/vector.h>
#include <util/generic/strbuf.h>
-#include <memory>
+#include <memory>
#include <cstdio>
#include <cstdlib>
/*
* Non-reallocated storage for the objects of POD type
*/
-template <class T, class Alloc = std::allocator<T>>
+template <class T, class Alloc = std::allocator<T>>
class segmented_pool: TNonCopyable {
protected:
Alloc seg_allocator;