void * EiC_ymalloc(char *file, int lineno, size_t nbytes) { void * pheap; pheap = (malloc)(nbytes); assertp(pheap==NULL,STDMSG); install(file,lineno,pheap,nbytes); return pheap; }
int EiC_ymark(char *file, int lineno, void *p, char mark) { int found; found = xlookup(p); assertp(found < 0,STDMSG); MTAB[BNO(p)].dbuf[found].mark = mark; return 1; }
void * EiC_yrealloc(char *file, int lineno, void *oldp, size_t nbytes) { void *newp; int found, d; if(oldp != NULL) { found = xlookup(oldp); assertp(found < 0,STDMSG); } newp = realloc(oldp,nbytes); assertp(nbytes && newp == NULL,("line %d in file %s\n",lineno,file)); if(oldp) { int bno = BNO(oldp); d = nbytes - MTAB[bno].dbuf[found].nbytes; if(bno != BNO(newp)) { int i; MTAB[bno].dbuf[found].p = NULL; MTAB[bno].dbuf[found].mark = freemark; i = install(file,lineno,newp,nbytes); /* retain creation time stamp */ MTAB[BNO(newp)].dbuf[i].alloc_num = MTAB[bno].dbuf[found].alloc_num; } else { MTAB[bno].dbuf[found].p = newp; MTAB[bno].dbuf[found].nbytes = nbytes; MTAB[bno].dbuf[found].crt_file = file; MTAB[bno].dbuf[found].crt_lineno = lineno; } EiC_tot_memory += d; } else install(file,lineno,newp,nbytes); return newp; }
/** * Builds a new memory handler. * @return Memory handler or NULL if there is not enough memory. * @ingroup memory */ gliss_memory_t *gliss_mem_new(void) { unsigned int i; memory_16_t *mem; mem = malloc(sizeof(memory_16_t)); assertp(mem != NULL, "no more memory") /* allocate 2^16 bytes right away, no paging system needed */ mem->storage = malloc(MEM16_SIZE * sizeof(uint8_t)); return mem; }
static int install(char *file, int lineno, void *p, size_t nbytes) { int bno; unsigned i; extern int EiC_memtraceON; bno = BNO(p); for(i=0;i<MTAB[bno].dbuf_no;++i) { /* search for empty slot */ if(MTAB[bno].dbuf[i].p == NULL) break; } if(i >= MTAB[bno].top) { MTAB[bno].top += BUFINC; if(!MTAB[bno].dbuf) { MTAB[bno].dbuf = (XALLOC*)(calloc)(sizeof(XALLOC),BUFINC + 1); } else { MTAB[bno].dbuf = (XALLOC*)realloc(MTAB[bno].dbuf, sizeof(XALLOC) * (MTAB[bno].top+1)); } } assertp(MTAB[bno].dbuf == NULL,("Out of Memory")); MTAB[bno].dbuf[i].p = p; MTAB[bno].dbuf[i].nbytes = nbytes; MTAB[bno].dbuf[i].mark = XGMARK; MTAB[bno].dbuf[i].crt_file = file; MTAB[bno].dbuf[i].crt_lineno = lineno; EiC_tot_memory += nbytes; EiC_tot_alloc++; if(i>=MTAB[bno].dbuf_no) MTAB[bno].dbuf_no++; MTAB[bno].dbuf[i].alloc_num = ++tot_seen; if(EiC_memtraceON) printf("%lu ",(unsigned long)tot_seen); return i; }
/** * Build a new memory handler. * @return Memory handler or NULL if there is not enough memory. * @ingroup memory */ gliss_memory_t* gliss_mem_new(void) { unsigned int i; memory_64_t* mem; /* allocate memory */ mem = (memory_64_t *)calloc(sizeof(memory_64_t), 1); assertp(mem != NULL, "no more memory") /* initialize spy */ # ifdef GLISS_MEM_SPY mem->spy_fun = gliss_mem_default_spy; mem->spy_data = 0; # endif return (gliss_memory_t*) mem; }
void * EiC_ymalloc(char *file, int lineno, size_t nbytes) { void * pheap; if(GetGameMode()) { unsigned long total = EiC_tot_memory + nbytes; if(total > gedMaxGameMem) //maks { //Don't alloc more then gedMaxGameMem EiC_error("Attempt to access %lu bytes.\n If is correct, set the variable gedMaxGameMem=%lu or more\n in an action before the allocation", nbytes, total); nbytes = 4; } } realAllocatedMem = nbytes; pheap = (malloc)(nbytes); if(pheap) memset(pheap,0, realAllocatedMem/*nelems * elems*/); //maks assertp(pheap==NULL,STDMSG); install(file,lineno,pheap,nbytes); return pheap; }
void * EiC_yrealloc(char *file, int lineno, void *oldp, size_t nbytes) { void *newp; int found = 0, d, bOld = 0, bno = 0; //maks if(nbytes <= 0 && oldp) { //maks: realloc definition EiC_yfree(file, lineno, oldp); return 0; } if(oldp != NULL) { found = xlookup(oldp); assertp(found < 0,STDMSG); bOld = 1; //maks bno = BNO(oldp); } if(GetGameMode()) { unsigned long total = EiC_tot_memory + nbytes; if(total > gedMaxGameMem) //maks { //Don't alloc more then gedMaxGameMem EiC_error("Attempt to access %lu bytes.\n If is correct, set the variable gedMaxGameMem=%lu or more\n in an action before the allocation", nbytes, total); nbytes = 4; } } realAllocatedMem = nbytes; newp = realloc(oldp,nbytes); assertp(nbytes && newp == NULL,("line %d in file %s\n",lineno,file)); if(bOld) //maks { d = nbytes - MTAB[bno].dbuf[found].nbytes; EiC_tot_memory -= MTAB[bno].dbuf[found].nbytes; //maks if(bno != BNO(newp)) { int i; MTAB[bno].dbuf[found].p = NULL; MTAB[bno].dbuf[found].mark = freemark; i = install(file,lineno,newp,nbytes); /* retain creation time stamp */ MTAB[BNO(newp)].dbuf[i].alloc_num = MTAB[bno].dbuf[found].alloc_num; } else { MTAB[bno].dbuf[found].p = newp; MTAB[bno].dbuf[found].nbytes = nbytes; MTAB[bno].dbuf[found].crt_file = file; MTAB[bno].dbuf[found].crt_lineno = lineno; EiC_tot_memory += nbytes; //maks } } else { install(file,lineno,newp,nbytes); } return newp; }
/** * Writes a double float in memory. * @param memory Memory to write in. * @param address Address to write float to. * @param val Float to write. * @ingroup memory */ void gliss_mem_writeld(gliss_memory_t *memory, gliss_address_t address, long double val) { assertp(0, "not implemented"); }
/** * Reads a long double float value. * @param memory Memory to work with. * @param address Address of float to read. * @return Read float. * @ingroup memory */ long double gliss_mem_readld(gliss_memory_t *memory, gliss_address_t address) { assertp(0, "not implemented !"); }