Question: fix my code please heres my output: About to dump the free list: Node address: 0 x 7 f 8 a 7 acff 0 5
fix my code please"
heres my output:
About to dump the free list:
Node address: xfaacff Node size stored: Node size actual Nod e t i
No suitable block found for allocation
Error: Sixth allocation failed
Failure in memory test one
main.c
int mainint argc, char argv
setlocaleLCNUMERIC,"";
if memoryTestOne
fprintfstderr"Failure in memory test one";
exit EXITFAILURE;
if memoryTestTwo
fprintfstderr"Failure in memory test two";
exit EXITFAILURE;
if memoryTestThree
fprintfstderr"Failure in memory test three";
exit EXITFAILURE;
printfTests Succeeded";
return EXITSUCCESS;
int mainint argc, char argv
setlocaleLCNUMERIC,"";
if memoryTestOne
fprintfstderr"Failure in memory test one";
exit EXITFAILURE;
if memoryTestTwo
fprintfstderr"Failure in memory test two";
exit EXITFAILURE;
if memoryTestThree
fprintfstderr"Failure in memory test three";
exit EXITFAILURE;
printfTests Succeeded";
return EXITSUCCESS;
fscMalloc.c fscMalloc.c
#include "fscMalloc.h
#include
#include
void fscMemorySetupmemoryStructure m fscAllocationMethod am sizet sizeInBytes
if FIRSTFITRETURNFIRST am
fprintfstderr "This code only supports the FIRSTFITRETURNFIRST allocation method
;
return NULL;
Allocate memory using malloc
mhead mallocsizeInBytes;
if mhead NULL
fprintfstderr "Memory allocation failed
;
return NULL;
Initialize memory
mheadsize sizeInBytes sizeoffscfreenodet;
mheadnext NULL;
return mhead;
void fscMallocmemoryStructure m sizet requestedSizeInBytes
Search for the first fit
fscfreenodet current mhead;
fscfreenodet prev NULL;
while current NULL
if currentsize requestedSizeInBytes
Allocate memory
if currentsize requestedSizeInBytes
Split the block
fscfreenodet newBlock fscfreenodetcharcurrent requestedSizeInBytes sizeoffscfreenodet;
newBlocksize currentsize requestedSizeInBytes sizeoffscfreenodet;
newBlocknext currentnext;
currentnext newBlock;
Update current block size
currentsize requestedSizeInBytes;
Remove current block from free list
if prev NULL
mhead currentnext;
else
prevnext currentnext;
Return allocated memory
return voidcurrent ;
prev current;
current currentnext;
No suitable block found
fprintfstderrNo suitable block found for allocation
;
return NULL;
void fscFreememoryStructure m void returnedMemory
Cast returnedMemory to freenodet
fscfreenodet block fscfreenodetcharreturnedMemory sizeoffscfreenodet;
Add block to free list
blocknext mhead;
mhead block;
Given a node, prints the list for you.
void printFreeListFILE out, fscfreenodet head
given a node, prints the list.
fscfreenodet current head;
fprintfout "About to dump the free list:
;
while current NULL
fprintfout "Node address: pt Node size stored: zut Node size actualzut Node next:p
voidcurrent
currentsize,
currentsize sizeoffscfreenodet
voidcurrentnext;
current currentnext;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
