"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/include/superblocks/manageonesuperblock.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).

manageonesuperblock.h  (Hoard-3.12):manageonesuperblock.h  (Hoard-3.13)
// -*- C++ -*- // -*- C++ -*-
/* /*
The Hoard Multiprocessor Memory Allocator The Hoard Multiprocessor Memory Allocator
www.hoard.org www.hoard.org
Author: Emery Berger, http://www.cs.umass.edu/~emery Author: Emery Berger, http://www.emeryberger.com
Copyright (c) 1998-2012 Emery Berger Copyright (c) 1998-2018 Emery Berger
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or the Free Software Foundation; either version 2 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
/** /**
* @file manageonesuperblock.h * @file manageonesuperblock.h
* @author Emery Berger <http://www.cs.umass.edu/~emery> * @author Emery Berger <http://www.emeryberger.com>
*/ */
#ifndef HOARD_MANAGEONESUPERBLOCK_H #ifndef HOARD_MANAGEONESUPERBLOCK_H
#define HOARD_MANAGEONESUPERBLOCK_H #define HOARD_MANAGEONESUPERBLOCK_H
/** /**
* @class ManageOneSuperblock * @class ManageOneSuperblock
* @brief A layer that caches exactly one superblock, thus avoiding costly look ups. * @brief A layer that caches exactly one superblock, thus avoiding costly look ups.
* @author Emery Berger <http://www.cs.umass.edu/~emery> * @author Emery Berger <http://www.cs.umass.edu/~emery>
*/ */
namespace Hoard { namespace Hoard {
template <class SuperHeap> template <class SuperHeap>
class ManageOneSuperblock : public SuperHeap { class ManageOneSuperblock : public SuperHeap {
public: public:
ManageOneSuperblock() ManageOneSuperblock()
: _current (NULL) : _current (nullptr)
{} {}
typedef typename SuperHeap::SuperblockType SuperblockType; typedef typename SuperHeap::SuperblockType SuperblockType;
/// Get memory from the current superblock. /// Get memory from the current superblock.
inline void * malloc (size_t sz) { inline void * malloc (size_t sz) {
if (_current) { if (_current) {
void * ptr = _current->malloc (sz); void * ptr = _current->malloc (sz);
if (ptr) { if (ptr) {
assert (_current->getSize(ptr) >= sz); assert (_current->getSize(ptr) >= sz);
skipping to change at line 82 skipping to change at line 82
} else { } else {
// It wasn't ours, so free it remotely. // It wasn't ours, so free it remotely.
SuperHeap::free (ptr); SuperHeap::free (ptr);
} }
} }
/// Get the current superblock and remove it. /// Get the current superblock and remove it.
SuperblockType * get() { SuperblockType * get() {
if (_current) { if (_current) {
SuperblockType * s = _current; SuperblockType * s = _current;
_current = NULL; _current = nullptr;
return s; return s;
} else { } else {
// There's none cached, so just get one from the superheap. // There's none cached, so just get one from the superheap.
return SuperHeap::get(); return SuperHeap::get();
} }
} }
/// Put the superblock into the cache. /// Put the superblock into the cache.
inline void put (SuperblockType * s) { inline void put (SuperblockType * s) {
if (!s || (s == _current) || (!s->isValidSuperblock())) { if (!s || (s == _current) || (!s->isValidSuperblock())) {
// Ignore if we already are holding this superblock, of if we // Ignore if we already are holding this superblock, of if we
// got a NULL pointer, or if it's invalid. // got a nullptr, or if it's invalid.
return; return;
} }
if (_current) { if (_current) {
// We have one already -- push it out. // We have one already -- push it out.
SuperHeap::put (_current); SuperHeap::put (_current);
} }
_current = s; _current = s;
} }
private: private:
/// Obtain a superblock and return an object from it. /// Obtain a superblock and return an object from it.
void * slowMallocPath (size_t sz) { void * slowMallocPath (size_t sz) {
void * ptr = NULL; void * ptr = nullptr;
while (!ptr) { while (!ptr) {
// If we don't have a superblock, get one. // If we don't have a superblock, get one.
if (!_current) { if (!_current) {
_current = SuperHeap::get(); _current = SuperHeap::get();
if (!_current) { if (!_current) {
// Out of memory. // Out of memory.
return NULL; return nullptr;
} }
} }
// Try to allocate memory from it. // Try to allocate memory from it.
ptr = _current->malloc (sz); ptr = _current->malloc (sz);
if (!ptr) { if (!ptr) {
// No memory left: put the superblock away and get a new one next time. // No memory left: put the superblock away and get a new one next time.
SuperHeap::put (_current); SuperHeap::put (_current);
_current = NULL; _current = nullptr;
} }
} }
return ptr; return ptr;
} }
/// The current superblock. /// The current superblock.
SuperblockType * _current; SuperblockType * _current;
}; };
 End of changes. 9 change blocks. 
9 lines changed or deleted 9 lines changed or added

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