//* halloc.c - main heap memory allocation/de-allocation functions //* System library headers #include #include //* Application headers #include "main.h" //* System/application structure sizes etc. #define GsOT_SIZE (sizeof(GsOT)) #define GsOT_TAG_SIZE (sizeof(GsOT_TAG)) #define GsSPRITE_SIZE (sizeof(GsSPRITE)) #define SCTRL_SIZE (sizeof(struct SCTRL)) #define PRIM_SIZE (24*sizeof(PACKET)) #define Z_PLANES (1< void OpenOT(GsOT **otpArray, PACKET **bpArray, int OTlen, int numObjects) { int buffSize=numObjects*PRIM_SIZE; //* Size of each buffer (in bytes) GsOT_TAG *OTtags; //* Create 2 OTs if ((OTtags = (GsOT_TAG *) calloc(Z_PLANES<<1, GsOT_TAG_SIZE))==NULL) printf("\nFailed to allocate memory for OTs!\n"); //* Create 2 OT headers and store their addresses in otpArray otpArray[1] = (otpArray[0] = (GsOT *) calloc(2, GsOT_SIZE)) + 1; if (otpArray[0]==NULL) printf("\nFailed to allocate memory for OT headers\n"); //* Initialize required OT header members otpArray[0]->length = otpArray[1]->length = OTlen; otpArray[1]->org = (otpArray[0]->org = OTtags) + Z_PLANES; //* Create 2 GPU packet buffers and store their addresses in bpArray bpArray[1] = (bpArray[0] = (PACKET *) calloc(2, buffSize)) + buffSize; if (bpArray[0]==NULL) printf("\nFailed to allocate memory for GPU buffers\n"); } //*------------------------------------------------------------------------------------------ //* CloseOT - Free all heap memory used by an open OT: OT headers, OTs, packet buffers //*------------------------------------------------------------------------------------- void CloseOT(GsOT *OTptr, PACKET *PKTptr) { free(OTptr->org); //* Free OT memory free(OTptr); //* Free OT header memory free(PKTptr); //* Free packet buffer memory } //*------------------------------------------------------------------------------------------ //* OpenSpriteArray - Create an array of sprites and (optionally) an associated array //* of sprite control structures which will be linked to the sprite array //*------------------------------------------------------------------------------------- void OpenSpriteArray(GsSPRITE **sprites, int numSprites, struct SCTRL **pscp) { int i; //* Create sprite array if ((*sprites = (GsSPRITE *) calloc(numSprites, GsSPRITE_SIZE))==NULL) { printf("\nFailed to allocate memory for sprites\n"); return; } //* Create and link a corresponding 'sprite control' array //* only if pscp is a valid address (of a pointer to struct SCTRL) if (pscp) { if ((*pscp = (struct SCTRL *) calloc(numSprites, SCTRL_SIZE))==NULL){ printf("\nFailed to allocate memory for sprite ctrl struct\n"); return; } for (i=0; i void CloseSpriteArray(GsSPRITE *sprites, struct SCTRL *scp) { free(sprites); //* Free sprite array memory if (scp) free(scp); //* Free sprite control array as required }