diff --git a/DRAMSys/library/src/simulation/MemoryManager.cpp b/DRAMSys/library/src/simulation/MemoryManager.cpp index 6f456272..0094a9b4 100644 --- a/DRAMSys/library/src/simulation/MemoryManager.cpp +++ b/DRAMSys/library/src/simulation/MemoryManager.cpp @@ -36,6 +36,7 @@ #include "MemoryManager.h" #include "../common/DebugManager.h" +#include "../controller/core/configuration/Configuration.h" #include using namespace std; @@ -48,20 +49,30 @@ MemoryManager::MemoryManager(): numberOfAllocations(0), numberOfFrees(0) MemoryManager::~MemoryManager() { for (gp *payload : freePayloads) { + delete[] payload->get_data_ptr(); delete payload; numberOfFrees++; } - //Comment in if you are suspecting a memory leak in the manager - //DebugManager::getInstance().printDebugMessage("MemoryManager","Number of allocated payloads: " + to_string(numberOfAllocations)); - //DebugManager::getInstance().printDebugMessage("MemoryManager","Number of freed payloads: " + to_string(numberOfFrees)); + DebugManager::getInstance().printDebugMessage("MemoryManager", + "Number of allocated payloads: " + to_string(numberOfAllocations)); + DebugManager::getInstance().printDebugMessage("MemoryManager", + "Number of freed payloads: " + to_string(numberOfFrees)); } gp *MemoryManager::allocate() { if (freePayloads.empty()) { numberOfAllocations++; - return new gp(this); + gp *payload = new gp(this); + + // Allocate a data buffer and initialize it with zeroes: + unsigned int dataLength = Configuration::getInstance().getBytesPerBurst(); + unsigned char *data = new unsigned char[dataLength]; + std::fill(data, data + dataLength, 0); + + payload->set_data_ptr(data); + return payload; } else { gp *result = freePayloads.back(); freePayloads.pop_back(); @@ -71,8 +82,6 @@ gp *MemoryManager::allocate() void MemoryManager::free(gp *payload) { - //unsigned char *dptr = payload->get_data_ptr(); - //delete[] dptr; payload->reset(); //clears all extensions freePayloads.push_back(payload); } diff --git a/DRAMSys/library/src/simulation/StlPlayer.h b/DRAMSys/library/src/simulation/StlPlayer.h index cace8884..dae8e4ab 100644 --- a/DRAMSys/library/src/simulation/StlPlayer.h +++ b/DRAMSys/library/src/simulation/StlPlayer.h @@ -89,12 +89,7 @@ public: } // Allocate a generic payload for this request. gp *payload = this->allocatePayload(); - - // Allocate a data buffer and initialize it with zeroes. It may be - // overwritten with data from the trace file depending on the storage - // mode. - unsigned char *data = new unsigned char[dataLength]; - std::fill(data, data + dataLength, 0); + unsigned char *data = payload->get_data_ptr(); // Trace files MUST provide timestamp, command and address for every // transaction. The data information depends on the storage mode @@ -170,16 +165,14 @@ public: payload->set_data_ptr(data); payload->set_command(cmd); - if (relative == false) - { + if (relative == false) { // Send the transaction directly or schedule it to be sent in the future. if (sendingTime <= sc_time_stamp()) this->payloadEventQueue.notify(*payload, BEGIN_REQ, SC_ZERO_TIME); else this->payloadEventQueue.notify(*payload, BEGIN_REQ, sendingTime - sc_time_stamp()); - } - else + } else payloadEventQueue.notify(*payload, BEGIN_REQ, sendingTime); }