/* * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2020 SAP SE. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. *
*/
// BinList is a data structure to manage small to very small memory blocks // (only a few words). It is used to manage deallocated blocks - see // class FreeBlocks.
// Memory blocks are kept in linked lists. Each list // contains blocks of only one size. There is a list for blocks of two words, // for blocks of three words, etc. The list heads are kept in a vector, // ordered by block size. //
// Insertion is of course fast, O(1). // // On retrieval, we attempt to find the closest fit to a given size, walking the // list head vector (a bitmask is used to speed that part up). // // This structure is a bit expensive in memory costs (we pay one pointer per managed // block size) so we only use it for a small number of sizes.
template <size_t smallest_word_size, int num_lists> class BinListImpl {
// Smallest block size must be large enough to hold a Block structure.
STATIC_ASSERT(smallest_word_size * sizeof(MetaWord) >= sizeof(Block));
STATIC_ASSERT(num_lists > 0);
public:
// Minimal word size a block must have to be manageable by this structure. conststatic size_t MinWordSize = smallest_word_size;
// Maximal (incl) word size a block can have to be manageable by this structure. conststatic size_t MaxWordSize = MinWordSize + num_lists - 1;
private:
Block* _blocks[num_lists];
MemRangeCounter _counter;
staticint index_for_word_size(size_t word_size) { int index = (int)(word_size - MinWordSize);
assert(index >= 0 && index < num_lists, "Invalid index %d", index); return index;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.