void MemoryManager::showAllocatedMemory() { unsigned int beginAllocatedAddress, endAllocatedAddress, totalAllocated, processId, internalFragmentation, externalFragmentation; // INSERT YOUR CODE TO SHOW EACH ONE OF THE ALLOCATED MEMORY PARTITIONS, INCLUDING INTERNAL AND EXTERNAL (THE FOLLOWING) FRAGMENTATION auto freeIt = _freeList.begin(); for(auto it = _busyList.begin(); it != _busyList.end(); it++){ // for each partition... auto p = (*it); beginAllocatedAddress = p->getBeginAddress(); endAllocatedAddress = p->getEndAddress(); totalAllocated = p->getLength(); processId = p->getProcess()->getId(); internalFragmentation = 0; externalFragmentation = 0; // Como as listas estão ordenadas por endereço, // só é preciso verificar a _freeList em ordem if(p->getBeginAddress() > (*freeIt)->getEndAddress()) freeIt++; if((*freeIt)->getBeginAddress() == p->getEndAddress()+1) externalFragmentation = (*freeIt)->getLength(); // no not change the next line (the way information are shown) std::cout << "\tAllocd: " << "B=" << (beginAllocatedAddress) << ", \tE=" << (endAllocatedAddress) << ", \tT=" << (totalAllocated) << ", \tPID=" << (processId) << ", \tIF=" << (internalFragmentation) << ", \tEF=" << (externalFragmentation) << "\n"; } }
static RemoteReflectionInfo makeRemoteReflectionInfo(RemoteSection fieldmd, RemoteSection assocty, RemoteSection builtin, RemoteSection capture, RemoteSection typeref, RemoteSection reflstr) { RemoteReflectionInfo Info = { fieldmd, assocty, builtin, capture, typeref, reflstr, 0, 0 }; const RemoteSection Sections[6] = { fieldmd, assocty, builtin, capture, typeref, reflstr }; Info.StartAddress = getStartAddress(Sections, 6); uintptr_t EndAddress = getEndAddress(Sections, 6); Info.TotalSize = EndAddress - Info.StartAddress; return Info; }
void Side::set(FrameBuffer& frame, uint32_t color) { if(!bEnabled) return; for(int address = getStartAddress(); address <= getEndAddress(); ++address) { frame.setColor(address, color); } }
void MemoryManager::deallocateMemoryOfProcess(Process* process) { // Pequena proteção... if(process->getBeginMemory() == 0 && process->getEndMemory() == 0) return; // Verifica se tem partições adjacentes auto itUp = _freeList.end();// Iterador da partição acima auto itDown = _freeList.end();// Iterador da partição abaixo for(auto it = _freeList.begin(); it != _freeList.end(); it++){ auto tmp = (*it); if(tmp->getEndAddress()+1 == process->getBeginMemory()){ itUp = it; }else if(tmp->getBeginAddress()-1 == process->getEndMemory()){ itDown = it; } if(tmp->getBeginAddress() > process->getEndMemory()) break; } auto pUp = (*itUp);// Partição acima auto pDown = (*itDown);// Partição abaixo // Espaço que ficará livre após este desalocamento unsigned int freeSize = 0; if(itUp != _freeList.end() && itDown != _freeList.end()){// Acima e abaixo // Existem partições livres acima e abaixo da partição que será desalocado pUp->setEndAddress(pDown->getEndAddress());// Atualiza o endereço final da partição acima // com o endereço final da partição abaixo [junta elas] freeSize = pUp->getLength(); delete pDown; _freeList.erase(itDown);// Remove a partição abaixo }else if(itUp != _freeList.end() && itDown == _freeList.end()){// Só acima // Existe uma partição livre acima da que será desalocada pUp->setEndAddress(process->getEndMemory());// Atualiza o endereço final da partição acima // com o endereço final da partição que será desalocada freeSize = pUp->getLength(); }else if(itUp == _freeList.end() && itDown != _freeList.end()){// Só abaixo // Existe uma partição livre abaixo da que será desalocada pDown->setBeginAddress(process->getBeginMemory());// Atualiza o endereço inicial da partição abaixo // com o endereço inicial da partição que será // desalocada freeSize = pDown->getLength(); }else{// Isolada // A partição esta isolada, então simplesmente adicione // ela na _freeList. auto tmp = new Partition(process->getBeginMemory(), process->getEndMemory()); addPartitionInOrder(tmp, false); freeSize = tmp->getLength(); } // Remove a partição do processo da _busyList for(auto it = _busyList.begin(); it != _busyList.end(); it++){ auto tmp = (*it); if(tmp->getProcess() == process){ delete (*it); _busyList.erase(it); break; } } // Zera a memória do processo process->setBeginMemory(0); process->setEndMemory(0); // Verifica se tem algum processo na fila que // caiba no espaço gerado por esta desalocação unsigned int pSize = 0; for(auto it = _queue.begin(); it != _queue.end(); it++){ auto tmp = (*it); pSize = getProcessSize(tmp); if(freeSize >= pSize){ allocateMemoryForProcess(tmp); _queue.erase(it); break; } } }