From 2f30950143cc70bc42a3c8a4111d7cf8198ec881 Mon Sep 17 00:00:00 2001 From: Nathan Binkert Date: Mon, 11 May 2009 10:38:43 -0700 Subject: ruby: Import ruby and slicc from GEMS We eventually plan to replace the m5 cache hierarchy with the GEMS hierarchy, but for now we will make both live alongside eachother. --- src/mem/gems_common/Allocator.hh | 83 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 src/mem/gems_common/Allocator.hh (limited to 'src/mem/gems_common/Allocator.hh') diff --git a/src/mem/gems_common/Allocator.hh b/src/mem/gems_common/Allocator.hh new file mode 100644 index 000000000..109696601 --- /dev/null +++ b/src/mem/gems_common/Allocator.hh @@ -0,0 +1,83 @@ +/* + * Copyright (c) 1999 by Mark Hill and David Wood for the Wisconsin + * Multifacet Project. ALL RIGHTS RESERVED. + * + * ##HEADER## + * + * This software is furnished under a license and may be used and + * copied only in accordance with the terms of such license and the + * inclusion of the above copyright notice. This software or any + * other copies thereof or any derivative works may not be provided or + * otherwise made available to any other persons. Title to and + * ownership of the software is retained by Mark Hill and David Wood. + * Any use of this software must include the above copyright notice. + * + * THIS SOFTWARE IS PROVIDED "AS IS". THE LICENSOR MAKES NO + * WARRANTIES ABOUT ITS CORRECTNESS OR PERFORMANCE. + * */ + +/* + * $Id$ + */ + +#ifndef ALLOCATOR_H +#define ALLOCATOR_H + +#include "Vector.hh" + +template +class Allocator { +public: + // Constructors + Allocator() { m_counter = 0; } + + // Destructor + ~Allocator() { for(int i=0; i m_pool_vec; + int m_counter; +}; + +template +inline +TYPE* Allocator::allocate(const TYPE& obj) +{ + m_counter++; + DEBUG_EXPR(ALLOCATOR_COMP, LowPrio, m_counter); + TYPE* new_obj_ptr; + + // See if we need to allocate any new objects + if (m_pool_vec.size() == 0) { + // Allocate a new item + m_pool_vec.insertAtBottom(new TYPE); + } + + // Pop the pointer from the stack/pool + int size = m_pool_vec.size(); + new_obj_ptr = m_pool_vec[size-1]; + m_pool_vec.setSize(size-1); + + // Copy the object + *new_obj_ptr = obj; + return new_obj_ptr; +} + +template +inline +void Allocator::deallocate(TYPE* obj) +{ + m_pool_vec.insertAtBottom(obj); +} + +#endif //ALLOCATOR_H -- cgit v1.2.3