memory.c CSCI-SHU MISC|very helpful
#include "oslabs.h" #include stdio.h #include string.h #include stdbool.h // 1 struct MEMORY_BLOCK best_fit_allocate(int request_size, struct MEMORY_BLOCK memory_map[MAPMAX],int *map_cnt, int process_id) { struct MEMORY_BLOCK temp_memory_block, allocated_memory; allocated__address = 0; allocated__address = 0; allocated_ss_id = 0; allocated_nt_size = 0; bool match = false; int memory_map_index = 0 , best_fit_segment = 0; // It finds the candidate memory blocks that can be allocated and chooses the one whose size is closest to the requested size. for (int i = 0; i = *map_cnt - 1; i++) { // If the free block found is exactly of the same size as the requested size, the method returns a pointer to this memory block. if (request_size == memory_map[i].segment_size) { match = true; memory_map_index = i; best_fit_segment = request_size; break; // If the free
Written for
- Institution
- New York University
- Course
- CSCI-SHU MISC
Document information
- Uploaded on
- December 7, 2022
- Number of pages
- 6
- Written in
- 2022/2023
- Type
- Exam (elaborations)
- Contains
- Questions & answers
Subjects
-
memoryl new york university csci shu misc