2 * Copyright (c) 1999 by Mark Hill and David Wood for the Wisconsin
3 * Multifacet Project. ALL RIGHTS RESERVED.
7 * This software is furnished under a license and may be used and
8 * copied only in accordance with the terms of such license and the
9 * inclusion of the above copyright notice. This software or any
10 * other copies thereof or any derivative works may not be provided or
11 * otherwise made available to any other persons. Title to and
12 * ownership of the software is retained by Mark Hill and David Wood.
13 * Any use of this software must include the above copyright notice.
15 * THIS SOFTWARE IS PROVIDED "AS IS". THE LICENSOR MAKES NO
16 * WARRANTIES ABOUT ITS CORRECTNESS OR PERFORMANCE.
26 #include "mem/gems_common/Vector.hh"
32 Allocator() { m_counter = 0; }
35 ~Allocator() { for(int i=0; i<m_pool_vec.size(); i++) { delete m_pool_vec[i]; }}
38 TYPE* allocate(const TYPE& obj);
39 void deallocate(TYPE* obj_ptr);
41 // Private copy constructor and assignment operator
42 Allocator(const Allocator& obj);
43 Allocator& operator=(const Allocator& obj);
47 // Data Members (m_ prefix)
48 Vector<TYPE*> m_pool_vec;
54 TYPE* Allocator<TYPE>::allocate(const TYPE& obj)
57 DEBUG_EXPR(ALLOCATOR_COMP, LowPrio, m_counter);
60 // See if we need to allocate any new objects
61 if (m_pool_vec.size() == 0) {
62 // Allocate a new item
63 m_pool_vec.insertAtBottom(new TYPE);
66 // Pop the pointer from the stack/pool
67 int size = m_pool_vec.size();
68 new_obj_ptr = m_pool_vec[size-1];
69 m_pool_vec.setSize(size-1);
78 void Allocator<TYPE>::deallocate(TYPE* obj)
80 m_pool_vec.insertAtBottom(obj);