Skip to content

Commit bec7e29

Browse files
committed
Memory: Add scratch allocator doc.
1 parent 8e97ff1 commit bec7e29

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

doc/Common.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ You need to manage singe bits and you want to avoid dealing with the OR-, AND- a
3838

3939
void main() {
4040
TBitField<uint32_t> bitfield(0);
41-
41+
4242
// The first bit is set
4343
bitfield.setBit(1);
4444
if (bitfield.getBit(1)) std::cout "First bit is set" << std:endl;
@@ -53,12 +53,12 @@ void main() {
5353
### Usecases
5454
### Examples
5555

56-
## TSharedPtr
56+
## TSharedPtr
5757
### Introduction
5858
### Usecases
5959
### Examples
6060

61-
## Variant
61+
## Variant
6262
### Introduction
6363
### Usecases
6464
### Examples

doc/Memory.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,34 @@ allocation scheme in all containers.
88
## CPPCore::TPoolAllocator
99
This allocator can be use to create an initial pool of object at the program startup.
1010

11+
## CPPCore::TScratchAllocator
12+
### Introduction
13+
The scratch allocator preallocates a memory block which can be used in your program. You do not have to deallocate any of the allocations.
14+
This will be done when clearing the allocator. All allocations will be invalidated.
15+
16+
### Usecases
17+
You need to sove any kind of algorithms. For this you need to work with dynamic allocations, which will be thrown away
18+
after finishing your work.
19+
20+
### Examples
21+
```cpp
22+
#include <Memroy/TScrachtAllocator.h>
23+
24+
using namespace ::cppcore;
25+
26+
int main() {
27+
// Will work
28+
ScratchAllocator myAllocator(1024);
29+
char *ptr1 = myAllocator.alloc(512);
30+
assert(ptr1 != nullptr);
31+
32+
// Overrange shall get catched
33+
char *ptr2 = myAllocator.alloc(600);
34+
assert(ptr2 == nullptr);
35+
36+
return 0;
37+
}
38+
```
39+
1140
## CPPCore::TStackAllocator
1241
The stack allocator preallocates a memory block which can be used in your program. When deallocating your memory you have to follow the first-in last-out rule.

0 commit comments

Comments
 (0)