Module rg3d_sound::pool[][src]

Expand description

Pool is contiguous block of memory with fixed-size entries, each entry can be either vacant or occupied. When you put an object into pool you get handle to that object. You can use that handle later on to borrow a reference to an object. Handle can point to some object or be invalid, this may look similar to raw pointers, but there is two major differences:

  1. We can check if handle is valid before accessing object it might point to.
  2. We can ensure that handle we using still valid for an object it points to. Each handle store special field that is shared across entry and handle, so handle is valid if these field in both handle and entry are same. This protects from situations where you have a handle that has valid index of a record, but payload in this record was replaced.

Contiguous memory block increases efficiency of memory operations - CPU will load portions of data into its cache piece by piece, it will be free from any indirections that might cause cache invalidation. This is so called cache friendliness.

Structs

ErasedHandle

Type-erased handle.

Handle

Handle is some sort of non-owning reference to content in a pool. It stores index of object and additional information that allows to ensure that handle is still valid (points to the same object as when handle was created).

Pool

Pool allows to create as many objects as you want in contiguous memory block. It allows to create and delete objects much faster than if they’ll be allocated on heap. Also since objects stored in contiguous memory block they can be effectively accessed because such memory layout is cache-friendly.

PoolIterator
PoolIteratorMut
PoolPairIterator
PoolPairIteratorMut
Ticket