/* Memory pool for persistent small- to medium-sized allocations. * *SomeAImusingsonthis,notnecessarilytrue: * *Thisisaverysimpleimplementation,butit'sgoodenoughforour *purposes.It'snotthread-safe.It'snotveryfast.It'snot *verymemoryefficient.It'snotverycacheefficient.It'snot *veryanythingefficient.Butit'ssimpleanditworks.Andit's *goodenoughforourpurposes.Ifyouneedsomethingmore
* sophisticated, use a real allocator. Or use a real language. */
assert (alignment > 0);
assert (alignment <= 2 * sizeof (void *));
assert ((alignment & (alignment - 1)) == 0); /* power of two */
if (size > (ChunkSize) / 4)
{ /* Big chunk, allocate separately. */
hb_vector_t<char> chunk; if (unlikely (!chunk.resize (size))) return nullptr; void *ret = chunk.arrayZ;
chunks.push (std::move (chunk)); if (chunks.in_error ()) return nullptr; if (chunks.length > 1)
{ // Bring back the previous last chunk to the end, so that // we can continue to allocate from it.
hb_swap (chunks.arrayZ[chunks.length - 1], chunks.arrayZ[chunks.length - 2]);
} return ret;
}
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.