// Creates a pool to store objects during program creation. Call attachToThread() to start using // the pool for its allocations. When your program is complete, call pool->detachFromThread() to // take ownership of the pool and its allocations. Before freeing any of the program's // allocations, make sure to reattach the pool by calling pool->attachToThread() again. static std::unique_ptr<Pool> Create();
// Attaches a pool to the current thread. // It is an error to call this while a pool is already attached. void attachToThread();
// Once you are done creating or destroying objects in the pool, detach it from the thread. // It is an error to call this while no pool is attached. void detachFromThread();
// Allocates memory from the thread pool. If the pool is exhausted, an additional block of pool // storage will be created to hold the data. staticvoid* AllocMemory(size_t size);
// Releases memory that was created by AllocMemory. All objects in the pool must be freed before // the pool can be destroyed. staticvoid FreeMemory(void* ptr);
staticbool IsAttached();
private:
Pool(); // use Create to make a pool
std::unique_ptr<SkSL::MemoryPool> fMemPool;
};
/** *IfyourclassinheritsfromPoolable,itsobjectswillbeallocatedfromthepool.
*/ class Poolable {
public: // Override operator new and delete to allow us to use a memory pool. staticvoid* operatornew(const size_t size) { return Pool::AllocMemory(size);
}
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.