CARTA Backend
The backend component of CARTA
Loading...
Searching...
No Matches
carta::TilePool Struct Reference

This struct stores the memory allocated for cached tile data. More...

#include <TilePool.h>

Inheritance diagram for carta::TilePool:
[legend]
Collaboration diagram for carta::TilePool:
[legend]

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.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ TilePool()

carta::TilePool::TilePool ( )
inline

Constructor.

Member Function Documentation

◆ Create()

TilePtr TilePool::Create ( )
private

Allocate a new tile object.

Returns
A tile object.
Here is the caller graph for this function:

◆ Full()

bool TilePool::Full ( )

Check if the pool is full.

Returns
Whether the pool has reached capacity.

This function is called from the custom deleter which is attached to tile objects obtained from this pool.

◆ Grow()

void TilePool::Grow ( int  size)

Grow the capacity of the pool.

Parameters
sizethe size increment to be added

◆ Pull()

TilePtr TilePool::Pull ( )

Request a tile object from the pool.

Returns
A tile object.

If the pool is empty, a new tile object will be created.

Here is the call graph for this function:

◆ Push()

void TilePool::Push ( std::unique_ptr< std::vector< float > > &  unique_tile)
noexcept

Return a tile object to the pool.

Parameters
unique_tilea unique pointer to a tile object

This function is called from the custom deleter which is attached to tile objects obtained from this pool.

Member Data Documentation

◆ _capacity

int carta::TilePool::_capacity
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.

◆ _stack

std::stack<TilePtr> carta::TilePool::_stack
private

The stack where reusable tile objects are stored.

◆ _tile_pool_mutex

std::mutex carta::TilePool::_tile_pool_mutex
private

The mutex used by functions which modify the stack.


The documentation for this struct was generated from the following files: