mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
Extract allocation macros to alloc.h (mimic the upstream)
See the upstream commit 24bda2faa0
This commit is contained in:
parent
80539245c8
commit
dc5b9340d5
|
@ -1941,6 +1941,7 @@ set_src(ENGINE_SERVER GLOB_RECURSE src/engine/server
|
|||
upnp.h
|
||||
)
|
||||
set_src(GAME_SERVER GLOB_RECURSE src/game/server
|
||||
alloc.h
|
||||
ddracechat.cpp
|
||||
ddracechat.h
|
||||
ddracecommands.cpp
|
||||
|
|
62
src/game/server/alloc.h
Normal file
62
src/game/server/alloc.h
Normal file
|
@ -0,0 +1,62 @@
|
|||
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
|
||||
/* If you are missing that file, acquire a complete release at teeworlds.com. */
|
||||
#ifndef GAME_SERVER_ALLOC_H
|
||||
#define GAME_SERVER_ALLOC_H
|
||||
|
||||
#include <new>
|
||||
|
||||
#include <base/system.h>
|
||||
|
||||
#define MACRO_ALLOC_HEAP() \
|
||||
public: \
|
||||
void *operator new(size_t Size) \
|
||||
{ \
|
||||
void *p = malloc(Size); \
|
||||
mem_zero(p, Size); \
|
||||
return p; \
|
||||
} \
|
||||
void operator delete(void *pPtr) \
|
||||
{ \
|
||||
free(pPtr); \
|
||||
} \
|
||||
\
|
||||
private:
|
||||
|
||||
#define MACRO_ALLOC_POOL_ID() \
|
||||
public: \
|
||||
void *operator new(size_t Size, int id); \
|
||||
void operator delete(void *p, int id); \
|
||||
void operator delete(void *p); /* NOLINT(misc-new-delete-overloads) */ \
|
||||
\
|
||||
private:
|
||||
|
||||
#define MACRO_ALLOC_POOL_ID_IMPL(POOLTYPE, PoolSize) \
|
||||
static char ms_PoolData##POOLTYPE[PoolSize][sizeof(POOLTYPE)] = {{0}}; \
|
||||
static int ms_PoolUsed##POOLTYPE[PoolSize] = {0}; \
|
||||
void *POOLTYPE::operator new(size_t Size, int id) \
|
||||
{ \
|
||||
dbg_assert(sizeof(POOLTYPE) == Size, "size error"); \
|
||||
dbg_assert(!ms_PoolUsed##POOLTYPE[id], "already used"); \
|
||||
/*dbg_msg("pool", "++ %s %d", #POOLTYPE, id);*/ \
|
||||
ms_PoolUsed##POOLTYPE[id] = 1; \
|
||||
mem_zero(ms_PoolData##POOLTYPE[id], Size); \
|
||||
return ms_PoolData##POOLTYPE[id]; \
|
||||
} \
|
||||
void POOLTYPE::operator delete(void *p, int id) \
|
||||
{ \
|
||||
dbg_assert(ms_PoolUsed##POOLTYPE[id], "not used"); \
|
||||
dbg_assert(id == (POOLTYPE *)p - (POOLTYPE *)ms_PoolData##POOLTYPE, "invalid id"); \
|
||||
/*dbg_msg("pool", "-- %s %d", #POOLTYPE, id);*/ \
|
||||
ms_PoolUsed##POOLTYPE[id] = 0; \
|
||||
mem_zero(ms_PoolData##POOLTYPE[id], sizeof(POOLTYPE)); \
|
||||
} \
|
||||
void POOLTYPE::operator delete(void *p) /* NOLINT(misc-new-delete-overloads) */ \
|
||||
{ \
|
||||
int id = (POOLTYPE *)p - (POOLTYPE *)ms_PoolData##POOLTYPE; \
|
||||
dbg_assert(ms_PoolUsed##POOLTYPE[id], "not used"); \
|
||||
/*dbg_msg("pool", "-- %s %d", #POOLTYPE, id);*/ \
|
||||
ms_PoolUsed##POOLTYPE[id] = 0; \
|
||||
mem_zero(ms_PoolData##POOLTYPE[id], sizeof(POOLTYPE)); \
|
||||
}
|
||||
|
||||
#endif
|
|
@ -5,59 +5,8 @@
|
|||
|
||||
#include <base/vmath.h>
|
||||
#include <game/server/gameworld.h>
|
||||
#include <new>
|
||||
|
||||
#define MACRO_ALLOC_HEAP() \
|
||||
public: \
|
||||
void *operator new(size_t Size) \
|
||||
{ \
|
||||
void *p = malloc(Size); \
|
||||
mem_zero(p, Size); \
|
||||
return p; \
|
||||
} \
|
||||
void operator delete(void *pPtr) \
|
||||
{ \
|
||||
free(pPtr); \
|
||||
} \
|
||||
\
|
||||
private:
|
||||
|
||||
#define MACRO_ALLOC_POOL_ID() \
|
||||
public: \
|
||||
void *operator new(size_t Size, int id); \
|
||||
void operator delete(void *p, int id); \
|
||||
void operator delete(void *p); /* NOLINT(misc-new-delete-overloads) */ \
|
||||
\
|
||||
private:
|
||||
|
||||
#define MACRO_ALLOC_POOL_ID_IMPL(POOLTYPE, PoolSize) \
|
||||
static char ms_PoolData##POOLTYPE[PoolSize][sizeof(POOLTYPE)] = {{0}}; \
|
||||
static int ms_PoolUsed##POOLTYPE[PoolSize] = {0}; \
|
||||
void *POOLTYPE::operator new(size_t Size, int id) \
|
||||
{ \
|
||||
dbg_assert(sizeof(POOLTYPE) == Size, "size error"); \
|
||||
dbg_assert(!ms_PoolUsed##POOLTYPE[id], "already used"); \
|
||||
/*dbg_msg("pool", "++ %s %d", #POOLTYPE, id);*/ \
|
||||
ms_PoolUsed##POOLTYPE[id] = 1; \
|
||||
mem_zero(ms_PoolData##POOLTYPE[id], Size); \
|
||||
return ms_PoolData##POOLTYPE[id]; \
|
||||
} \
|
||||
void POOLTYPE::operator delete(void *p, int id) \
|
||||
{ \
|
||||
dbg_assert(ms_PoolUsed##POOLTYPE[id], "not used"); \
|
||||
dbg_assert(id == (POOLTYPE *)p - (POOLTYPE *)ms_PoolData##POOLTYPE, "invalid id"); \
|
||||
/*dbg_msg("pool", "-- %s %d", #POOLTYPE, id);*/ \
|
||||
ms_PoolUsed##POOLTYPE[id] = 0; \
|
||||
mem_zero(ms_PoolData##POOLTYPE[id], sizeof(POOLTYPE)); \
|
||||
} \
|
||||
void POOLTYPE::operator delete(void *p) /* NOLINT(misc-new-delete-overloads) */ \
|
||||
{ \
|
||||
int id = (POOLTYPE *)p - (POOLTYPE *)ms_PoolData##POOLTYPE; \
|
||||
dbg_assert(ms_PoolUsed##POOLTYPE[id], "not used"); \
|
||||
/*dbg_msg("pool", "-- %s %d", #POOLTYPE, id);*/ \
|
||||
ms_PoolUsed##POOLTYPE[id] = 0; \
|
||||
mem_zero(ms_PoolData##POOLTYPE[id], sizeof(POOLTYPE)); \
|
||||
}
|
||||
#include "alloc.h"
|
||||
|
||||
/*
|
||||
Class: Entity
|
||||
|
|
Loading…
Reference in a new issue