A4 programming
//------------------------------------------------ // NAME : YOUR NAME // STUDENT# : ####### // // COURSE : COMP 2160, SECTION: A01 // INSTRUCTOR: Stela H. Seo // ASSIGNMENT: 04 // // REMARKS : This is the interface for the object manager. // The terms object and block are used interchangably below. //------------------------------------------------ //------------------------------------------------------------------------------ // INCLUDE GUARD //------------------------------------------------------------------------------ #ifndef _OBJECT_MANAGER_H_ #define _OBJECT_MANAGER_H_ //------------------------------------------------------------------------------ // CONSTANTS AND TYPES //------------------------------------------------------------------------------ #define NULL_REF 0 typedef unsigned long Ref; typedef enum Boolean { false, true } boolean; //------------------------------------------------------------------------------ // PROTOTYPES //------------------------------------------------------------------------------ //-------------------------------------------------- // PURPOSE: Initialize our object manager // INPUT PARAMETERS: // [size]<IN> Our object manager's pool size // OUTPUT PARAMETERS: // [boolean]<OUT> True, if we successfully initialized or already initialized; otherwise, false // REMARKS: This can be called multiple times; first call (or call after calling destroy()) will be effective to change the pool size //-------------------------------------------------- boolean initialize( const int size ); //-------------------------------------------------- // PURPOSE: Release all resources used in our object manager // REMARKS: This can be called multiple times. //-------------------------------------------------- void destroy( void ); //-------------------------------------------------- // PURPOSE: This function trys to allocate a block of given size from our buffer. // It will fire the garbage collector as required. // INPUT PARAMETERS: // [size]<IN> Size of an object to allocate in a number of bytes // OUTPUT PARAMETERS: // [Ref]<OUT> On success it returns the reference number for the block of memory allocated for the object. // On failure it returns NULL_REF (0) //-------------------------------------------------- Ref insert( const int size ); //-------------------------------------------------- // PURPOSE: Update the reference count of an object // INPUT PARAMETERS: // [ref]<IN> Object reference //-------------------------------------------------- void addRef( const Ref ref ); //-------------------------------------------------- // PURPOSE: Update the reference count of an object // INPUT PARAMETERS: // [ref]<IN> Object reference //-------------------------------------------------- void removeRef( const Ref ref ); //-------------------------------------------------- // PURPOSE: Returns a pointer to the object being requested given by the reference // INPUT PARAMETERS: // [ref]<IN> Object reference // OUTPUT PARAMETERS: // [void *]<OUT> Pointer to the object //-------------------------------------------------- void * get( const Ref ref ); //-------------------------------------------------- // PURPOSE: This function traverses the index and prints the info in each entry corresponding to a block of allocated memory. // This should print the block's reference id, it's starting address, and it's size (in bytes). //-------------------------------------------------- void dump( void ); //------------------------------------------------------------------------------ // END OF INCLUDE GUARD //------------------------------------------------------------------------------ #endif