Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You are to implement a simple object manager. You will also need to define appro

ID: 3576182 • Letter: Y

Question

 You are to implement a simple object manager. You will also need to define appropriate data  types and data structures for keeping track of the objects that have been allocated   #ifndef _OBJECT_MANAGER_H #define _OBJECT_MANAGER_H  // The number of bytes of memory we have access to -- put here so everyone's consistent. #ifndef MEMORY_SIZE #define MEMORY_SIZE 1024*512 #endif  #define NULL_REF 0  typedef unsigned long Ref;   // This function trys to allocate a block of given size from our buffer. // It will fire the garbage collector as required. // We always assume that an insert always creates a new object... // On success it returns the reference number for the block of memory allocated for the object. // On failure it returns NULL_REF (0) Ref insertObject( const int size )  // returns a pointer to the object being requested given by the reference id void *retrieveObject( const Ref ref )  // update our index to indicate that we have another reference to the given object void addReference( const Ref ref )  // update our index to indicate that a reference is gone void dropReference( const Ref ref )  // initialize the object manager void initPool()  // clean up the object manager (before exiting) void destroyPool()  // This function traverses the index and prints the info in each entry corresponding to a block of allocated memory. // You should print the block's reference id, it's starting address, and it's size (in bytes). void dumpPool()  #endif 

Explanation / Answer

#include #include int main() { int num, i, *ptr, sum = 0; printf("Enter number of elements: "); scanf("%d", &num); ptr = (int*) malloc(num * sizeof(int)); //memory allocated using malloc if(ptr == NULL) { printf("Error! memory not allocated."); exit(0); } printf("Enter elements of array: "); for(i = 0; i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote