Question 8
In assignment 4, we implemented the cache_create function to dynamically allocate memory space for num_entries cache entries. We also implemented the cache_destroy function to deallocate that memory space. Below is a partial implementation of the cache_create and cache_destroy functions:
int cache_create(int num_entries) {
int ret_value = -1;
if (cache == NULL && num_entries >= 2 && num_entries <= 4096) {
cache = __[1]___(__[2]__, __[3]__); // Allocate cache
if (cache != NULL) {
cache_size = num_entries;
ret_value = 1;
}
}
return ret_value;
}
int cache_destroy(void) {
int ret_value = -1;
if (cache != NULL) {
__[4]___(__[5]__); // Deallocate cache
cache = __[6]__; // Avoid dangling pointer
cache_size = 0;
ret_value = 1;
}
return ret_value;
}
Please specify what goes into the blanks marked with [numbers]. Below are some hints for each blank:
[1]. Function name.
[2]. First parameter.
[3]. Second parameter.
[4]. Function name.
[5]. Parameter.
[6]. Value assigned to cache.
FYI: cache is the global pointer variable of type cache_entry_t * that stores the address of the dynamically allocated memory space, and cache_size is the global variable of type int that stores the number of entries of the cache.