1 ///-*-C++-*-//////////////////////////////////////////////////////////////////
3 // Hoard: A Fast, Scalable, and Memory-Efficient Allocator
4 // for Shared-Memory Multiprocessors
5 // Contact author: Emery Berger, http://www.cs.utexas.edu/users/emery
7 // Copyright (c) 1998-2000, The University of Texas at Austin.
9 // This library is free software; you can redistribute it and/or modify
10 // it under the terms of the GNU Library General Public License as
11 // published by the Free Software Foundation, http://www.fsf.org.
13 // This library is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Library General Public License for more details.
18 //////////////////////////////////////////////////////////////////////////////
33 block(superblock
* sb
)
36 _magic(FREE_BLOCK_MAGIC
),
38 _next(NULL
), _mySuperblock(sb
)
43 operator=(const block
& b
)
49 _mySuperblock
= b
._mySuperblock
;
51 _requestedSize
= b
._requestedSize
;
57 ALLOCATED_BLOCK_MAGIC
= 0xcafecafe,
58 FREE_BLOCK_MAGIC
= 0xbabebabe
61 // Mark this block as free.
62 inline void markFree(void);
64 // Mark this block as allocated.
65 inline void markAllocated(void);
67 // Is this block valid? (i.e.,
68 // does it have the right magic number?)
69 inline const int isValid(void) const;
71 // Return the block's superblock pointer.
72 inline superblock
*getSuperblock(void);
76 setRequestedSize(size_t s
)
82 getRequestedSize(void)
84 return _requestedSize
;
90 setActualSize(size_t s
)
115 setCallStack(int index
, void *address
)
117 _callStack
[index
] = address
;
121 getCallStack(int index
)
123 return _callStack
[index
];
127 setAllocatedSize(size_t size
)
129 _allocatedSize
= size
;
135 return _allocatedSize
;
140 #if USE_PRIVATE_HEAPS
143 unsigned long _magic
;
144 double _d1
; // For alignment.
148 block
*_next
; // The next block in a linked-list of blocks.
149 size_t _actualSize
; // The actual size of the block.
152 double _d2
; // For alignment.
153 superblock
*_mySuperblock
; // A pointer to my superblock.
155 #else // ! USE_PRIVATE_HEAPS
159 unsigned long _magic
;
160 double _d3
; // For alignment.
164 block
*_next
; // The next block in a linked-list of blocks.
165 superblock
*_mySuperblock
; // A pointer to my superblock.
166 #endif // USE_PRIVATE_HEAPS
169 void *_callStack
[HEAP_CALL_STACK_SIZE
];
170 size_t _allocatedSize
;
175 double _d4
; // This is just for alignment purposes.
176 size_t _requestedSize
; // The amount of space requested (vs. allocated).
181 block(const block
&);
186 block::getSuperblock(void)
192 return _mySuperblock
;
197 block::markFree(void)
200 assert(_magic
== ALLOCATED_BLOCK_MAGIC
);
201 _magic
= FREE_BLOCK_MAGIC
;
207 block::markAllocated(void)
210 assert(_magic
== FREE_BLOCK_MAGIC
);
211 _magic
= ALLOCATED_BLOCK_MAGIC
;
217 block::isValid(void) const
220 return _magic
== FREE_BLOCK_MAGIC
221 || _magic
== ALLOCATED_BLOCK_MAGIC
;
227 } // namespace BPrivate