diff options
author | Ruslan Kovalev <ruslan.a.kovalev@gmail.com> | 2022-02-10 16:46:45 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:45 +0300 |
commit | 9123176b341b6f2658cff5132482b8237c1416c8 (patch) | |
tree | 49e222ea1c5804306084bb3ae065bb702625360f /util/memory | |
parent | 59e19371de37995fcb36beb16cd6ec030af960bc (diff) | |
download | ydb-9123176b341b6f2658cff5132482b8237c1416c8.tar.gz |
Restoring authorship annotation for Ruslan Kovalev <ruslan.a.kovalev@gmail.com>. Commit 2 of 2.
Diffstat (limited to 'util/memory')
-rw-r--r-- | util/memory/addstorage.h | 2 | ||||
-rw-r--r-- | util/memory/alloc.h | 2 | ||||
-rw-r--r-- | util/memory/blob.h | 2 | ||||
-rw-r--r-- | util/memory/mmapalloc.h | 2 | ||||
-rw-r--r-- | util/memory/pool.h | 32 | ||||
-rw-r--r-- | util/memory/pool_ut.cpp | 18 | ||||
-rw-r--r-- | util/memory/segmented_string_pool.h | 2 | ||||
-rw-r--r-- | util/memory/segpool_alloc.h | 2 | ||||
-rw-r--r-- | util/memory/smallobj.h | 50 | ||||
-rw-r--r-- | util/memory/smallobj_ut.cpp | 28 | ||||
-rw-r--r-- | util/memory/tempbuf.h | 2 |
11 files changed, 71 insertions, 71 deletions
diff --git a/util/memory/addstorage.h b/util/memory/addstorage.h index 7ecbd0ebd5..597c73a988 100644 --- a/util/memory/addstorage.h +++ b/util/memory/addstorage.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include <util/system/align.h> #include <util/system/defaults.h> diff --git a/util/memory/alloc.h b/util/memory/alloc.h index 9e45e3e547..d59575aef5 100644 --- a/util/memory/alloc.h +++ b/util/memory/alloc.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include <memory> diff --git a/util/memory/blob.h b/util/memory/blob.h index b9bfcf5645..20c02a68df 100644 --- a/util/memory/blob.h +++ b/util/memory/blob.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include <util/generic/fwd.h> #include <util/generic/strbuf.h> diff --git a/util/memory/mmapalloc.h b/util/memory/mmapalloc.h index 5c984a3ebd..06002e58fc 100644 --- a/util/memory/mmapalloc.h +++ b/util/memory/mmapalloc.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once class IAllocator; diff --git a/util/memory/pool.h b/util/memory/pool.h index 48494cb33d..13c8b6b9ed 100644 --- a/util/memory/pool.h +++ b/util/memory/pool.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include "alloc.h" @@ -7,7 +7,7 @@ #include <util/generic/bitops.h> #include <util/generic/utility.h> #include <util/generic/intrlist.h> -#include <util/generic/strbuf.h> +#include <util/generic/strbuf.h> #include <util/generic/singleton.h> #include <new> @@ -79,7 +79,7 @@ private: inline char* Data() noexcept { return (char*)(this + 1); } - + inline size_t DataSize() const noexcept { return Cur_ - Data(); } @@ -157,22 +157,22 @@ public: template <typename T> inline T* Allocate() { - return (T*)this->Allocate(sizeof(T), alignof(T)); + return (T*)this->Allocate(sizeof(T), alignof(T)); } template <typename T> inline T* Allocate(size_t align) { - return (T*)this->Allocate(sizeof(T), Max(align, alignof(T))); + return (T*)this->Allocate(sizeof(T), Max(align, alignof(T))); } template <typename T> inline T* AllocateArray(size_t count) { - return (T*)this->Allocate(sizeof(T) * count, alignof(T)); + return (T*)this->Allocate(sizeof(T) * count, alignof(T)); } template <typename T> inline T* AllocateArray(size_t count, size_t align) { - return (T*)this->Allocate(sizeof(T) * count, Max(align, alignof(T))); + return (T*)this->Allocate(sizeof(T) * count, Max(align, alignof(T))); } template <typename T> @@ -196,7 +196,7 @@ public: template <typename T> inline T* NewArray(size_t count) { - T* arr = (T*)AllocateArray<T>(count); + T* arr = (T*)AllocateArray<T>(count); for (T *ptr = arr, *end = arr + count; ptr != end; ++ptr) { new (ptr) T; @@ -217,12 +217,12 @@ public: std::char_traits<TChar>::copy(ret, str, len); return ret; } - + template <typename TChar> 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) { TChar* ret = static_cast<TChar*>(Allocate((buf.size() + 1) * sizeof(TChar))); @@ -292,7 +292,7 @@ protected: private: void AddChunk(size_t hint); void DoClear(bool keepfirst) noexcept; - + private: TChunk Empty_; TChunk* Current_; @@ -321,9 +321,9 @@ struct TPoolableBase { inline void operator delete(void*, TPool&) noexcept { } - -private: - inline void* operator new(size_t); // disallow default allocation + +private: + inline void* operator new(size_t); // disallow default allocation }; struct TPoolable: public TPoolableBase<TMemoryPool> { @@ -371,7 +371,7 @@ public: : Pool_(o.GetPool()) { } - + inline T* allocate(size_t n) { return (T*)Pool_->Allocate(n * sizeof(T), alignof(T)); } @@ -401,7 +401,7 @@ public: inline TPool* GetPool() const { return Pool_; } - + inline friend bool operator==(const TPoolAllocBase& l, const TPoolAllocBase& r) { return l.Pool_ == r.Pool_; } diff --git a/util/memory/pool_ut.cpp b/util/memory/pool_ut.cpp index dc5893778a..1158a8ca42 100644 --- a/util/memory/pool_ut.cpp +++ b/util/memory/pool_ut.cpp @@ -99,33 +99,33 @@ private: } alloc.CheckAtEnd(); - + { TMemoryPool pool(150, TMemoryPool::TExpGrow::Instance(), &alloc); - + pool.Allocate(8); - + size_t memavail = pool.Available(); size_t memwaste = pool.MemoryWaste(); size_t memalloc = pool.MemoryAllocated(); - + for (size_t i = 0; i < 1000; ++i) { void* m = pool.Allocate(i); UNIT_ASSERT(m); memset(m, 0, i); } - + pool.ClearKeepFirstChunk(); - + UNIT_ASSERT_VALUES_EQUAL(memalloc - 8, pool.MemoryAllocated()); UNIT_ASSERT_VALUES_EQUAL(memwaste + 8, pool.MemoryWaste()); UNIT_ASSERT_VALUES_EQUAL(memavail + 8, pool.Available()); - + for (size_t i = 0; i < 1000; ++i) { void* m = pool.Allocate(i); UNIT_ASSERT(m); memset(m, 0, i); - } + } pool.Clear(); @@ -133,7 +133,7 @@ private: UNIT_ASSERT_VALUES_EQUAL(0, pool.MemoryWaste()); UNIT_ASSERT_VALUES_EQUAL(0, pool.Available()); } - + alloc.CheckAtEnd(); struct TConstructorTest { diff --git a/util/memory/segmented_string_pool.h b/util/memory/segmented_string_pool.h index c8c724a2ae..a40aa408f5 100644 --- a/util/memory/segmented_string_pool.h +++ b/util/memory/segmented_string_pool.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include <util/system/align.h> #include <util/system/yassert.h> diff --git a/util/memory/segpool_alloc.h b/util/memory/segpool_alloc.h index 2d6b5a0e3e..1a83b7a543 100644 --- a/util/memory/segpool_alloc.h +++ b/util/memory/segpool_alloc.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include "segmented_string_pool.h" diff --git a/util/memory/smallobj.h b/util/memory/smallobj.h index 7501933758..63de666bae 100644 --- a/util/memory/smallobj.h +++ b/util/memory/smallobj.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include "pool.h" #include "alloc.h" @@ -16,14 +16,14 @@ class TFixedSizeAllocator { return (TAlloc*)ptr; } - static constexpr size_t EntitySize(size_t alloc) noexcept { + static constexpr size_t EntitySize(size_t alloc) noexcept { return Max(sizeof(TAlloc), alloc); } - static constexpr size_t EntityAlign(size_t align) noexcept { - return Max(alignof(TAlloc), align); - } - + static constexpr size_t EntityAlign(size_t align) noexcept { + return Max(alignof(TAlloc), align); + } + static inline TAlloc* Construct(void* ptr) noexcept { return (TAlloc*)ptr; } @@ -32,31 +32,31 @@ class TFixedSizeAllocator { public: using IGrowPolicy = TMemoryPool::IGrowPolicy; - TFixedSizeAllocator(size_t allocSize, IAllocator* alloc) - : TFixedSizeAllocator(allocSize, alignof(TAlloc), TMemoryPool::TExpGrow::Instance(), alloc) + TFixedSizeAllocator(size_t allocSize, IAllocator* alloc) + : TFixedSizeAllocator(allocSize, alignof(TAlloc), TMemoryPool::TExpGrow::Instance(), alloc) + { + } + + TFixedSizeAllocator(size_t allocSize, size_t alignSize, IAllocator* alloc) + : TFixedSizeAllocator(allocSize, alignSize, TMemoryPool::TExpGrow::Instance(), alloc) + { + } + + TFixedSizeAllocator(size_t allocSize, IGrowPolicy* grow, IAllocator* alloc) + : TFixedSizeAllocator(allocSize, alignof(TAlloc), grow, alloc) { } - TFixedSizeAllocator(size_t allocSize, size_t alignSize, IAllocator* alloc) - : TFixedSizeAllocator(allocSize, alignSize, TMemoryPool::TExpGrow::Instance(), alloc) - { - } - - TFixedSizeAllocator(size_t allocSize, IGrowPolicy* grow, IAllocator* alloc) - : TFixedSizeAllocator(allocSize, alignof(TAlloc), grow, alloc) - { - } - - TFixedSizeAllocator(size_t allocSize, size_t alignSize, IGrowPolicy* grow, IAllocator* alloc) + TFixedSizeAllocator(size_t allocSize, size_t alignSize, IGrowPolicy* grow, IAllocator* alloc) : Pool_(allocSize, grow, alloc) - , AlignSize_(TAlloc::EntityAlign(alignSize)) - , AllocSize_(TAlloc::EntitySize(allocSize)) + , AlignSize_(TAlloc::EntityAlign(alignSize)) + , AllocSize_(TAlloc::EntitySize(allocSize)) { } inline void* Allocate() { if (Y_UNLIKELY(Free_.Empty())) { - return Pool_.Allocate(AllocSize_, AlignSize_); + return Pool_.Allocate(AllocSize_, AlignSize_); } return Free_.PopFront()->ToPointer(); @@ -72,7 +72,7 @@ public: private: TMemoryPool Pool_; - const size_t AlignSize_; + const size_t AlignSize_; const size_t AllocSize_; TIntrusiveSList<TAlloc> Free_; }; @@ -83,12 +83,12 @@ public: using IGrowPolicy = TFixedSizeAllocator::IGrowPolicy; inline TSmallObjAllocator(IAllocator* alloc) - : Alloc_(sizeof(T), alignof(T), alloc) + : Alloc_(sizeof(T), alignof(T), alloc) { } inline TSmallObjAllocator(IGrowPolicy* grow, IAllocator* alloc) - : Alloc_(sizeof(T), alignof(T), grow, alloc) + : Alloc_(sizeof(T), alignof(T), grow, alloc) { } diff --git a/util/memory/smallobj_ut.cpp b/util/memory/smallobj_ut.cpp index 6da02f0ecf..86003d1d53 100644 --- a/util/memory/smallobj_ut.cpp +++ b/util/memory/smallobj_ut.cpp @@ -18,29 +18,29 @@ class TSmallObjAllocTest: public TTestBase { }; struct TClass64: public TObjectFromPool<TClass64> { - alignas(64) ui64 Data = 0; - }; - + alignas(64) ui64 Data = 0; + }; + UNIT_TEST_SUITE(TSmallObjAllocTest); - UNIT_TEST(TestAlign) - UNIT_TEST(TestError) + UNIT_TEST(TestAlign) + UNIT_TEST(TestError) UNIT_TEST(TestAllocate) UNIT_TEST_SUITE_END(); private: - void TestAlign() { - TClass64::TPool pool(TDefaultAllocator::Instance()); + void TestAlign() { + TClass64::TPool pool(TDefaultAllocator::Instance()); TClass64* f1 = new (&pool) TClass64; TClass64* f2 = new (&pool) TClass64; TClass64* f3 = new (&pool) TClass64; TClass64* f4 = new (&pool) TClass64; - UNIT_ASSERT_VALUES_EQUAL(64u, alignof(TClass64)); - UNIT_ASSERT_VALUES_EQUAL((size_t)0, (size_t)(f1) & (alignof(TClass64) - 1)); - UNIT_ASSERT_VALUES_EQUAL((size_t)0, (size_t)(f2) & (alignof(TClass64) - 1)); - UNIT_ASSERT_VALUES_EQUAL((size_t)0, (size_t)(f3) & (alignof(TClass64) - 1)); - UNIT_ASSERT_VALUES_EQUAL((size_t)0, (size_t)(f4) & (alignof(TClass64) - 1)); - } - + UNIT_ASSERT_VALUES_EQUAL(64u, alignof(TClass64)); + UNIT_ASSERT_VALUES_EQUAL((size_t)0, (size_t)(f1) & (alignof(TClass64) - 1)); + UNIT_ASSERT_VALUES_EQUAL((size_t)0, (size_t)(f2) & (alignof(TClass64) - 1)); + UNIT_ASSERT_VALUES_EQUAL((size_t)0, (size_t)(f3) & (alignof(TClass64) - 1)); + UNIT_ASSERT_VALUES_EQUAL((size_t)0, (size_t)(f4) & (alignof(TClass64) - 1)); + } + inline void TestError() { TErrClass::TPool pool(TDefaultAllocator::Instance()); TErrClass* f = new (&pool) TErrClass(false); diff --git a/util/memory/tempbuf.h b/util/memory/tempbuf.h index 38b967a718..334670eb1e 100644 --- a/util/memory/tempbuf.h +++ b/util/memory/tempbuf.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include <util/system/defaults.h> #include <util/generic/ptr.h> |