"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/include/superblocks/tlab.h" between
Hoard-3.12.tar.gz and Hoard-3.13.tar.gz

About: The Hoard memory allocator is a drop-in replacement for malloc() that can improve application performance, especially for multithreaded programs running on multiprocessors (hint: newer releases now part of the HeapLayers package).

tlab.h  (Hoard-3.12):tlab.h  (Hoard-3.13)
skipping to change at line 68 skipping to change at line 68
enum { DesiredAlignment = HL::MallocInfo::Alignment }; enum { DesiredAlignment = HL::MallocInfo::Alignment };
public: public:
enum { Alignment = ParentHeap::Alignment }; enum { Alignment = ParentHeap::Alignment };
ThreadLocalAllocationBuffer (ParentHeap * parent) ThreadLocalAllocationBuffer (ParentHeap * parent)
: _parentHeap (parent), : _parentHeap (parent),
_localHeapBytes (0) _localHeapBytes (0)
{ {
sassert<gcd<Alignment, DesiredAlignment>::value == DesiredAlignment> verif static_assert(gcd<Alignment, DesiredAlignment>::value == DesiredAlignment,
yAlignment; "Alignment mismatch.");
sassert<(Alignment >= 2 * sizeof(size_t))> verifyCanHoldTwoPointers; static_assert((Alignment >= 2 * sizeof(size_t)),
verifyAlignment = verifyAlignment; "Alignment must be enough to hold two pointers.");
verifyCanHoldTwoPointers = verifyCanHoldTwoPointers;
} }
~ThreadLocalAllocationBuffer() { ~ThreadLocalAllocationBuffer() {
clear(); clear();
} }
inline static size_t getSize (void * ptr) { inline static size_t getSize (void * ptr) {
return getSuperblock(ptr)->getSize (ptr); return getSuperblock(ptr)->getSize (ptr);
} }
inline void * malloc (size_t sz) { inline void * malloc (size_t sz) {
#if 0
if (sz < Alignment) { if (sz < Alignment) {
sz = Alignment; sz = Alignment;
} }
#endif
// Get memory from the local heap, // Get memory from the local heap,
// and deduct that amount from the local heap bytes counter. // and deduct that amount from the local heap bytes counter.
if (sz <= LargestObject) { if (sz <= LargestObject) {
auto c = getSizeClass (sz); auto c = getSizeClass (sz);
auto * ptr = _localHeap(c).get(); auto * ptr = _localHeap(c).get();
if (ptr) { if (ptr) {
assert (_localHeapBytes >= sz); assert (_localHeapBytes >= sz);
_localHeapBytes -= getClassSize (c); // sz; _localHeapBytes -= getClassSize (c); // sz;
assert (getSize(ptr) >= sz); assert (getSize(ptr) >= sz);
assert ((size_t) ptr % Alignment == 0); assert ((size_t) ptr % Alignment == 0);
skipping to change at line 108 skipping to change at line 110
} }
// No more local memory (for this size, at least). // No more local memory (for this size, at least).
// Now get the memory from our parent. // Now get the memory from our parent.
auto * ptr = _parentHeap->malloc (sz); auto * ptr = _parentHeap->malloc (sz);
assert ((size_t) ptr % Alignment == 0); assert ((size_t) ptr % Alignment == 0);
return ptr; return ptr;
} }
inline void free (void * ptr) { inline void free (void * ptr) {
if (!ptr) {
return;
}
auto * s = getSuperblock (ptr); auto * s = getSuperblock (ptr);
// If this isn't a valid superblock, just return. // If this isn't a valid superblock, just return.
if (s->isValidSuperblock()) { if (s && s->isValidSuperblock()) {
ptr = s->normalize (ptr); ptr = s->normalize (ptr);
auto sz = s->getObjectSize (); auto sz = s->getObjectSize ();
if ((sz <= LargestObject) && (sz + _localHeapBytes <= LocalHeapThreshold) ) { if ((sz <= LargestObject) && (sz + _localHeapBytes <= LocalHeapThreshold) ) {
// Free small objects locally, unless we are out of space. // Free small objects locally, unless we are out of space.
assert (getSize(ptr) >= sizeof(HL::SLList::Entry *)); assert (getSize(ptr) >= sizeof(HL::SLList::Entry *));
auto c = getSizeClass (sz); auto c = getSizeClass (sz);
 End of changes. 5 change blocks. 
9 lines changed or deleted 7 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)