mirror of
https://github.com/TombEngine/TombEngine.git
synced 2025-05-11 04:56:49 +03:00
using Alias
This commit is contained in:
parent
22d4793b39
commit
23bcc2e1c0
8 changed files with 30 additions and 15 deletions
|
@ -4,6 +4,7 @@
|
|||
#include <vector>
|
||||
#include <iostream>
|
||||
#include "pool.h"
|
||||
#include <limits>
|
||||
namespace T5M::Memory {
|
||||
template <typename T,typename Pool>
|
||||
class PoolAllocator {
|
||||
|
@ -31,16 +32,16 @@ namespace T5M::Memory {
|
|||
~PoolAllocator() {}
|
||||
|
||||
pointer allocate(size_type n, const void* hint = 0) {
|
||||
return pool->malloc<value_type>(n);
|
||||
return (pool)->malloc<value_type>(n);
|
||||
}
|
||||
void deallocate(T* ptr, size_type n) {
|
||||
pool->free(ptr);
|
||||
(pool)->free(ptr);
|
||||
}
|
||||
|
||||
size_type max_size() const {
|
||||
#pragma push_macro("max") //thanks Microsoft
|
||||
#undef max
|
||||
return numeric_limits<size_type>::max();
|
||||
return std::numeric_limits<size_type>::max();
|
||||
#pragma pop_macro("max")
|
||||
}
|
||||
};
|
||||
|
|
|
@ -2,16 +2,16 @@
|
|||
#include "malloc.h"
|
||||
#include "door.h"
|
||||
#include "PoolAllocator.h"
|
||||
using namespace std;
|
||||
using namespace T5M::Memory;
|
||||
char* malloc_buffer;
|
||||
int malloc_size;
|
||||
char* malloc_ptr;
|
||||
int malloc_free;
|
||||
int malloc_used;
|
||||
Pool<static_cast<unsigned>(BlockSize::Small)>* gameMemory;
|
||||
TGPool* gameMemory;
|
||||
void init_game_malloc() noexcept
|
||||
{
|
||||
gameMemory = new Pool<static_cast<size_t>(BlockSize::Small)>(8*1024*1024);
|
||||
gameMemory = new TGPool(8 * 1024 * 1024);
|
||||
}
|
||||
|
||||
void game_free(void* ptr) noexcept
|
||||
|
|
|
@ -1,15 +1,17 @@
|
|||
#pragma once
|
||||
#include "pool.h"
|
||||
#include <utility>
|
||||
#include "memory/memory.h"
|
||||
extern char* malloc_buffer;
|
||||
extern int malloc_size;
|
||||
extern char* malloc_ptr;
|
||||
extern int malloc_free;
|
||||
extern int malloc_used;
|
||||
using namespace T5M::Memory;
|
||||
extern Pool<static_cast<unsigned>(BlockSize::Small)>* gameMemory;
|
||||
template <typename T>
|
||||
[[nodiscard]] T* game_malloc(size_t count= 1) noexcept {
|
||||
return gameMemory->malloc<T>(count);
|
||||
extern T5M::Memory::TGPool* gameMemory;
|
||||
|
||||
template <typename T,typename ... Args>
|
||||
[[nodiscard]] T* game_malloc(size_t count = 1,Args&&...args) noexcept {
|
||||
return gameMemory->malloc<T>(count,std::forward<Args>(args)...);
|
||||
}
|
||||
void init_game_malloc() noexcept;
|
||||
void game_free(void* ptr) noexcept;
|
8
TR5Main/Game/memory/memory.h
Normal file
8
TR5Main/Game/memory/memory.h
Normal file
|
@ -0,0 +1,8 @@
|
|||
#pragma once
|
||||
#include "pool.h"
|
||||
#include "PoolAllocator.h"
|
||||
#include <vector>
|
||||
namespace T5M::Memory {
|
||||
using TGPool = Pool<16>;
|
||||
template<typename T> using vector = std::vector <T, PoolAllocator<T, TGPool>>;
|
||||
}
|
|
@ -114,8 +114,8 @@ namespace T5M::Memory {
|
|||
}
|
||||
}
|
||||
public:
|
||||
template <typename T>
|
||||
T* malloc(Size count = 1) {
|
||||
template <typename T,typename ... Args>
|
||||
T* malloc(Size count = 1,Args&&...args) {
|
||||
//Forbid allocation of size 0
|
||||
if (count < 1) return nullptr;
|
||||
//assertm(count >= 1,"Allocation Size must be greater than 0!");
|
||||
|
@ -149,7 +149,7 @@ namespace T5M::Memory {
|
|||
head->data.nextFreeBlock = currentNode->data.nextFreeBlock;
|
||||
head->data.managedBlocks = numFreeBlocksAfterSplit;
|
||||
Log("Malloc: New Free Blocks : " << numFreeBlocksAfterSplit)
|
||||
return reinterpret_cast<T*>(blockToReturn);
|
||||
return new(blockToReturn)T(std::forward<Args>(args)...);
|
||||
|
||||
}
|
||||
void free(void* ptr) {
|
||||
|
|
|
@ -15,7 +15,7 @@ void InitialiseAutoGuns(short itemNumber)
|
|||
|
||||
item = &Items[itemNumber];
|
||||
item->meshBits = 1024;
|
||||
item->data = game_malloc<uint8_t[5702]>();
|
||||
item->data = game_malloc<uint8_t>(5702);
|
||||
}
|
||||
|
||||
static void TriggerAutoGunSmoke(PHD_VECTOR* pos, char shade)
|
||||
|
|
|
@ -142,6 +142,7 @@ xcopy /Y "$(ProjectDir)Scripting\Scripts\*.lua" "$(TargetDir)\Scripts"</Command>
|
|||
<ClInclude Include="Game\memory\pool.h" />
|
||||
<ClInclude Include="Game\memory\linearPoolAllocator.h" />
|
||||
<ClInclude Include="Game\memory\PoolAllocator.h" />
|
||||
<ClInclude Include="Game\memory\memory.h" />
|
||||
<ClInclude Include="Game\phd_global.h" />
|
||||
<ClInclude Include="Game\memory\qmalloc.h" />
|
||||
<ClInclude Include="Game\room.h" />
|
||||
|
|
|
@ -849,6 +849,9 @@
|
|||
<ClInclude Include="Game\memory\PoolAllocator.h">
|
||||
<Filter>File di intestazione</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Game\memory\memory.h">
|
||||
<Filter>File di intestazione</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Game\box.cpp">
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue