Scippy

SCIP

Solving Constraint Integer Programs

memory.c File Reference

Detailed Description

memory allocation routines

Author
Tobias Achterberg

Definition in file memory.c.

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include "blockmemshell/memory.h"

Go to the source code of this file.

Macros

#define debugMessage   while( FALSE ) printf
 
#define errorMessage   printf
 
#define printErrorHeader(f, l)   printf("[%s:%d] ERROR: ", f, l)
 
#define printError   printf
 
#define warningMessage   printf
 
#define printInfo   printf
 
#define FALSE   0
 
#define TRUE   1
 
#define MAX(x, y)   ((x) >= (y) ? (x) : (y))
 
#define MIN(x, y)   ((x) <= (y) ? (x) : (y))
 
#define CHUNKLENGTH_MIN   1024
 
#define CHUNKLENGTH_MAX   1048576
 
#define STORESIZE_MAX   8192
 
#define GARBAGE_SIZE   256
 
#define ALIGNMENT   (sizeof(FREELIST))
 
#define checkChunk(chunk)
 
#define checkChkmem(chkmem)
 
#define CHKHASH_SIZE   1013
 
#define checkBlkmem(blkmem)
 

Typedefs

typedef struct Freelist FREELIST
 
typedef struct Chunk CHUNK
 

Functions

size_t BMSgetPointerSize_call (const void *ptr)
 
void BMSdisplayMemory_call (void)
 
void BMScheckEmptyMemory_call (void)
 
long long BMSgetMemoryUsed_call (void)
 
void * BMSallocClearMemory_call (size_t num, size_t size, const char *filename, int line)
 
void * BMSallocMemory_call (size_t size, const char *filename, int line)
 
void * BMSreallocMemory_call (void *ptr, size_t size, const char *filename, int line)
 
void BMSclearMemory_call (void *ptr, size_t size)
 
void BMScopyMemory_call (void *ptr, const void *source, size_t size)
 
void BMSmoveMemory_call (void *ptr, const void *source, size_t size)
 
void * BMSduplicateMemory_call (const void *source, size_t size, const char *filename, int line)
 
void BMSfreeMemory_call (void *ptr, const char *filename, int line)
 
static void alignSize (size_t *size)
 
void BMSalignMemsize (size_t *size)
 
int BMSisAligned (size_t size)
 
static int isPtrInChunk (const CHUNK *chunk, const void *ptr)
 
static CHUNKfindChunk (const BMS_CHKMEM *chkmem, const void *ptr)
 
static int isPtrInChkmem (const BMS_CHKMEM *chkmem, const void *ptr)
 
static int linkChunk (BMS_CHKMEM *chkmem, CHUNK *chunk)
 
static void unlinkChunk (CHUNK *chunk)
 
static void linkEagerChunk (BMS_CHKMEM *chkmem, CHUNK *chunk)
 
static void unlinkEagerChunk (CHUNK *chunk)
 
static int createChunk (BMS_CHKMEM *chkmem)
 
static void destroyChunk (CHUNK *chunk)
 
static void freeChunk (CHUNK *chunk)
 
static void * allocChunkElement (CHUNK *chunk)
 
static void freeChunkElement (CHUNK *chunk, void *ptr)
 
static BMS_CHKMEMcreateChkmem (int size, int initchunksize, int garbagefactor)
 
static void clearChkmem (BMS_CHKMEM *chkmem)
 
static void destroyChkmem (BMS_CHKMEM **chkmem)
 
static void * allocChkmemElement (BMS_CHKMEM *chkmem)
 
static void garbagecollectChkmem (BMS_CHKMEM *chkmem)
 
static void freeChkmemElement (BMS_CHKMEM *chkmem, void *ptr, const char *filename, int line)
 
BMS_CHKMEMBMScreateChunkMemory_call (size_t size, int initchunksize, int garbagefactor, const char *filename, int line)
 
void BMSclearChunkMemory_call (BMS_CHKMEM *chkmem, const char *filename, int line)
 
void BMSdestroyChunkMemory_call (BMS_CHKMEM **chkmem, const char *filename, int line)
 
void * BMSallocChunkMemory_call (BMS_CHKMEM *chkmem, size_t size, const char *filename, int line)
 
void * BMSduplicateChunkMemory_call (BMS_CHKMEM *chkmem, const void *source, size_t size, const char *filename, int line)
 
void BMSfreeChunkMemory_call (BMS_CHKMEM *chkmem, void *ptr, size_t size, const char *filename, int line)
 
void BMSgarbagecollectChunkMemory_call (BMS_CHKMEM *chkmem)
 
long long BMSgetChunkMemoryUsed_call (const BMS_CHKMEM *chkmem)
 
static BMS_CHKMEMfindChkmem (const BMS_BLKMEM *blkmem, const void *ptr)
 
static int getHashNumber (int size)
 
BMS_BLKMEMBMScreateBlockMemory_call (int initchunksize, int garbagefactor, const char *filename, int line)
 
void BMSclearBlockMemory_call (BMS_BLKMEM *blkmem, const char *filename, int line)
 
void BMSdestroyBlockMemory_call (BMS_BLKMEM **blkmem, const char *filename, int line)
 
void * BMSallocBlockMemory_call (BMS_BLKMEM *blkmem, size_t size, const char *filename, int line)
 
void * BMSreallocBlockMemory_call (BMS_BLKMEM *blkmem, void *ptr, size_t oldsize, size_t newsize, const char *filename, int line)
 
void * BMSduplicateBlockMemory_call (BMS_BLKMEM *blkmem, const void *source, size_t size, const char *filename, int line)
 
void BMSfreeBlockMemory_call (BMS_BLKMEM *blkmem, void *ptr, size_t size, const char *filename, int line)
 
void BMSgarbagecollectBlockMemory_call (BMS_BLKMEM *blkmem)
 
long long BMSgetBlockMemoryUsed_call (const BMS_BLKMEM *blkmem)
 
size_t BMSgetBlockPointerSize_call (const BMS_BLKMEM *blkmem, const void *ptr)
 
void BMSdisplayBlockMemory_call (const BMS_BLKMEM *blkmem)
 
void BMScheckEmptyBlockMemory_call (const BMS_BLKMEM *blkmem)
 

Macro Definition Documentation

#define errorMessage   printf

Definition at line 44 of file memory.c.

Referenced by garbagecollectChkmem().

#define warningMessage   printf

Definition at line 49 of file memory.c.

#define printInfo   printf
#define FALSE   0

Definition at line 54 of file memory.c.

Referenced by createChunk(), and linkChunk().

#define TRUE   1

Definition at line 55 of file memory.c.

Referenced by linkChunk().

#define MAX (   x,
 
)    ((x) >= (y) ? (x) : (y))
#define MIN (   x,
 
)    ((x) <= (y) ? (x) : (y))

Definition at line 59 of file memory.c.

Referenced by addBilinMcCormick(), addConcaveEstimatorBivariate(), addConcaveEstimatorMultivariate(), addConflictBinvar(), addIntervalGradientEstimator(), addLinearization(), addLinearizationCuts(), aggregation(), analyzeEnergyRequirement(), applyFixings(), applyVbounds(), BMSreallocBlockMemory_call(), calcPscostQuot(), calcScore(), calcShiftVal(), calculateBounds(), checkArraySizesGLS(), checkArraySizesHeur(), checkCurvature(), checkFactorable(), checkFixedVariables(), checkRedundancySide(), chooseDoubleVar(), collectBinaryCliqueData(), collectBinaryImplicationData(), collectBinaryVars(), collectBranchingCands(), collectDataTTEF(), collectIntVars(), collectMaxactVar(), collectNonBinaryImplicationData(), collectNonBinaryVBoundData(), collectThetaSubtree(), computeCoreWithInterval(), computeFieldWidth(), computeFixingOrder(), computeViolation(), conflictAnalyze(), conflictCreateReconvergenceConss(), conflictInsertConflictset(), conflictMarkBoundCheckPresence(), conflictsetAddBound(), conflictsetAddBounds(), conflictsetCalcInsertDepth(), consCapacityConstraintsFinder(), consCheckRedundancy(), consdataGetActivity(), consdataGetFeasibility(), consdataTightenCoefs(), consdataUpdateLinearActivity(), copyAndSolveComponent(), coretimesUpdateLb(), createChunk(), createCoreProfile(), createCoverCuts(), createCoverCutsTimepoint(), createCoveringProblem(), createDisjuctiveCons(), createNlRow(), createSubproblem(), createSubscip(), cutGenerationHeuristic(), cutpoolDelCut(), detectRedundantConstraints(), determineBound(), dualWeightsTightening(), ensureMemorySize(), evalLhs(), evalMin(), execRelpscost(), exprgraphUpdateVarNodeBounds(), exprUnconvertPolynomial(), findDominancePairs(), fixAndPropagate(), fixDiscreteVars(), fullDualPresolve(), generateCloseCutPoint(), generateConvexConcaveUnderestimator(), generateCut(), generateCutLTIcomputeCoefs(), generateCutSol(), generateOrthogonal_lx_ly_Underestimator(), generateOrthogonal_lx_uy_Underestimator(), generateSparseCut(), generateUnderestimatorParallelYFacets(), getBounddist(), getFlowCover(), getImpliedBounds(), getIterationsLeft(), getZiValue(), GUBsetCalcCliquePartition(), handleCycle(), hashtableResize(), hessLagAddExprtree(), hessLagSparsitySetNzFlagForExprtree(), initSepaData(), insertSortedRootNeighbors(), insertZerolist(), isLbBetter(), isUbBetter(), lpGetResolveItlim(), nlrowRemoveFixedLinearCoefs(), nlrowRemoveFixedQuadVars(), nodeGetUctScore(), nodepairqueueCreate(), normalizeCons(), normalizeCumulativeCondition(), optimize(), paramsetSetSeparatingAggressive(), performFixing(), performStrongbranchWithPropagation(), perturb(), preprocessCliques(), preprocessConstraintPairs(), presolveConsEst(), presolveConsLct(), presolveDual(), presolveFindDuplicates(), presolveTryAddLinearReform(), prettifyConss(), priceAndCutLoop(), primalAddOrigSol(), primalAddSol(), primalSetCutoffbound(), primalSetUpperbound(), propagateBounds(), propagateBoundsBilinearTerm(), propagateBoundsCons(), propagateBoundsGetQuadActivity(), propagateCons(), propagateLbTTEF(), propagateTimetable(), propagateUbTTEF(), proposeBranchingPoint(), proposeFeasibleSolution(), readNonlinearExprs(), registerVariableInfeasibilities(), resolvePropagation(), resolvePropagationCoretimes(), respropCumulativeCondition(), rowAddNorms(), rowCalcIdxsAndVals(), SCIP_DECL_BRANCHEXECLP(), SCIP_DECL_CONSENFOLP(), SCIP_DECL_CONSINITLP(), SCIP_DECL_CONSINITSOL(), SCIP_DECL_CONSPRESOL(), SCIP_DECL_EXPREVAL(), SCIP_DECL_EXPRGRAPHVARADDED(), SCIP_DECL_HEUREXEC(), SCIP_DECL_NLPISETINTPAR(), SCIP_DECL_NODESELSELECT(), SCIP_DECL_PRESOLEXEC(), SCIP_DECL_PROPRESPROP(), SCIP_DECL_SEPAEXECLP(), SCIPaddToNlpiProblemQuadratic(), SCIPanalyzeDeductionsProbing(), SCIPapplyHeurDualval(), SCIPapplyHeurSubNlp(), SCIPapplyProximity(), SCIPapplyUndercover(), SCIPapplyZeroobj(), SCIPboolarrayExtend(), SCIPboolarraySetVal(), SCIPbranchGetBranchingPoint(), SCIPcalcCliquePartition(), SCIPcalcIntegralScalar(), SCIPcolGetStrongbranch(), SCIPcolGetStrongbranches(), SCIPcolSetStrongbranchData(), SCIPconflictAddRelaxedBound(), SCIPconshdlrPropagate(), SCIPconshdlrSeparateLP(), SCIPevalExprtreeLocalBounds(), SCIPexprgraphGetSeparableTrees(), SCIPgetGap(), SCIPgetTransGap(), SCIPinferVarLbCons(), SCIPinferVarLbProp(), SCIPintarrayExtend(), SCIPintarraySetVal(), SCIPintervalIntersect(), SCIPintervalIsSubsetEQ(), SCIPintervalMin(), SCIPintervalMulInf(), SCIPintervalPowerScalarInverse(), SCIPintervalQuadBivar(), SCIPintervalSolveBivariateQuadExpressionAllScalar(), SCIPintervalUnify(), SCIPlpGetRootObjval(), SCIPlpGetSol(), SCIPlpGetUnboundedSol(), SCIPlpiGetSolverName(), SCIPlpiSetIntpar(), SCIPlpShrinkCols(), SCIPlpShrinkRows(), SCIPlpSolveAndEval(), SCIPnlpiOracleGetJacobianSparsity(), SCIPnlrowCreate(), SCIPnlrowGetNLPFeasibility(), SCIPnlrowGetPseudoFeasibility(), SCIPnlrowGetSolActivity(), SCIPnlrowGetSolFeasibility(), SCIPnodeAddBoundinfer(), SCIPnodeCutoff(), SCIPnodeFocus(), SCIPnodePropagateAgain(), SCIPparamSetReal(), SCIPprimalUpdateObjlimit(), SCIPprimalUpdateObjoffset(), SCIPprobUpdateDualbound(), SCIPptrarrayExtend(), SCIPptrarraySetVal(), SCIPrealarrayExtend(), SCIPrealarraySetVal(), SCIPrealToRational(), SCIPresolveSolHeurSubNlp(), SCIProwCalcIntegralScalar(), SCIProwGetLPActivity(), SCIProwGetLPFeasibility(), SCIProwGetNLPFeasibility(), SCIProwGetObjParallelism(), SCIProwGetPseudoActivity(), SCIProwGetPseudoFeasibility(), SCIProwGetRelaxFeasibility(), SCIProwGetSolActivity(), SCIProwGetSolFeasibility(), SCIPselectVarPseudoStrongBranching(), SCIPselectVarStrongBranching(), SCIPsetCutoffbounddelta(), SCIPsetIsLbBetter(), SCIPsetIsUbBetter(), SCIPsetLpfeastol(), SCIPsolveCIP(), SCIPstoreSolutionGap(), SCIPtightenVarLb(), SCIPtightenVarLbGlobal(), SCIPtreeBranchVar(), SCIPtreeBranchVarNary(), SCIPtreeCalcChildEstimate(), SCIPtreeGetLowerbound(), SCIPvarChgLbGlobal(), SCIPvarChgLbLocal(), SCIPvarGetAvgSol(), SCIPvarGetMultaggrUbGlobal(), SCIPvarGetMultaggrUbLocal(), SCIPvarIsBinary(), SCIPvboundsAdd(), selectShifting(), separateCons(), separateCuts(), separateGLS(), separateHeur(), separatePoint(), separateSequLiftedMinimalCoverInequality(), sepastoreIsBdchgApplicable(), sequentialUpAndDownLifting(), sequentialUpAndDownLiftingGUB(), solveDerivativeEquation(), solveNode(), solveSubMIP(), solveSubNLP(), solveSubproblem(), solveSubscip(), sortVariables(), splitProblem(), tightenBounds(), tightenCoefs(), tightenLbTTEF(), tightenUbTTEF(), tightenWeightsLift(), turnoffNodeSelector(), updateEstimate(), varAddTransitiveBinaryClosureImplic(), varAddTransitiveImplic(), varProcessChgLbLocal(), varRemoveImplicsVbs(), and varUpdateAggregationBounds().

#define CHUNKLENGTH_MIN   1024

minimal size of a chunk (in bytes)

Definition at line 466 of file memory.c.

Referenced by createChunk().

#define CHUNKLENGTH_MAX   1048576

maximal size of a chunk (in bytes)

Definition at line 467 of file memory.c.

Referenced by createChunk().

#define STORESIZE_MAX   8192

maximal number of elements in one chunk

Definition at line 468 of file memory.c.

Referenced by createChunk().

#define GARBAGE_SIZE   256

size of lazy free list to start garbage collection

Definition at line 469 of file memory.c.

Referenced by freeChkmemElement().

#define ALIGNMENT   (sizeof(FREELIST))

minimal alignment of chunks

Definition at line 470 of file memory.c.

Referenced by alignSize(), BMSalignMemsize(), and BMSisAligned().

#define checkChunk (   chunk)

Definition at line 715 of file memory.c.

Referenced by allocChunkElement(), and freeChunkElement().

#define checkChkmem (   chkmem)
#define CHKHASH_SIZE   1013
#define checkBlkmem (   blkmem)

Definition at line 1497 of file memory.c.

Referenced by BMSallocBlockMemory_call(), and BMSfreeBlockMemory_call().

Typedef Documentation

typedef struct Freelist FREELIST

linked list of free memory elements

Definition at line 472 of file memory.c.

typedef struct Chunk CHUNK

chunk of memory elements

Definition at line 473 of file memory.c.

Function Documentation

size_t BMSgetPointerSize_call ( const void *  ptr)

returns the size of an allocated memory element

Parameters
ptrpointer to allocated memory

Definition at line 242 of file memory.c.

void BMSdisplayMemory_call ( void  )

outputs information about currently allocated memory to the screen

Definition at line 250 of file memory.c.

References printInfo.

void BMScheckEmptyMemory_call ( void  )

displays a warning message on the screen, if allocated memory exists

Definition at line 260 of file memory.c.

References printInfo.

long long BMSgetMemoryUsed_call ( void  )

returns total number of allocated bytes

Definition at line 270 of file memory.c.

void* BMSallocClearMemory_call ( size_t  num,
size_t  size,
const char *  filename,
int  line 
)

allocates memory and initializes it with 0; returns NULL if memory allocation failed

Parameters
numnumber of memory element to allocate
sizesize of one memory element to allocate
filenamesource file where the allocation is performed
lineline number in source file where the allocation is performed

Definition at line 280 of file memory.c.

References debugMessage, MAX, NULL, printError, and printErrorHeader.

void* BMSallocMemory_call ( size_t  size,
const char *  filename,
int  line 
)

allocates memory; returns NULL if memory allocation failed

Parameters
sizesize of memory element to allocate
filenamesource file where the allocation is performed
lineline number in source file where the allocation is performed

Definition at line 309 of file memory.c.

References debugMessage, MAX, NULL, printError, and printErrorHeader.

Referenced by BMSduplicateMemory_call().

void* BMSreallocMemory_call ( void *  ptr,
size_t  size,
const char *  filename,
int  line 
)

allocates memory; returns NULL if memory allocation failed

Parameters
ptrpointer to memory to reallocate
sizenew size of memory element
filenamesource file where the reallocation is performed
lineline number in source file where the reallocation is performed

Definition at line 336 of file memory.c.

References MAX, NULL, printError, and printErrorHeader.

void BMSclearMemory_call ( void *  ptr,
size_t  size 
)

clears a memory element (i.e. fills it with zeros)

Parameters
ptrpointer to memory element
sizesize of memory element

Definition at line 369 of file memory.c.

References NULL.

void BMScopyMemory_call ( void *  ptr,
const void *  source,
size_t  size 
)

copies the contents of one memory element into another memory element

Parameters
ptrpointer to target memory element
sourcepointer to source memory element
sizesize of memory element to copy

Definition at line 382 of file memory.c.

References NULL.

Referenced by BMSduplicateMemory_call().

void BMSmoveMemory_call ( void *  ptr,
const void *  source,
size_t  size 
)

moves the contents of one memory element into another memory element, should be used if both elements overlap, otherwise BMScopyMemory is faster

Parameters
ptrpointer to target memory element
sourcepointer to source memory element
sizesize of memory element to copy

Definition at line 399 of file memory.c.

References NULL.

void* BMSduplicateMemory_call ( const void *  source,
size_t  size,
const char *  filename,
int  line 
)

allocates memory and copies the contents of the given memory element into the new memory element

Parameters
sourcepointer to source memory element
sizesize of memory element to copy
filenamesource file where the duplication is performed
lineline number in source file where the duplication is performed

Definition at line 414 of file memory.c.

References BMSallocMemory_call(), BMScopyMemory_call(), and NULL.

void BMSfreeMemory_call ( void *  ptr,
const char *  filename,
int  line 
)

frees an allocated memory element

Parameters
ptrpointer to memory element
filenamesource file where the deallocation is performed
lineline number in source file where the deallocation is performed

Definition at line 433 of file memory.c.

References NULL, printError, and printErrorHeader.

static void alignSize ( size_t *  size)
static

aligns the given byte size corresponding to the minimal alignment

Parameters
sizepointer to the size to align

Definition at line 524 of file memory.c.

References ALIGNMENT.

Referenced by BMSalignMemsize(), BMSallocBlockMemory_call(), BMScreateChunkMemory_call(), BMSfreeBlockMemory_call(), and BMSreallocBlockMemory_call().

void BMSalignMemsize ( size_t *  size)

aligns the given byte size corresponding to the minimal alignment for chunk and block memory

Parameters
sizepointer to the size to align

Definition at line 535 of file memory.c.

References ALIGNMENT, and alignSize().

int BMSisAligned ( size_t  size)

checks whether the given size meets the alignment conditions for chunk and block memory

Parameters
sizesize to check for alignment

Definition at line 544 of file memory.c.

References ALIGNMENT.

Referenced by createChkmem(), createChunk(), and getHashNumber().

static int isPtrInChunk ( const CHUNK chunk,
const void *  ptr 
)
static

checks, if the given pointer belongs to the given chunk

Parameters
chunkmemory chunk
ptrpointer

Definition at line 555 of file memory.c.

References NULL.

Referenced by freeChunkElement().

static CHUNK* findChunk ( const BMS_CHKMEM chkmem,
const void *  ptr 
)
static

given a pointer, finds the chunk this pointer points to in the chunk array of the given chunk block; binary search is used; returns NULL if the pointer does not belong to the chunk block

Parameters
chkmemchunk block
ptrpointer

Definition at line 572 of file memory.c.

References NULL.

Referenced by garbagecollectChkmem(), and isPtrInChkmem().

static int isPtrInChkmem ( const BMS_CHKMEM chkmem,
const void *  ptr 
)
static

checks, if a pointer belongs to a chunk of the given chunk block

Parameters
chkmemchunk block
ptrpointer

Definition at line 608 of file memory.c.

References findChunk(), and NULL.

Referenced by findChkmem(), and freeChkmemElement().

static int linkChunk ( BMS_CHKMEM chkmem,
CHUNK chunk 
)
static

links chunk to the block's chunk array, sort it by store pointer; returns TRUE if successful, FALSE otherwise

Parameters
chkmemchunk block
chunkmemory chunk

Definition at line 724 of file memory.c.

References BMSreallocMemoryArray, debugMessage, FALSE, NULL, and TRUE.

Referenced by createChunk().

static void unlinkChunk ( CHUNK chunk)
static

unlinks chunk from the chunk block's chunk list

Parameters
chunkmemory chunk

Definition at line 796 of file memory.c.

References debugMessage, and NULL.

Referenced by freeChunk().

static void linkEagerChunk ( BMS_CHKMEM chkmem,
CHUNK chunk 
)
static

links chunk to the chunk block's eager chunk list

Parameters
chkmemchunk block
chunkmemory chunk

Definition at line 829 of file memory.c.

References NULL.

Referenced by freeChunkElement().

static void unlinkEagerChunk ( CHUNK chunk)
static

unlinks chunk from the chunk block's eager chunk list

Parameters
chunkmemory chunk

Definition at line 850 of file memory.c.

References NULL.

Referenced by allocChunkElement(), and freeChunk().

static int createChunk ( BMS_CHKMEM chkmem)
static

creates a new memory chunk in the given chunk block and adds memory elements to the lazy free list; returns TRUE if successful, FALSE otherwise

Parameters
chkmemchunk block

Definition at line 875 of file memory.c.

References BMSallocMemorySize, BMSisAligned(), checkChkmem, CHUNKLENGTH_MAX, CHUNKLENGTH_MIN, debugMessage, FALSE, linkChunk(), MAX, MIN, NULL, and STORESIZE_MAX.

Referenced by allocChkmemElement().

static void destroyChunk ( CHUNK chunk)
static

destroys a chunk without updating the chunk lists

Parameters
chunkmemory chunk

Definition at line 946 of file memory.c.

References BMSfreeMemory, debugMessage, and NULL.

Referenced by clearChkmem(), and freeChunk().

static void freeChunk ( CHUNK chunk)
static

removes a completely unused chunk, i.e. a chunk with all elements in the eager free list

Parameters
chunkmemory chunk

Definition at line 960 of file memory.c.

References debugMessage, destroyChunk(), NULL, unlinkChunk(), and unlinkEagerChunk().

Referenced by garbagecollectChkmem().

static void* allocChunkElement ( CHUNK chunk)
static

returns an element of the eager free list and removes it from the list

Parameters
chunkmemory chunk

Definition at line 990 of file memory.c.

References checkChunk, debugMessage, NULL, and unlinkEagerChunk().

Referenced by allocChkmemElement().

static void freeChunkElement ( CHUNK chunk,
void *  ptr 
)
static

puts given pointer into the eager free list and adds the chunk to the eager list of its chunk block, if necessary

Parameters
chunkmemory chunk
ptrpointer

Definition at line 1027 of file memory.c.

References checkChunk, debugMessage, isPtrInChunk(), linkEagerChunk(), and NULL.

Referenced by garbagecollectChkmem().

static BMS_CHKMEM* createChkmem ( int  size,
int  initchunksize,
int  garbagefactor 
)
static

creates a new chunk block data structure

Parameters
sizeelement size of the chunk block
initchunksizenumber of elements in the first chunk of the chunk block
garbagefactorgarbage collector is called, if at least garbagefactor * avg. chunksize elements are free (-1: disable garbage collection)

Definition at line 1056 of file memory.c.

References BMSallocMemory, BMSisAligned(), and NULL.

Referenced by BMSallocBlockMemory_call(), and BMScreateChunkMemory_call().

static void clearChkmem ( BMS_CHKMEM chkmem)
static

destroys all chunks of the chunk block, but keeps the chunk block header structure

Parameters
chkmemchunk block

Definition at line 1096 of file memory.c.

References destroyChunk(), and NULL.

Referenced by BMSclearChunkMemory_call(), destroyChkmem(), and garbagecollectChkmem().

static void destroyChkmem ( BMS_CHKMEM **  chkmem)
static

deletes chunk block and frees all associated memory chunks

Parameters
chkmempointer to chunk block

Definition at line 1119 of file memory.c.

References BMSfreeMemory, BMSfreeMemoryArrayNull, clearChkmem(), and NULL.

Referenced by BMSclearBlockMemory_call(), BMSdestroyChunkMemory_call(), and BMSgarbagecollectBlockMemory_call().

static void* allocChkmemElement ( BMS_CHKMEM chkmem)
static

allocates a new memory element from the chunk block

Parameters
chkmemchunk block

Definition at line 1138 of file memory.c.

References allocChunkElement(), checkChkmem, createChunk(), and NULL.

Referenced by BMSallocBlockMemory_call(), and BMSallocChunkMemory_call().

static void garbagecollectChkmem ( BMS_CHKMEM chkmem)
static

sorts the lazy free list of the chunk block into the eager free lists of the chunks, and removes completely unused chunks

Parameters
chkmemchunk block

Definition at line 1177 of file memory.c.

References checkChkmem, clearChkmem(), debugMessage, errorMessage, findChunk(), freeChunk(), freeChunkElement(), and NULL.

Referenced by BMSgarbagecollectBlockMemory_call(), BMSgarbagecollectChunkMemory_call(), and freeChkmemElement().

static void freeChkmemElement ( BMS_CHKMEM chkmem,
void *  ptr,
const char *  filename,
int  line 
)
static

frees a memory element and returns it to the lazy freelist of the chunk block

Parameters
chkmemchunk block
ptrmemory element
filenamesource file of the function call
lineline number in source file of the function call

Definition at line 1244 of file memory.c.

References checkChkmem, GARBAGE_SIZE, garbagecollectChkmem(), isPtrInChkmem(), NULL, printError, and printErrorHeader.

Referenced by BMSfreeBlockMemory_call(), and BMSfreeChunkMemory_call().

BMS_CHKMEM* BMScreateChunkMemory_call ( size_t  size,
int  initchunksize,
int  garbagefactor,
const char *  filename,
int  line 
)

creates a new chunk block data structure

Parameters
sizeelement size of the chunk block
initchunksizenumber of elements in the first chunk of the chunk block
garbagefactorgarbage collector is called, if at least garbagefactor * avg. chunksize elements are free (-1: disable garbage collection)
filenamesource file of the function call
lineline number in source file of the function call

Definition at line 1283 of file memory.c.

References alignSize(), createChkmem(), debugMessage, NULL, printError, and printErrorHeader.

void BMSclearChunkMemory_call ( BMS_CHKMEM chkmem,
const char *  filename,
int  line 
)

clears a chunk block data structure

Parameters
chkmemchunk block
filenamesource file of the function call
lineline number in source file of the function call

Definition at line 1307 of file memory.c.

References clearChkmem(), debugMessage, NULL, printError, and printErrorHeader.

void BMSdestroyChunkMemory_call ( BMS_CHKMEM **  chkmem,
const char *  filename,
int  line 
)

destroys and frees a chunk block data structure

Parameters
chkmempointer to chunk block
filenamesource file of the function call
lineline number in source file of the function call

Definition at line 1325 of file memory.c.

References debugMessage, destroyChkmem(), NULL, printError, and printErrorHeader.

void* BMSallocChunkMemory_call ( BMS_CHKMEM chkmem,
size_t  size,
const char *  filename,
int  line 
)

allocates a memory element of the given chunk block

Parameters
chkmemchunk block
sizesize of memory element to allocate (only needed for sanity check)
filenamesource file of the function call
lineline number in source file of the function call

Definition at line 1345 of file memory.c.

References allocChkmemElement(), checkChkmem, debugMessage, NULL, printError, and printErrorHeader.

Referenced by BMSduplicateChunkMemory_call().

void* BMSduplicateChunkMemory_call ( BMS_CHKMEM chkmem,
const void *  source,
size_t  size,
const char *  filename,
int  line 
)

duplicates a given memory element by allocating a new element of the same chunk block and copying the data

Parameters
chkmemchunk block
sourcesource memory element
sizesize of memory element to allocate (only needed for sanity check)
filenamesource file of the function call
lineline number in source file of the function call

Definition at line 1372 of file memory.c.

References BMSallocChunkMemory_call(), BMScopyMemorySize, and NULL.

void BMSfreeChunkMemory_call ( BMS_CHKMEM chkmem,
void *  ptr,
size_t  size,
const char *  filename,
int  line 
)

frees a memory element of the given chunk block

Parameters
chkmemchunk block
ptrmemory element to free
sizesize of memory element to allocate (only needed for sanity check)
filenamesource file of the function call
lineline number in source file of the function call

Definition at line 1394 of file memory.c.

References checkChkmem, debugMessage, freeChkmemElement(), NULL, printError, and printErrorHeader.

void BMSgarbagecollectChunkMemory_call ( BMS_CHKMEM chkmem)

calls garbage collection of chunk block and frees chunks without allocated memory elements

Parameters
chkmemchunk block

Definition at line 1421 of file memory.c.

References debugMessage, and garbagecollectChkmem().

long long BMSgetChunkMemoryUsed_call ( const BMS_CHKMEM chkmem)

returns the number of allocated bytes in the chunk block

Parameters
chkmemchunk block

Definition at line 1431 of file memory.c.

References NULL.

static BMS_CHKMEM* findChkmem ( const BMS_BLKMEM blkmem,
const void *  ptr 
)
static

finds the chunk block, to whick the given pointer belongs to; this could be done by selecting the chunk block of the corresponding element size, but in a case of an error (free gives an incorrect element size), we want to identify and output the correct element size

Parameters
blkmemblock memory
ptrmemory element to search

Definition at line 1506 of file memory.c.

References CHKHASH_SIZE, isPtrInChkmem(), and NULL.

Referenced by BMSgetBlockPointerSize_call().

static int getHashNumber ( int  size)
static

calculates hash number of memory size

Parameters
sizeelement size

Definition at line 1529 of file memory.c.

References BMSisAligned().

Referenced by BMSallocBlockMemory_call(), and BMSfreeBlockMemory_call().

BMS_BLKMEM* BMScreateBlockMemory_call ( int  initchunksize,
int  garbagefactor,
const char *  filename,
int  line 
)

creates a block memory allocation data structure

Parameters
initchunksizenumber of elements in the first chunk of each chunk block
garbagefactorgarbage collector is called, if at least garbagefactor * avg. chunksize elements are free (-1: disable garbage collection)
filenamesource file of the function call
lineline number in source file of the function call

Definition at line 1539 of file memory.c.

References BMSallocMemory, CHKHASH_SIZE, NULL, printError, and printErrorHeader.

void BMSclearBlockMemory_call ( BMS_BLKMEM blkmem,
const char *  filename,
int  line 
)

frees all chunk blocks in the block memory

Parameters
blkmemblock memory
filenamesource file of the function call
lineline number in source file of the function call

Definition at line 1569 of file memory.c.

References CHKHASH_SIZE, destroyChkmem(), NULL, printError, and printErrorHeader.

Referenced by BMSdestroyBlockMemory_call().

void BMSdestroyBlockMemory_call ( BMS_BLKMEM **  blkmem,
const char *  filename,
int  line 
)

clears and deletes block memory

Parameters
blkmempointer to block memory
filenamesource file of the function call
lineline number in source file of the function call

Definition at line 1602 of file memory.c.

References BMSclearBlockMemory_call(), BMSfreeMemory, NULL, printError, and printErrorHeader.

void* BMSallocBlockMemory_call ( BMS_BLKMEM blkmem,
size_t  size,
const char *  filename,
int  line 
)

allocates memory in the block memory pool

Parameters
blkmemblock memory
sizesize of memory element to allocate
filenamesource file of the function call
lineline number in source file of the function call

Definition at line 1624 of file memory.c.

References alignSize(), allocChkmemElement(), BMSduplicateMemoryArray, checkBlkmem, createChkmem(), debugMessage, getHashNumber(), NULL, printError, and printErrorHeader.

Referenced by BMSduplicateBlockMemory_call(), and BMSreallocBlockMemory_call().

void* BMSreallocBlockMemory_call ( BMS_BLKMEM blkmem,
void *  ptr,
size_t  oldsize,
size_t  newsize,
const char *  filename,
int  line 
)

resizes memory element in the block memory pool, and copies the data

Parameters
blkmemblock memory
ptrmemory element to reallocated
oldsizeold size of memory element
newsizenew size of memory element
filenamesource file of the function call
lineline number in source file of the function call

Definition at line 1679 of file memory.c.

References alignSize(), BMSallocBlockMemory_call(), BMScopyMemorySize, BMSfreeBlockMemory_call(), MIN, and NULL.

void* BMSduplicateBlockMemory_call ( BMS_BLKMEM blkmem,
const void *  source,
size_t  size,
const char *  filename,
int  line 
)

duplicates memory element in the block memory pool, and copies the data

Parameters
blkmemblock memory
sourcememory element to duplicate
sizesize of memory elements
filenamesource file of the function call
lineline number in source file of the function call

Definition at line 1710 of file memory.c.

References BMSallocBlockMemory_call(), BMScopyMemorySize, and NULL.

void BMSfreeBlockMemory_call ( BMS_BLKMEM blkmem,
void *  ptr,
size_t  size,
const char *  filename,
int  line 
)

frees memory element in the block memory pool

Parameters
blkmemblock memory
ptrmemory element to free
sizesize of memory element
filenamesource file of the function call
lineline number in source file of the function call

Definition at line 1730 of file memory.c.

References alignSize(), checkBlkmem, debugMessage, freeChkmemElement(), getHashNumber(), NULL, printError, and printErrorHeader.

Referenced by BMSreallocBlockMemory_call().

void BMSgarbagecollectBlockMemory_call ( BMS_BLKMEM blkmem)

calls garbage collection of block memory, frees chunks without allocated memory elements, and frees chunk blocks without any chunks

Parameters
blkmemblock memory

Definition at line 1783 of file memory.c.

References CHKHASH_SIZE, destroyChkmem(), garbagecollectChkmem(), and NULL.

long long BMSgetBlockMemoryUsed_call ( const BMS_BLKMEM blkmem)

returns the number of allocated bytes in the block memory

Parameters
blkmemblock memory

Definition at line 1814 of file memory.c.

References NULL.

size_t BMSgetBlockPointerSize_call ( const BMS_BLKMEM blkmem,
const void *  ptr 
)

returns the size of the given memory element; returns 0, if the element is not member of the block memory

Parameters
blkmemblock memory
ptrmemory element

Definition at line 1824 of file memory.c.

References findChkmem(), and NULL.

void BMSdisplayBlockMemory_call ( const BMS_BLKMEM blkmem)

outputs allocation diagnostics of block memory

Parameters
blkmemblock memory

Definition at line 1844 of file memory.c.

References CHKHASH_SIZE, NULL, and printInfo.

void BMScheckEmptyBlockMemory_call ( const BMS_BLKMEM blkmem)

outputs warning messages, if there are allocated elements in the block memory

Parameters
blkmemblock memory

Definition at line 1967 of file memory.c.

References CHKHASH_SIZE, NULL, and printInfo.