Aeon Engine c550894
AeonGames Open Source Game Engine
Loading...
Searching...
No Matches
MemoryPool.hpp
1/*
2Copyright (C) 2019,2025,2026 Rodrigo Jose Hernandez Cordoba
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16#ifndef AEONGAMES_MEMORYPOOL_H
17#define AEONGAMES_MEMORYPOOL_H
18#include <cstdint>
19#include <vector>
21
22namespace AeonGames
23{
28 constexpr const std::size_t operator ""_kb ( unsigned long long int aKyloBytes )
29 {
30 return aKyloBytes * 1024;
31 }
32
36 constexpr const std::size_t operator ""_mb ( unsigned long long int aMegaBytes )
37 {
38 return aMegaBytes * 1024_kb;
39 }
40
44 constexpr const std::size_t operator ""_gb ( unsigned long long int aGigaBytes )
45 {
46 return aGigaBytes * 1024_mb;
47 }
48
54 {
55 public:
60 DLL MemoryPool ( size_t sizeOfEachBlock, size_t numOfBlocks );
62 DLL void* Allocate();
64 DLL void DeAllocate ( void* p );
65 private:
66 uint8_t * AddrFromIndex ( size_t i ) const;
67 size_t IndexFromAddr ( const uint8_t* p ) const;
68 size_t mBlockSize;
69 size_t mNumOfBlocks;
70 size_t mNumOfFreeBlocks;
71 size_t mNumOfInitializedBlocks;
72 std::vector<uint8_t> mMemory;
73 uint8_t* mNext;
74 };
75}
76#endif
Platform-specific macros, includes, and DLL export/import definitions.
DLL void * Allocate()
Allocate a block from the pool.
DLL MemoryPool(size_t sizeOfEachBlock, size_t numOfBlocks)
Construct a memory pool.
DLL void DeAllocate(void *p)
Return a block to the pool.
<- This is here just for the literals
Definition AABB.hpp:31