Question
With the following struct definition and createArray function, use the given function definition to get the current size of the Array in bytes. typedef struct
With the following struct definition and createArray function, use the given function definition to get the current size of the Array in bytes.
typedef struct LonelyPartyArray {
int size; int num_fragments; int fragment_length; int num_active_fragments; int **fragments; int *fragment_sizes;
} LonelyPartyArray;
LonelyPartyArray *createLonelyPartyArray(int num_fragments, int fragment_length){ if( (num_fragments>0)&&(fragment_length>0) ){ LonelyPartyArray *createdArray; createdArray = (LonelyPartyArray *)malloc( sizeof(LonelyPartyArray) ); if(createdArray==NULL){ return NULL; } createdArray->fragment_length = fragment_length; createdArray->num_fragments = num_fragments; createdArray->num_active_fragments = 0; createdArray->size = 0; createdArray->fragments = (int ** )calloc(num_fragments,sizeof(int *)); if(createdArray->fragments==NULL){ free(createdArray); return NULL; } createdArray->fragment_sizes = (int*)calloc(num_fragments,sizeof(int)); if(createdArray->fragment_sizes == NULL){ free(createdArray->fragments); free(createdArray); return NULL;
----------- long long unsigned int getCurrentSizeInBytes(LonelyPartyArray *party);
Description: This function should return the number of bytes currently taken up in memory by the LPA. You will need to account for all of the following:
The number of bytes taken up by the LPA pointer itself: sizeof(LPA*)
The number of bytes taken up by the LPA struct (which is just the number of bytes taken
up by the four integers and two pointers within the struct): sizeof(LPA)
The number of bytes taken up by the fragments array (i.e., the number of bytes taken
up by the pointers in that array).
The number of bytes taken up by the fragment_sizes array (i.e., the number of bytes taken up by the integers in that array).
The number of bytes taken up by the active fragments (i.e., the number of bytes taken up by all the integer cells in the individual array fragments).
The getArraySizeInBytes() and getCurrentSizeInBytes() functions will let you see, concretely, the amount of memory saved by using a lonely party array instead of a traditional C- style array.4
Note: You should use sizeof() in this function (rather than hard-coding the sizes of any data types), and cast the sizeof() values to long long unsigned int as appropriate.
Output: This function should not print anything to the screen. Returns: The number of bytes (as just described), or 0 if the party pointer is NULL.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started