示例#1
0
/* gets bit at x,y in m */
int getBit(BitMatrix *m,int x,int y){
    int mask=0;
    calcAddr(&x,&y,&mask);
    /*printf("%d %d %d",x,y,m->bits[y][x]);*/
    return (m->bits[y*m->rowWidth+x]&mask)!=0;
}
示例#2
0
/* sets bit at x,y in m to 0 */
void delBit(BitMatrix *m,int x,int y){
    int mask=0;
    calcAddr(&x,&y,&mask);
    m->bits[y*m->rowWidth+x]&=(~mask);
}
示例#3
0
		void *memReAllocate(const sChar *file, const sU32 line, const allocType type, const sU32 size, void *addr)
		{
		  allocUnit *au;
		  sU32      hashIndex, oldSize, newRealSize;
		  void      *oldAddr, *newRealAddr;

		  FRASSERT(size<MAXALLOC);

		  if (!addr)
		    return memAllocate(file, line, type, size);

		  au=findUnit(addr);
		  if (!au)
		  {
				fr::debugOut("%s : trying to realloc nonallocated memory\n", formatOwner(file, line));
		    sourceFile="include_debug_h_everywhere_please.cpp";
		    sourceLine=303;
		    return 0;
		  }

		  if (type!=au->type)
				fr::debugOut("%s : allocation and reallocation types mismatch (%s vs %s)\n", formatOwner(file, line), atypes[au->type], atypes[type]);

		  oldSize=au->size;
		  oldAddr=au->addr;
		  newRealSize=calcRealSize(size);
		  newRealAddr=realloc(au->realAddr, newRealSize);

		  stats.curAlloc-=au->size;
		  stats.curRealAlloc-=au->realSize;

		  au->realSize=newRealSize;
		  au->realAddr=newRealAddr;
		  au->size=calcSize(newRealSize);
		  au->addr=calcAddr(newRealAddr);
		  au->type=type;
		  au->line=line;
		  if (file)
		    strncpy(au->file, file, 63);
		  else
		    strcpy(au->file, "???");

		  hashIndex=0xffffffff;
		  if (oldAddr!=au->addr)
		  {
		    hashIndex=((sU32) oldAddr>>4) & ALLOCHASHMASK;

		    if (allocHash[hashIndex]==au)
		      allocHash[hashIndex]=au->next;
		    else
		    {
		      if (au->prev) au->prev->next=au->next;
		      if (au->next) au->next->prev=au->prev;
		    }

		    hashIndex=((sU32) au->addr>>4) & ALLOCHASHMASK;
		    if (allocHash[hashIndex])
		      allocHash[hashIndex]->prev=au;

		    au->next=allocHash[hashIndex];
		    au->prev=0;
		    allocHash[hashIndex]=au;
		  }
示例#4
0
/* sets bit at x,y to 1 */
void setBit(BitMatrix *m, int x, int y){
    int mask=0;
    calcAddr(&x,&y,&mask);
    m->bits[y*m->rowWidth+x]|=mask;
    /*printf("%d %d %d\n",x,y,m->bits[y][x]);*/
}
示例#5
0
		void *memAllocate(const sChar *file, const sU32 line, const allocType type, const sU32 size)
		{
		  allocUnit **temp;
		  allocUnit *au;
		  sU32      i, hashIndex;

		  FRASSERT(size<MAXALLOC);

		  if (!reservoir)
		  {
		    reservoir=(allocUnit *) malloc(sizeof(allocUnit)*256);
		    if (!reservoir)
					fr::errorExit("memory manager panic");

		    memset(reservoir, 0, sizeof(allocUnit)*256);
		    for (i=0; i<255; i++)
		      reservoir[i].next=&reservoir[i+1];

		    if (reservoirBuffer)
		      temp=(allocUnit **) realloc(reservoirBuffer, (reservoirSize+1)*sizeof(allocUnit *));
		    else
		      temp=(allocUnit **) malloc(sizeof(allocUnit *));

		    if (!temp)
					fr::errorExit("memory manager panic");

		    reservoirBuffer=temp;
		    reservoirBuffer[reservoirSize++]=reservoir;
		  }

		  au=reservoir;
		  reservoir=au->next;

		  memset(au, 0, sizeof(allocUnit));
		  au->realSize=calcRealSize(size);
		  au->realAddr=malloc(au->realSize);
		  au->size=size;
		  au->addr=calcAddr(au->realAddr);
		  au->type=type;
		  au->line=line;
		  if (file)
		    strncpy(au->file, file, 63);
		  else
		    strcpy(au->file, "???");

		  hashIndex=((sU32) au->addr>>4) & ALLOCHASHMASK;
		  if (allocHash[hashIndex])
		    allocHash[hashIndex]->prev=au;

		  au->next=allocHash[hashIndex];
		  au->prev=0;
		  allocHash[hashIndex]=au;

#ifdef HOTSPOTS
		  updateHotspot(au->file?au->file:"???", au->line, au->size);
#endif

		  stats.totalAlloc+=au->size;
		  stats.totalRealAlloc+=au->realSize;
		  stats.totalAllocUnits++;
		  stats.curAlloc+=au->size;
		  stats.curRealAlloc+=au->realSize;
		  stats.curAllocUnits++;
		  
		  if (stats.curAlloc>stats.peakAlloc)
		    stats.peakAlloc=stats.curAlloc;

		  if (stats.curRealAlloc>stats.peakRealAlloc)
		    stats.peakRealAlloc=stats.curRealAlloc;

		  if (stats.curAllocUnits>stats.peakAllocUnits)
		    stats.peakAllocUnits=stats.curAllocUnits;

		  wipeUnit(au);
		  sourceFile="include_debug_h_everywhere_please.cpp";
		  sourceLine=303;

		  if (!au->addr)
				fr::debugOut("MDBG: warning, allocation of %lu bytes FAILED\n", au->size);

		  return au->addr;
		}