-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
50 lines (35 loc) · 1.15 KB
/
main.cpp
File metadata and controls
50 lines (35 loc) · 1.15 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
50
#include <iostream>
#include "LinearAllocator.h"
int main()
{
LinearAllocator alloc(1000);
std::cout << "Allocate space for 3 ints" << std::endl;
int* arr = (int*)alloc.Allocate(sizeof(int) * 3);
arr[0] = 10;
arr[1] = 20;
arr[2] = 30;
std::cout << "Used: " << alloc.GetUsed() << " bytes" << std::endl;
std::cout << "Values: ";
for (int i = 0; i < 3; i++)
std::cout << " |"<< arr[i] << "| ";
std::cout << std::endl;
// Allocate more
float* floatPtr = (float*)alloc.Allocate(sizeof(float));
*floatPtr = 3.14f;
std::cout << "Used: " << alloc.GetUsed() << " bytes\n";
// Reset and allocate again (reuses same memory)
std::cout << "before reset - Used: " << alloc.GetUsed() << " bytes\n";
alloc.Reset();
int* arr2 = static_cast<int *>(alloc.Allocate(sizeof(int) * 5));
arr2[0] = 1;
arr2[1] = 2;
arr2[2] = 3;
arr2[3] = 4;
arr2[4] = 5;
std::cout << "After reset - Used: " << alloc.GetUsed() << " bytes\n";
std::cout << "Values: ";
for (int i = 0; i < 5; i++)
std::cout << " |"<< arr2[i] << "| ";
std::cout << std::endl;
std::cin.get();
}