Skip to content
This repository was archived by the owner on Mar 30, 2026. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 7 additions & 22 deletions app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,19 @@
namespace {

constexpr int kBytesToAllocate{64};
constexpr std::size_t kElementsCount{10};

}

class [[nodiscard]] ScopedTimer {
public:
~ScopedTimer() {
try {
std::println(
"{}", std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::steady_clock::now() - start_)
);
} catch (...) {
}
}

private:
std::chrono::steady_clock::time_point start_{std::chrono::steady_clock::now()};
};

auto main() -> int {
try {
lab::memory::PoolMemoryResource<kBytesToAllocate, 10> pool_resource{lab::memory::NewMemoryResource::Instance()};
lab::memory::PoolMemoryResource<kBytesToAllocate, kElementsCount> pool_resource{lab::memory::NewMemoryResource::Instance()};
lab::memory::PoolAllocator<int> pool_allocator{&pool_resource};
ScopedTimer timer{};
int* arr{pool_allocator.allocate(10)};
std::iota(arr, arr + 10, 0);
std::for_each(arr, arr + 10, [counter = 0, arr](int& value) mutable -> void {
arr[counter] = counter;
std::println("arr[{}] = {}", counter, arr[counter]);
int* arr{pool_allocator.allocate(kElementsCount)};
std::iota(arr, arr + kElementsCount, 0); // NOLINT
std::for_each(arr, arr + kElementsCount, [counter = 0, arr](int& value) mutable -> void { // NOLINT
arr[counter] = counter; // NOLINT
std::println("arr[{}] = {}", counter, arr[counter]); // NOLINT
++counter;
});
} catch (const std::exception& error) {
Expand Down
Loading