1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
/****************************************************************************
* *
* Loki - Programs for genetic analysis of complex traits using MCMC *
* *
* Simon Heath - University of Washington *
* *
* March 1997 *
* *
* remember.c: *
* *
* Routines for keeping track of allocated memory that is used in weird *
* ways so that it is not easy to keep track of it. *
* *
* Copyright (C) Simon C. Heath 1997, 2000, 2002 *
* This is free software. You can distribute it and/or modify it *
* under the terms of the Modified BSD license, see the file COPYING *
* *
****************************************************************************/
#include <stdlib.h>
#ifdef USE_DMALLOC
#include <dmalloc.h>
#endif
#include <stdio.h>
#include "utils.h"
#include "loki_struct.h"
#ifdef FUNC_NAME
#undef FUNC_NAME
#endif
#define FUNC_NAME "AddRemem"
/* Adds a memory pointer (from malloc()) to list. Used by FreeStuff()
* So all can be free()'d with one call */
struct remember *AddRemem(void *p,struct remember *rblock)
{
struct remember *pr;
if(!p || !rblock) ABT_FUNC("Called with zero pointer\n");
if(rblock->pos==REMSIZE) {
if(!(pr=malloc(sizeof(struct remember)))) ABT_FUNC(MMsg);
rblock->next=pr;
rblock=pr;
rblock->pos=0;
rblock->next=0;
}
rblock->mem[rblock->pos++]=p;
return rblock;
}
void FreeRemem(struct remember *rblock)
{
int i;
struct remember *pr;
while(rblock) {
pr=rblock->next;
for(i=0;i<rblock->pos;i++) {
free(rblock->mem[i]);
}
free(rblock);
rblock=pr;
}
}
|