Skip to content

Commit

Permalink
Merge pull request #564 from DrylandEcology/remove_DEBUG_MEM_function…
Browse files Browse the repository at this point in the history
…ality

Remove debug mem functionality
  • Loading branch information
alexisBelt authored Oct 12, 2023
2 parents 1378631 + f5b3981 commit 6060363
Show file tree
Hide file tree
Showing 9 changed files with 1 addition and 277 deletions.
7 changes: 0 additions & 7 deletions ST_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,4 @@ void Indiv_SortSize( const byte sorttype,
int Indiv_CompSize_A( const void *key1, const void *key2);
int Indiv_CompSize_D( const void *key1, const void *key2);

#ifdef DEBUG_MEM
void RGroup_SetMemoryRefs(void);
void Species_SetMemoryRefs(void);
void Parm_SetMemoryRefs(void);
void Stat_SetMemoryRefs(void);
#endif

#endif
6 changes: 1 addition & 5 deletions ST_indivs.c
Original file line number Diff line number Diff line change
Expand Up @@ -435,11 +435,7 @@ void _delete (IndivType *ndv)

sp = ndv->myspecies;
s = Species[sp];

#ifdef DEBUG_MEM
assert(fValidPointer(ndv, sizeof(IndivType)));
#endif


/* Detach indiv's data object from list */
if (ndv == s->IndvHead) {
if (ndv->Next == NULL)
Expand Down
32 changes: 0 additions & 32 deletions ST_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,6 @@
void files_init(void);
void maxrgroupspecies_init(void);

#ifdef DEBUG_MEM
#define chkmem_f CheckMemoryIntegrity(FALSE);
#define chkmem_t CheckMemoryIntegrity(TRUE);
void CheckMemoryIntegrity(Bool flag); /* local */
void Stat_NoteMemoryRefs(void) ;
#else
#define chkmem_f
#define chkmem_t
#endif

/*************** Local Function Declarations ***************/
/***********************************************************/
void Plot_Initialize( void);
Expand Down Expand Up @@ -797,28 +787,6 @@ void check_sizes(const char *chkpt) {

}

#ifdef DEBUG_MEM
void CheckMemoryIntegrity(Bool flag) {
// DLM - 6/6/2013 : NOTE - The dynamically allocated variables added for the new grid option are not accounted for here. I haven't bothered to add them because it would add a ton of code and I haven't been using the code to facilitate debugging of memory. Instead I have been using the valgrind program to debug my memory, as I feel like it is a better solution. If wanting to use this code to debug memory, memory references would probably have to be set up for the dynamically allocated variables in ST_grid.c as well as the new dynamically allocated grid_Stat variable in ST_stats.c.


ClearMemoryRefs();

if (flag || Globals.currIter > 1 || Globals.currYear > 1)
Stat_SetMemoryRefs();

RGroup_SetMemoryRefs();
Species_SetMemoryRefs();
Parm_SetMemoryRefs();

SXW_SetMemoryRefs();
CheckMemoryRefs();

}
#endif



#ifdef DEBUG_GROW
/**************************************************************/
void Debug_AddByIter( Int iter) {
Expand Down
36 changes: 0 additions & 36 deletions ST_params.c
Original file line number Diff line number Diff line change
Expand Up @@ -1253,39 +1253,3 @@ void parm_free_memory( void ) {
for(i = 0; i < NFILES; i++)
Mem_Free(_files[i]);
}



#ifdef DEBUG_MEM
#include "sw_src/myMemory.h"
/**************************************************************/
void Parm_SetMemoryRefs( void) {
/*======================================================*/
/* when debugging memory problems, use the bookkeeping
code in myMemory.c
This routine sets the known memory refs in this module
so they can be checked for leaks, etc. All refs will
have been cleared by a call to ClearMemoryRefs() before
this, and will be checked via CheckMemoryRefs() after
this, most likely in the main() function.
EVERY dynamic allocation must be noted here or the
check will fail (which is the point, to catch unknown
or missing pointers to memory).
*/
ST_FileIndex i;
GrpIndex rg;
SppIndex sp;

for(i=F_First; i<= F_MortAvg; i++)
NoteMemoryRef(_files[i]);

ForEachGroup(rg)
NoteMemoryRef( RGroup[rg]->kills);
ForEachSpecies(sp)
NoteMemoryRef( Species[sp]->kills);

NoteMemoryRef(_files[F_SXW]);
}

#endif
29 changes: 0 additions & 29 deletions ST_resgroups.c
Original file line number Diff line number Diff line change
Expand Up @@ -1259,35 +1259,6 @@ IndivType **RGroup_GetIndivs(GrpIndex rg, const char sort, IntS *num)
return nlist;
}

#ifdef DEBUG_MEM
#include "sw_src/myMemory.h"
/*======================================================*/
void RGroup_SetMemoryRefs( void)
{
/* when debugging memory problems, use the bookkeeping
code in myMemory.c
This routine sets the known memory refs in this module
so they can be checked for leaks, etc. All refs will
have been cleared by a call to ClearMemoryRefs() before
this, and will be checked via CheckMemoryRefs() after
this, most likely in the main() function.
EVERY dynamic allocation must be noted here or the
check will fail (which is the point, to catch unknown
or missing pointers to memory).
*/
GrpIndex rg;

ForEachGroup(rg)
{
NoteMemoryRef(RGroup[rg]);
NoteMemoryRef(RGroup[rg]->kills); /* this is set it params() */
}

}

#endif

/* COMMENT 1 - Algorithm for rgroup_PartResources() */
/*
* Assign minimum resources to each group based on relative
Expand Down
37 changes: 0 additions & 37 deletions ST_species.c
Original file line number Diff line number Diff line change
Expand Up @@ -693,40 +693,3 @@ void save_annual_species_relsize() {
}
}
}

#ifdef DEBUG_MEM
#include "sw_src/myMemory.h"
/*======================================================*/
void Species_SetMemoryRefs( void)
{
/* when debugging memory problems, use the bookkeeping
code in myMemory.c
This routine sets the known memory refs in this module
so they can be checked for leaks, etc. All refs will
have been cleared by a call to ClearMemoryRefs() before
this, and will be checked via CheckMemoryRefs() after
this, most likely in the main() function.
EVERY dynamic allocation must be noted here or the
check will fail (which is the point, to catch unknown
or missing pointers to memory).
*/
SppIndex sp;
IndivType *p;

ForEachSpecies(sp)
{
NoteMemoryRef(Species[sp]);
NoteMemoryRef(Species[sp]->kills);
p = Species[sp]->IndvHead;
while (p)
{
NoteMemoryRef(p);
p = p->Next;
}
}

}

#endif
89 changes: 0 additions & 89 deletions ST_stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -1036,92 +1036,3 @@ void make_header( char *buf) {

Mem_Free(fields);
}

#ifdef DEBUG_MEM
void Stat_SetMemoryRefs(void) {
/* when debugging memory problems, use the bookkeeping
code in myMemory.c
This routine sets the known memory refs in this module
so they can be checked for leaks, etc. All refs will
have been cleared by a call to ClearMemoryRefs() before
this, and will be checked via CheckMemoryRefs() after
this, most likely in the main() function.
EVERY dynamic allocation must be noted here or the
check will fail (which is the point, to catch unknown
or missing pointers to memory).
*/

// DLM - 6/6/2013 : NOTE - The dynamically allocated grid_Stat variable is not accounted for here at the moment, it might need adding for this function to work correctly. I've been using the valgrind program to debug memory errors, so I haven't bothered adding them since I haven't been using it.

SppIndex sp;
GrpIndex rg;

if (BmassFlags.graz)
NoteMemoryRef(_Grazed);

ForEachGroup(rg) {
NotememoryRef(_Grazed[rg].s);
}
}

if (BmassFlags.dist)
NoteMemoryRef(_Dist.s);

if (BmassFlags.ppt)
NoteMemoryRef(_Ppt.s);

if (BmassFlags.tmp)
NoteMemoryRef(_Temp.s);

if (BmassFlags.grpb) {
NoteMemoryRef(_Grp);

ForEachGroup(rg)
NoteMemoryRef(_Grp[rg].s);

if (BmassFlags.size) {
NoteMemoryRef(_Gsize);

ForEachGroup(rg)
NoteMemoryRef(_Gsize[rg].s);
}
}

if (MortFlags.group) {
NoteMemoryRef(_Gestab);
ForEachGroup(rg)
NoteMemoryRef(_Gestab[rg].s);

NoteMemoryRef(_Gmort);

ForEachGroup(rg)
NoteMemoryRef(_Gmort[rg].s);
}

if (BmassFlags.sppb || BmassFlags.indv) {
if(BmassFlags.sppb)
NoteMemoryRef(_Spp);
if(BmassFlags.indv)
NoteMemoryRef(_Indv);
ForEachSpecies(sp) {
if (BmassFlasg.sppb)
NoteMemoryRef(_Spp[sp].s);
if (BmassFlags.indv)
NoteMemoryRef(_Indv[sp].s);
}
}

if (MortFlags.species) {
NoteMemoryRef(_Sestab);
ForEachSpecies(sp)
NoteMemoryRef(_Sestab[sp].s);

NoteMemoryRef(_Smort);
ForEachSpecies(sp)
NoteMemoryRef(_Smort[sp].s);
}
}

#endif
37 changes: 0 additions & 37 deletions sxw.c
Original file line number Diff line number Diff line change
Expand Up @@ -1134,43 +1134,6 @@ void _print_debuginfo(void) {
CloseFile(&f, &LogInfo);
}


#ifdef DEBUG_MEM
#include "sw_src/include/myMemory.h"
/*======================================================*/
void SXW_SetMemoryRefs( void) {
/* when debugging memory problems, use the bookkeeping
code in myMemory.c
This routine sets the known memory refs so they can be
checked for leaks, etc. Includes malloc-ed memory from
SXW as well as SOILWAT. All refs will have been cleared
by a call to ClearMemoryRefs() before this, and will be
checked via CheckMemoryRefs() after this, most likely in
the main() function.
*/
TimeInt p;
int i, last = SXW_NFILES-1; /* recall we skipped the first file */

for (i=0; i < last; i++) {
NoteMemoryRef(*_sxwfiles[i]);
}
NoteMemoryRef(_roots_max);
NoteMemoryRef(_roots_rel);
NoteMemoryRef(_roots_current);
NoteMemoryRef(_rootsXphen);
NoteMemoryRef(_roots_active);
NoteMemoryRef(_roots_phen_totals);
NoteMemoryRef(_phen);
NoteMemoryRef(_phen_grp_rel);
NoteMemoryRef(_transp_grp_totals);
NoteMemoryRef(SXW->transp);


SW_CTL_SetMemoryRefs();
}

#endif

/** Convert STEPWAT2 indices of SOILWAT2's vegetation type into a
SOILWAT2 index
Expand Down
5 changes: 0 additions & 5 deletions sxw_funcs.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,4 @@ void SXW_Run_SOILWAT (void);
void SXW_InitPlot (void);
void SXW_PrintDebug(Bool cleanup) ;

#ifdef DEBUG_MEM
void SXW_SetMemoryRefs(void);
#endif


#endif

0 comments on commit 6060363

Please sign in to comment.