24 #include <glog/logging.h> 26 using namespace folly;
31 std::set<size_t*> allocatedItems;
33 static const size_t requestedBlockSize = 64;
35 size_t minimum_size =
sizeof(
SysArena), maximum_size = minimum_size;
39 size_t*
ptr =
static_cast<size_t*
>(arena.
allocate(
sizeof(
long)));
40 allocatedItems.insert(ptr);
41 minimum_size += requestedBlockSize;
45 VLOG(4) << minimum_size <<
" < " << arena.
totalSize() <<
" < " 49 ptr =
static_cast<size_t*
>(arena.
allocate(requestedBlockSize / 2));
50 allocatedItems.insert(ptr);
53 VLOG(4) << minimum_size <<
" < " << arena.
totalSize() <<
" < " 57 for (
int i = 0;
i < 10;
i++) {
58 ptr =
static_cast<size_t*
>(arena.
allocate(requestedBlockSize));
59 allocatedItems.insert(ptr);
61 minimum_size += 10 * requestedBlockSize;
66 VLOG(4) << minimum_size <<
" < " << arena.
totalSize() <<
" < " 70 ptr =
static_cast<size_t*
>(arena.
allocate(10 * requestedBlockSize));
71 allocatedItems.insert(ptr);
72 minimum_size += 10 * requestedBlockSize;
77 VLOG(4) << minimum_size <<
" < " << arena.
totalSize() <<
" < " 81 for (
const auto& item : allocatedItems) {
87 VLOG(4) << minimum_size <<
" < " << arena.
totalSize() <<
" < " 92 static const size_t smallChunkSize = 1024;
93 static const size_t blockSize =
goodMallocSize(16 * smallChunkSize);
94 const size_t bigChunkSize = blockSize - 4 * smallChunkSize;
104 bytesUsed += 2 * smallChunkSize;
111 bytesUsed += bigChunkSize;
118 bytesUsed += bigChunkSize;
124 static const size_t tinyChunkSize = 7;
127 size_t delta = arena.
bytesUsed() - bytesUsed;
132 static const size_t requestedBlockSize = 64;
137 std::vector<size_t, SysArenaAllocator<size_t>>
vec{
140 for (
size_t i = 0;
i < 1000;
i++) {
144 for (
size_t i = 0;
i < 1000;
i++) {
150 static const size_t requestedBlockSize =
sizeof(size_t);
151 static const size_t maxSize = 10 * requestedBlockSize;
153 SysArena arena(requestedBlockSize, maxSize);
155 void*
a = arena.
allocate(
sizeof(
size_t));
162 gflags::ParseCommandLineFlags(&argc, &argv,
true);
#define EXPECT_THROW(statement, expected_exception)
int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_
#define EXPECT_EQ(val1, val2)
—— Concurrent Priority Queue Implementation ——
static constexpr size_t kBlockOverhead
#define EXPECT_TRUE(condition)
GTEST_API_ void InitGoogleTest(int *argc, char **argv)
void deallocate(void *, size_t=0)
void * allocate(size_t size)
TEST(SequencedExecutor, CPUThreadPoolExecutor)
int main(int argc, char *argv[])
size_t goodMallocSize(size_t minSize) noexcept