Compiler Design – Modify Code:
Memory Management project
Given FirstFit, please finish NextFit and WorstFit.Follow the form of FirstFit! Please!
defragmentPrepareEnd and Front do not need tomodify.
!!!!!!!!!!!!!!!!!!!Do not provide code in differentform!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!Do not provide code in differentform!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!Do not provide code in differentform!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!Do not provide code in differentform!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!Do not provide code in differentform!!!!!!!!!!!!!!!!!!!!!!
————————————————————————————-
//FirstFit.hpp
#ifndef FIRSTFIT_HPP
#define FIRSTFIT_HPP
#include “Policy.hpp”
class FirstFit : public Policy
{
public:
void* onMalloc(int size);
void onFree(void* address);
};
#endif // !FIRSTFIT_HPP
————————————————————————————-
//FirstFit.cpp
#include “stdafx.h”
#include “FirstFit.hpp”
#include “MemoryStructure.hpp”
#include “ScheduleProcessor.hpp”
#include “defines.hpp”
#include <thread>
int defragmentPrepareEnd(int target_size);
int defragmentPrepareFront(int target_size);
void* FirstFit::onMalloc(int size)
{
MemoryStructure* ms = MemoryStructure::getInstance();
while(true)
{
void* prev_end = 0;
for(int i = 0; i < ms->getAllocationListSize(); i++)
{
Allocation alloc = ms->getAllocation(i);
if((int)alloc.addr – (int)prev_end >= size)
{
ASSERT(ms->allocate(prev_end, size));
return prev_end;
}
prev_end = (void*)((int)alloc.addr + (int)alloc.size);
}
if(MAX_MEMORY_CAP
PayPal Gateway not configured
PayPal Gateway not configured