Question: I start with : https: / / www . chegg.com / homework - help / questions - and - answers / write - memory -
I start with : https:wwwchegg.comhomeworkhelpquestionsandanswerswritememorysystemcppwriteprogramscrossplatformccontainersstlallowedvectorqshareecdbbeeaaabf
and My code is here :
#include "Mem.h
#include "Heap.h
#include "Type.h
struct SecretPtr Free pFree; ;
void Mem::initialize
thispoHeappUsedHead nullptr;
thispoHeappFreeHead nullptr;
uintptrt freeBlockAddr reinterpretcastthispoRawMem sizeofHeap;
thispoHeappNextFit reinterpretcastfreeBlockAddr;
uintt availableMem Mem::TotalSize sizeofHeap sizeofFree;
Free freeBlock thispoHeappNextFit;
freeBlockpNext nullptr;
freeBlockpPrev nullptr;
SETFREEfreeBlockmData;
SETABOVEUSEDfreeBlockmData;
SETALLOCSIZEfreeBlockmData, availableMem;
thispoHeappFreeHead freeBlock;
thispoHeapcurrNumUsedBlocks ;
thispoHeapcurrUsedMem ;
thispoHeapcurrNumFreeBlocks ;
thispoHeapcurrFreeMem availableMem;
void Mem::mallocconst uintt size
check Image
void Mem::freevoid const data
if data nullptr
return;
Used usedBlock reinterpretcastdata;
Free freeBlock reinterpretcastusedBlock;
SETFREEfreeBlockmData;
SETABOVEUSEDfreeBlockmData;
SETALLOCSIZEfreeBlockmData, usedBlockmData;
Free prevFreeBlock nullptr;
Free nextFreeBlock nullptr;
uintptrt nextBlockAddr reinterpretcastfreeBlock GETALLOCSIZEfreeBlockmData;
uintptrt h reinterpretcastthispoRawMem Mem::TotalSize;
if nextBlockAddr h
Used nextBlockHeader reinterpretcastnextBlockAddr;
if ISUSEDnextBlockHeadermData
nextFreeBlock reinterpretcastnextBlockHeader;
thispoHeappNextFit nextFreeBlock;
uintptrt prevBlockAddr reinterpretcastfreeBlock GETALLOCSIZEreinterpretcastfreeBlock mData;
if prevBlockAddr reinterpretcastthispoRawMem sizeofHeap
Free prevBlockHeader reinterpretcastprevBlockAddr;
if ISUSEDprevBlockHeadermData
prevFreeBlock prevBlockHeader;
if thispoHeappUsedHead usedBlock
thispoHeappUsedHead usedBlockpNext;
else
usedBlockpPrevpNext usedBlockpNext;
if usedBlockpNext nullptr
usedBlockpNextpPrev usedBlockpPrev;
thispoHeapcurrNumUsedBlocks;
thispoHeapcurrUsedMem GETALLOCSIZEfreeBlockmData;
thispoHeapcurrNumFreeBlocks;
thispoHeapcurrFreeMem GETALLOCSIZEfreeBlockmData;
if prevFreeBlock nullptr
prevFreeBlockpNext freeBlockpNext;
if freeBlockpNext nullptr
freeBlockpNextpPrev prevFreeBlock;
freeBlock prevFreeBlock;
if nextFreeBlock nullptr
if freeBlockpNext nullptr
freeBlockpNextpPrev freeBlock;
freeBlockpNext nextFreeBlockpNext;
SETALLOCSIZEfreeBlockmData, GETALLOCSIZEfreeBlockmData GETALLOCSIZEnextFreeBlockmData;
if thispoHeappNextFit nextFreeBlock
thispoHeappNextFit freeBlock;
freeBlockpNext thispoHeappFreeHead;
if thispoHeappFreeHead nullptr
thispoHeappFreeHeadpPrev freeBlock;
thispoHeappFreeHead freeBlock;
freeBlockpPrev nullptr;
End of File
No code has been changed except Mem.cpp
But I cannot pass test code with
blkStart hdrEnd;
blkEnd blkStart GETALLOCSIZEfreemData;
CHECKEQUALPTRFIXblkStart PTRFIXhdrEnd;
CHECKEQUALPTRFIXblkEndxc;
CHECKEQUAL GETALLOCSIZEusedmDataxcd;
Please fix my code and pass this tests code line.
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
