| Flutter Impeller |

Public Member Functions | List of all members
impeller::Pool< T > Class Template Reference

A thread-safe pool with a limited byte size. More...

`#include <pool.h>`

## Public Member Functions
| Pool (uint32_t limit_bytes)
std::shared_ptr< T > | Grab ()
void | Recycle (std::shared_ptr< T > object)
uint32_t | GetSize () const

## Detailed Description

### template<typename T>
class impeller::Pool< T >

A thread-safe pool with a limited byte size.

Template Parameters

  T | The type that the pool will contain.

Definition at line 15 of file pool.h.

## Constructor & Destructor Documentation

## ◆ Pool()

template<typename T >

impeller::Pool< T >::Pool | ( | uint32_t | limit_bytes | ) |
| inline explicit

Definition at line 17 of file pool.h.

17 : limit_bytes_(limit_bytes) {}

## Member Function Documentation

## ◆ GetSize()

template<typename T >

uint32_t impeller::Pool< T >::GetSize | ( |  | ) | const
| inline

Definition at line 41 of file pool.h.

41 {
42 std::scoped_lock lock(mutex_);
43 return size_;
44 }

## ◆ Grab()

template<typename T >

std::shared_ptr<T> impeller::Pool< T >::Grab | ( |  | ) |
| inline

Definition at line 19 of file pool.h.

19 {
20 std::scoped_lock lock(mutex_);
21 if (pool_.empty()) {
22 return T::Create();
23 }
24 std::shared_ptr<T> result = std::move(pool_.back());
25 pool_.pop_back();
26 size_ -= result->GetSize();
27 return result;
28 }

## ◆ Recycle()

template<typename T >

void impeller::Pool< T >::Recycle | ( | std::shared_ptr< T > | object | ) |
| inline

Definition at line 30 of file pool.h.

30 {
31 std::scoped_lock lock(mutex_);
32 size_t object_size = object->GetSize();
33 if (size_ + object_size <= limit_bytes_ &&
34 object_size < (limit_bytes_ / 2)) {
35 object->Reset();
36 size_ += object_size;
37 pool_.emplace_back(std::move(object));
38 }
39 }

The documentation for this class was generated from the following file:

- impeller/renderer/pool.h