Question
you will b implmnting a mmory allocator for th hap of a usr-lvl procss. **(Must be done in C no C++) done use malloc you
you will b implmnting a mmory allocator for th hap of a usr-lvl procss.
**(Must be done in C no C++) done use malloc
you must us mmap() . Scond, although a ral mmory allocator rqusts mor mmory from th OS whnvr it can't satisfy a rqust from th usr, your mmory allocator must call mmap() only on tim (whn it is first initializd).
Classic malloc() and fr() ar dfind as follows:
void *malloc(siz_t siz): malloc() allocats siz byts and rturns a pointr to th allocatd mmory. Th mmory is not clard.
void fr(void *ptr): fr() frs th mmory spac pointd to by ptr, which must hav bn rturnd by a prvious call to malloc() (or calloc() or ralloc()). Othrwis, or if fr(ptr) has alrady bn calld bfor, undfind bhaviour occurs. If ptr is NULL, no opration is prformd.
must align rqusts on 16-byt addrsss.
Th program will nd to maintain data structurs that minimally kp track of blocks of fr spac. Ths data structurs should ***NOT*** b in th allocatd pags thmslvs.
If th usr frs two blocks of mmory that ar adjacnt, your program should coalsc thm.
If th usr attmpts to allocat mor spac than is availabl in an opn fr block, thn malloc_alloc should rturn NULL.
void malloc_init(int num_pags_for_hap){
int pagsiz;
pagsiz = gtpagsiz();
void *ptr;
ptr = mmap(NULL, pagsiz, add flag hr, -1, 0);
rturn;
}
void *malloc_alloc(int num_byts_allocat){
rturn NULL;
}
void malloc_fr(void *pointr_ara_to_fr){
rturn;
}
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