![]() |
CARTA Backend
The backend component of CARTA
|
This struct stores the memory allocated for cached tile data. More...
#include <TilePool.h>
Classes | |
struct | TilePtrDeleter |
The custom deleter which allows discarded tiles to be returned to the pool. More... | |
Public Member Functions | |
TilePool () | |
Constructor. | |
void | Grow (int size) |
Grow the capacity of the pool. | |
TilePtr | Pull () |
Request a tile object from the pool. | |
void | Push (std::unique_ptr< std::vector< float > > &unique_tile) noexcept |
Return a tile object to the pool. | |
bool | Full () |
Check if the pool is full. | |
Private Member Functions | |
TilePtr | Create () |
Allocate a new tile object. | |
Private Attributes | |
std::mutex | _tile_pool_mutex |
The mutex used by functions which modify the stack. | |
std::stack< TilePtr > | _stack |
The stack where reusable tile objects are stored. | |
int | _capacity |
The maximum number of items which may be stored in the stack. | |
This struct stores the memory allocated for cached tile data.
Instead of repeatedly allocating and freeing memory for cached tile data, which has a significant performance cost, we keep a pool of allocated tile objects which are reused as tiles are read and discarded (up to a given capacity). The capacity of the pool should be 4 more than the capacity of the cache, so that we can always load a chunk before evicting anything.
|
inline |
Constructor.
|
private |
Allocate a new tile object.
bool TilePool::Full | ( | ) |
Check if the pool is full.
This function is called from the custom deleter which is attached to tile objects obtained from this pool.
void TilePool::Grow | ( | int | size | ) |
Grow the capacity of the pool.
size | the size increment to be added |
TilePtr TilePool::Pull | ( | ) |
Request a tile object from the pool.
If the pool is empty, a new tile object will be created.
|
noexcept |
Return a tile object to the pool.
unique_tile | a unique pointer to a tile object |
This function is called from the custom deleter which is attached to tile objects obtained from this pool.
|
private |
The maximum number of items which may be stored in the stack.
When capacity is reached, discarded tile objects are really deleted instead of being returned to the pool.
|
private |
The stack where reusable tile objects are stored.
|
private |
The mutex used by functions which modify the stack.