Jim Helman (jimh++at++surreal)
Fri, 19 May 95 08:00:59 -0700
rgds,
-jim helman
jimh++at++surreal.asd.sgi.com
415/390-1151
#define TRICHUNK 128 /* initial allocation size */
#define MAXTRICHUNK 8192 /* maximum allocation size */
static void
freeTris(pfdGeoBuilder *bldr)
{
pfdPrim *tri;
int chunkSize = TRICHUNK;
static int FreedTris = 0;
/* Free linked list of triangle chunks */
tri = bldr->triList;
do
{
pfdPrim *next;
next = tri[chunkSize-1].next;
pfFree(tri);
FreedTris++;
tri = next;
chunkSize <<= 1;
if (chunkSize > MAXTRICHUNK)
chunkSize >>= 1;
} while (tri != bldr->triList);
}
static pfdPrim *
getPrim(pfdGeoBuilder *bldr)
{
pfdPrim *t = NULL;
int chunkSize = TRICHUNK;
int newChunkSize = 0;
/*
* Create and link in a new chunk of triangles whose size is twice
* the size of the previous chunk. Use last triangle in chunk as link.
*/
if (bldr->availTri->flags == LINK_TRI)
{
if (bldr->availTri->next == bldr->triList)
{
/* determine old chunk size */
t = bldr->triList;
while (&t[chunkSize-1] != bldr->availTri)
{
t = t[chunkSize-1].next;
chunkSize <<= 1;
if (chunkSize > MAXTRICHUNK)
chunkSize >>= 1;
}
/* determine new chunk size */
newChunkSize = chunkSize << 1;
if (newChunkSize > MAXTRICHUNK)
newChunkSize >>= 1;
bldr->availTri = t[chunkSize-1].next =
pfCalloc(newChunkSize, sizeof(pfdPrim), NULL);
pfAdd(bldr->mallocList,bldr->availTri);
/* Point last tri in chunk to head of linked list */
t = &bldr->availTri[newChunkSize-1];
t->next = bldr->triList;
t->flags = LINK_TRI;
}
else
bldr->availTri = bldr->availTri->next;
}
t = bldr->availTri;
bldr->availTri++;
return t;
}
This archive was generated by hypermail 2.0b2 on Mon Aug 10 1998 - 17:51:30 PDT