Dura2D  v0.1.0
An educational 2D game physics library
Loading...
Searching...
No Matches
d2BlockAllocator.h
Go to the documentation of this file.
1// MIT License
2
3// Copyright (c) 2019 Erin Catto
4
5// Permission is hereby granted, free of charge, to any person obtaining a copy
6// of this software and associated documentation files (the "Software"), to deal
7// in the Software without restriction, including without limitation the rights
8// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9// copies of the Software, and to permit persons to whom the Software is
10// furnished to do so, subject to the following conditions:
11
12// The above copyright notice and this permission notice shall be included in all
13// copies or substantial portions of the Software.
14
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21// SOFTWARE.
22
23#ifndef D2BLOCKALLOCATOR_H
24#define D2BLOCKALLOCATOR_H
25
26#include "dura2d/d2api.h"
27#include "dura2d/d2Types.h"
28
29// Allocation sizes
30constexpr int d2_blockSizeCount = 14;
31
32// Forward declarations
33struct d2Block;
34struct d2Chunk;
35
41{
42public:
45
48
54 void* Allocate(int32 size);
55
61 void Free(void* p, int32 size);
62
64 void Clear();
65
66private:
68 d2Chunk* m_chunks {nullptr};
69
71 int m_chunkCount {0};
72
74 int m_chunkSpacing {0};
75
77 d2Block* m_freeLists[d2_blockSizeCount] {nullptr};
78};
79
80#endif //D2BLOCKALLOCATOR_H
The d2BlockAllocator class is responsible for managing memory allocation and deallocation....
Definition d2BlockAllocator.h:41
void Free(void *p, int32 size)
Frees a block of memory.
d2BlockAllocator()
Default constructor.
void * Allocate(int32 size)
Allocates a block of memory of the specified size.
void Clear()
Clears all allocated blocks.
~d2BlockAllocator()
Destructor.
constexpr int d2_blockSizeCount
Definition d2BlockAllocator.h:30
signed int int32
Definition d2Types.h:6
#define D2_API
Definition d2api.h:27