Question: Write the memory system with Cpp: 1 . Write all programs in cross - platform C + + 2 . No Containers, NO STL allowed
Write the memory system with Cpp:
Write all programs in crossplatform C
No Containers, NO STL allowed Vector Lists, Sets, etc...
Simple Oldfashion C No modern C
No Adding files
Create a memory system within a heap
Take the given memory system framework for the heap layout:
o Add the allocators
o Add the deallocators
Mem.h
#include "Heap.h
class Mem
public:
static const uintt TotalSize ;
static const uintt HeapAlign ;
static const uintt HeapAlignMask HeapAlign ;
static const uintt HeaderGuards ;
enum class Guard TypeA Type TypeNone;
public:
Mem Guard type ;
Mem default;
Memconst Mem & delete;
Mem & operator const Mem & delete;
~Mem;
void free void const data ;
void malloc const uintt size ;
void initialize;
Heap GetHeap;
void Printint count;
private:
Useful in malloc and free
Heap poHeap;
Below: Not used in malloc, free, or initialize
Guard type;
void poRawMem;
;
#endif
End of File
Mem.cpp
#include "Mem.h
#include "Heap.h
#include "Type.h
To help with coalescing... not required
struct SecretPtr
Free pFree;
;
Initialized the Memory block:
Update the Heap
Create a free block
Heap structure links to free hdr
void Mem::initialize
TODO
Find a free block that fits
Change it to used may require subdivision
Correct the heap Links usedfree headers
Update stats
Return pointer to block
void Mem::malloc const uintt size
TODO
Return the free block to the system
May require Coalescing
Correct the heap Links usedfree headers
Update stats
void Mem::free void const data
TODO
Mem::~Mem
skip do not modify
Heap Mem::GetHeap
return thispoHeap;
Mem::MemGuard type do not modify
thispoHeap nullptr;
thispoRawMem nullptr;
thistype type;
Do a land grab get the space for the entire heap
Since OS have Different Alignments... I forced it to byte aligned
poRawMem alignedmallocMem::TotalSize Mem::HeaderGuards, Mem::HeapAlign;
assertpoRawMem nullptr;
if thistype Guard::TypeA
HEAPSETBOTTOMAGUARDS
else
HEAPSETBOTTOMGUARDS
assertuinttpoRawMem & Mem::HeapAlignMaskx;
Heap p newpoRawMem Heap;
assertp;
thispoHeap p;
void Mem::Printint count
skip do not modify
End of File
Heap.h
#include "Used.h
#include "Free.h
class Heap
public:
Heap;
Heapconst Heap& delete;
Heap& operator const Heap& delete;
~Heap default;
public:
Used pUsedHead;
Free pFreeHead;
Free pNextFit;
uintt currNumUsedBlocks;
uintt currUsedMem;
uintt currNumFreeBlocks;
uintt currFreeMem;
uintt pad;
;
#endif
Heap.cpp
#include "Heap.h
#include "Mem.h
Heap::Heap
: pUsedHeadnullptr
pFreeHeadnullptr
pNextFitnullptr
currNumUsedBlocks
currUsedMem
currNumFreeBlocks
currFreeMem
pad
Free.h
#include "Type.h
class Used;
class Free
public:
Do not reorder, change or add data fields
You can add methods if you wish
Free pNext;
Free pPrev;
uintt mData;
Free default;
;
#endif
Free.cpp
#include "Used.h
#include "Free.h
#include "Type.h
TODO
Used.h
#ifndef USEDH
#define USEDH
#include "Type.h
class Free;
class Used
public:
Do not reorder, change or add data fields
You can add methods if you wish
Used pNext;
Used pPrev;
uintt mData;
Used default;
;
#endif
Used.cpp
#include "Free.h
#include "Used.h
TODO
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
