sc_mm.cc revision 12047
12068SN/A/* 22068SN/A * Copyright (c) 2015, University of Kaiserslautern 32188SN/A * All rights reserved. 42068SN/A * 52068SN/A * Redistribution and use in source and binary forms, with or without 62068SN/A * modification, are permitted provided that the following conditions are 72068SN/A * met: 82068SN/A * 92068SN/A * 1. Redistributions of source code must retain the above copyright notice, 102068SN/A * this list of conditions and the following disclaimer. 112068SN/A * 122068SN/A * 2. Redistributions in binary form must reproduce the above copyright 132068SN/A * notice, this list of conditions and the following disclaimer in the 142068SN/A * documentation and/or other materials provided with the distribution. 152068SN/A * 162068SN/A * 3. Neither the name of the copyright holder nor the names of its 172068SN/A * contributors may be used to endorse or promote products derived from 182068SN/A * this software without specific prior written permission. 192068SN/A * 202068SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 212068SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 222068SN/A * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 232068SN/A * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 242068SN/A * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 252068SN/A * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 262068SN/A * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 272068SN/A * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 282665Ssaidi@eecs.umich.edu * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 292665Ssaidi@eecs.umich.edu * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 302068SN/A * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 312649Ssaidi@eecs.umich.edu * 322649Ssaidi@eecs.umich.edu * Authors: 332649Ssaidi@eecs.umich.edu * Robert Gernhardt 342649Ssaidi@eecs.umich.edu * Matthias Jung 352649Ssaidi@eecs.umich.edu */ 362068SN/A 372068SN/A#include <iostream> 382068SN/A 392068SN/A#include "sc_mm.hh" 402068SN/A 412068SN/Ausing namespace std; 422068SN/A 432068SN/Anamespace Gem5SystemC 448588Sgblack@eecs.umich.edu{ 458588Sgblack@eecs.umich.edu 468588Sgblack@eecs.umich.eduMemoryManager::MemoryManager(): numberOfAllocations(0), numberOfFrees(0) 478588Sgblack@eecs.umich.edu{ 488588Sgblack@eecs.umich.edu 498588Sgblack@eecs.umich.edu} 502068SN/A 512068SN/AMemoryManager::~MemoryManager() 522068SN/A{ 538588Sgblack@eecs.umich.edu for (gp* payload: freePayloads) { 548588Sgblack@eecs.umich.edu delete payload; 552068SN/A numberOfFrees++; 562068SN/A } 578588Sgblack@eecs.umich.edu} 582075SN/A 592068SN/Agp* 602068SN/AMemoryManager::allocate() 612068SN/A{ 628588Sgblack@eecs.umich.edu if (freePayloads.empty()) { 638588Sgblack@eecs.umich.edu numberOfAllocations++; 648588Sgblack@eecs.umich.edu return new gp(this); 658588Sgblack@eecs.umich.edu } else { 668588Sgblack@eecs.umich.edu gp* result = freePayloads.back(); 678588Sgblack@eecs.umich.edu freePayloads.pop_back(); 688588Sgblack@eecs.umich.edu return result; 692068SN/A } 702068SN/A} 712068SN/A 728588Sgblack@eecs.umich.eduvoid 732068SN/AMemoryManager::free(gp* payload) 742069SN/A{ 752068SN/A payload->reset(); //clears all extensions 762068SN/A freePayloads.push_back(payload); 774027Sstever@eecs.umich.edu} 784027Sstever@eecs.umich.edu 794027Sstever@eecs.umich.edu} 806076Sgblack@eecs.umich.edu