// 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.