1. Homepage
  2. Exam
  3. [2021] CMPSC311 Introduction to Systems Programming - Q8 Cache

[2021] CMPSC311 Introduction to Systems Programming - Q8 Cache

This question has been solved
Engage in a Conversation

Question 8 CourseNana.COM

  CourseNana.COM

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: CourseNana.COM

  CourseNana.COM

int cache_create(int num_entries) { CourseNana.COM

int ret_value = -1; CourseNana.COM

if (cache == NULL && num_entries >= 2 && num_entries <= 4096) { CourseNana.COM

cache = __[1]___(__[2]__, __[3]__);  // Allocate cache CourseNana.COM

if (cache != NULL) { CourseNana.COM

cache_size = num_entries; CourseNana.COM

ret_value = 1; CourseNana.COM

} CourseNana.COM

  CourseNana.COM

} CourseNana.COM

return ret_value; CourseNana.COM

} CourseNana.COM

  CourseNana.COM

int cache_destroy(void) { CourseNana.COM

int ret_value = -1; CourseNana.COM

if (cache != NULL) { CourseNana.COM

__[4]___(__[5]__); // Deallocate cache CourseNana.COM

cache = __[6]__; // Avoid dangling pointer CourseNana.COM

cache_size = 0; CourseNana.COM

ret_value = 1; CourseNana.COM

} CourseNana.COM

return ret_value; CourseNana.COM

} CourseNana.COM

  CourseNana.COM

Please specify what goes into the blanks marked with [numbers]. Below are some hints for each blank: CourseNana.COM

  CourseNana.COM

[1]. Function name. CourseNana.COM

[2]. First parameter. CourseNana.COM

[3]. Second parameter. CourseNana.COM

[4]. Function name. CourseNana.COM

[5]. Parameter. CourseNana.COM

[6]. Value assigned to cache. CourseNana.COM

  CourseNana.COM

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. CourseNana.COM

Get the Solution to This Question

WeChat (微信) WeChat (微信)
Whatsapp WhatsApp
Pennsylvania State University代写,PSU代写,Introduction to Systems Programming代写,CMPSC311代写,Pennsylvania State University代编,PSU代编,Introduction to Systems Programming代编,CMPSC311代编,Pennsylvania State University代考,PSU代考,Introduction to Systems Programming代考,CMPSC311代考,Pennsylvania State Universityhelp,PSUhelp,Introduction to Systems Programminghelp,CMPSC311help,Pennsylvania State University作业代写,PSU作业代写,Introduction to Systems Programming作业代写,CMPSC311作业代写,Pennsylvania State University编程代写,PSU编程代写,Introduction to Systems Programming编程代写,CMPSC311编程代写,Pennsylvania State Universityprogramming help,PSUprogramming help,Introduction to Systems Programmingprogramming help,CMPSC311programming help,Pennsylvania State Universityassignment help,PSUassignment help,Introduction to Systems Programmingassignment help,CMPSC311assignment help,Pennsylvania State Universitysolution,PSUsolution,Introduction to Systems Programmingsolution,CMPSC311solution,