-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.cpp
More file actions
49 lines (40 loc) · 1.66 KB
/
Copy pathexample.cpp
File metadata and controls
49 lines (40 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "src/allocator.h"
#include <iostream>
#include <vector>
int main() {
std::cout << "Memory Allocator Example\n";
std::cout << "========================\n\n";
// Create allocator with 64MB pool
CustomAllocator allocator(64 * 1024 * 1024);
std::vector<void*> pointers;
// Allocate some memory blocks
std::cout << "Allocating memory blocks...\n";
for (int i = 0; i < 10; ++i) {
size_t size = (i + 1) * 64;
void* ptr = allocator.allocate(size);
if (ptr) {
pointers.push_back(ptr);
std::cout << " Allocated " << size << " bytes at " << ptr << "\n";
}
}
std::cout << "\nStatistics:\n";
std::cout << " Total size: " << allocator.get_total_size() << " bytes\n";
std::cout << " Used size: " << allocator.get_used_size() << " bytes\n";
std::cout << " Free size: " << allocator.get_free_size() << " bytes\n";
// Deallocate some blocks
std::cout << "\nDeallocating some blocks...\n";
for (size_t i = 0; i < pointers.size(); i += 2) {
std::cout << " Deallocating block at " << pointers[i] << "\n";
allocator.deallocate(pointers[i]);
}
std::cout << "\nFinal Statistics:\n";
std::cout << " Total size: " << allocator.get_total_size() << " bytes\n";
std::cout << " Used size: " << allocator.get_used_size() << " bytes\n";
std::cout << " Free size: " << allocator.get_free_size() << " bytes\n";
// Clean up remaining blocks
for (size_t i = 1; i < pointers.size(); i += 2) {
allocator.deallocate(pointers[i]);
}
std::cout << "\nExample completed successfully!\n";
return 0;
}