|
ORTS
|
#include <stdlib.h>#include <string.h>#include <ctype.h>#include <SR/sr_mem_control.h>#include <SR/sr_output.h>#include <inttypes.h>Go to the source code of this file.
Classes | |
| struct | srMemData |
Functions | |
| static int | cmp_func (const void *pt1, const void *pt2) |
| static void | sort () |
| void * | sr_mem_control_alloc (const char *type, char *file, int line, int size, void *addr) |
| bool | sr_mem_control_free (char *file, int line, void *addr) |
| void * | sr_mem_control_realloc (char *file, int line, int size, void *addr) |
| void | sr_memory_report () |
| unsigned | sr_memory_allocated () |
| void | sr_memory_report_output (SrOutput &o) |
Variables | |
| static bool | changed = false |
| static srMemData * | mem_data = 0 |
| static int | mem_data_size = 0 |
| static int | mem_data_capacity = 0 |
| static unsigned | mem_bytes_used = 0 |
| static SrOutput & | output = sr_out |
| static int cmp_func | ( | const void * | pt1, |
| const void * | pt2 | ||
| ) | [static] |
Definition at line 41 of file sr_mem_control.cpp.
References srMemData::file, srMemData::size, and srMemData::type.
Referenced by sort().
| static void sort | ( | ) | [static] |
Definition at line 55 of file sr_mem_control.cpp.
References cmp_func(), and mem_data_size.
Referenced by AutoGatherAI::allocateMineralPatchFor(), Decomp::check(), Game::gen_view_diffs(), GameTile::generate_shadows(), ScriptVector::intersect(), GfxModule::move_objects(), GfxModule::pick(), Server::run(), ScriptVector::setify(), ScriptVector::sort(), RouteAllocator::sortRoutesAccordingToLocation(), sr_memory_report(), and ScriptVector::subtract().
| void* sr_mem_control_alloc | ( | const char * | type, |
| char * | file, | ||
| int | line, | ||
| int | size, | ||
| void * | addr | ||
| ) |
This function saves in an internal buffer the given parameters in order to keep track of allocated memory. It may be used by replacing new/malloc calls to:
sr_mem_control_alloc("X",__FILE__,__LINE__,sizeof(X),new X)
Then sr_memory_report() can be called to see all allocated data that was not freed. It is better to use this function with the macros SR_NEW and SR_MALLOC.
Definition at line 60 of file sr_mem_control.cpp.
References changed, mem_bytes_used, mem_data_capacity, mem_data_size, srMemData::set(), and size.
Referenced by sr_mem_control_realloc().
| bool sr_mem_control_free | ( | char * | file, |
| int | line, | ||
| void * | addr | ||
| ) |
This function erases from the internal buffer the given address of memory, that was previously registered with sr_mem_control_alloc(). It is to be used replacing delete/free calls in the following way:
sr_mem_control_free(__FILE__,__LINE__,X); delete X;
It is better to use this function with the macros SR_DEL, SR_DELA and SR_FREE.
Definition at line 86 of file sr_mem_control.cpp.
References changed, SrOutput::fatal_error(), mem_bytes_used, mem_data_size, and srMemData::size.
Referenced by sr_mem_control_realloc().
| void* sr_mem_control_realloc | ( | char * | file, |
| int | line, | ||
| int | size, | ||
| void * | addr | ||
| ) |
This function performs a call to realloc(addr,size), and returns the new pointer. But it also updates the pointers saved in the internal buffer in order to keep track of allocated memory. It may be used replacing realloc calls in the following way:
pt=sr_mem_control_realloc(__FILE__,__LINE__,newsize,pt)
It is better to use this function with the macro SR_REALLOC.
Definition at line 103 of file sr_mem_control.cpp.
References sr_mem_control_alloc(), and sr_mem_control_free().
| unsigned sr_memory_allocated | ( | ) |
Returns the total of memory allocated. Only the memory allocated using sr_mem_control_alloc/free/realloc, or the related macros are taken into account.
Definition at line 127 of file sr_mem_control.cpp.
References mem_bytes_used.
| void sr_memory_report | ( | ) |
This function gives a report about all allocated data that was not freed using sr_out. But to make it work, the user needs to change all new/malloc/delete/free calls by calls to the macros SR_NEW, SR_MALLOC, SR_REALLOC, SR_DEL, SR_DELA, SR_FREE or functions sr_mem_control_alloc/free/realloc.
Definition at line 110 of file sr_mem_control.cpp.
References srMemData::addr, srMemData::file, srMemData::line, mem_bytes_used, mem_data_size, SrOutput::put(), SrOutput::putf(), srMemData::size, sort(), srnl, and srMemData::type.
| void sr_memory_report_output | ( | SrOutput & | o | ) |
Changes the output used for the reports.
Definition at line 132 of file sr_mem_control.cpp.
bool changed = false [static] |
Definition at line 34 of file sr_mem_control.cpp.
Referenced by TRTerrain::TR_Terrain::add_segments(), GameObj::apply_comp_diff(), stype::apply_diff(), ScriptVector::apply_diff(), ScriptSet::apply_diff(), GameObj::apply_diff(), MapTool::generate_game_tiles(), MapTool::generate_marine_map(), MapTool::generate_random_cliff_map(), MapTool::generate_random_map(), TR_PFEngine::insert_boundaries(), MapEvalHandler::processNewObject(), HOG::mapCliqueAbstraction::removeNode(), HOG::graphHierarchy::removeNode(), HOG::mapCliqueAbstraction::repairAbstraction(), HOG::graphHierarchy::repairAbstraction(), sr_mem_control_alloc(), sr_mem_control_free(), and HOG::sharedAMapGroup::updateLocation().
unsigned mem_bytes_used = 0 [static] |
Definition at line 38 of file sr_mem_control.cpp.
Referenced by sr_mem_control_alloc(), sr_mem_control_free(), sr_memory_allocated(), and sr_memory_report().
Definition at line 35 of file sr_mem_control.cpp.
int mem_data_capacity = 0 [static] |
Definition at line 37 of file sr_mem_control.cpp.
Referenced by sr_mem_control_alloc().
int mem_data_size = 0 [static] |
Definition at line 36 of file sr_mem_control.cpp.
Referenced by sort(), sr_mem_control_alloc(), sr_mem_control_free(), and sr_memory_report().
Definition at line 39 of file sr_mem_control.cpp.
Referenced by TR_PFEngine::find_path().