| 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 17 of file pool.h.

## Constructor & Destructor Documentation

## ◆ Pool()

template<typename T >

impeller::Pool< T >::Pool | ( | uint32_t | limit_bytes | ) |
| inlineexplicit

Definition at line 19 of file pool.h.

19 : limit_bytes_(limit_bytes) {}

## Member Function Documentation

## ◆ GetSize()

template<typename T >

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

Definition at line 43 of file pool.h.

43 {
44 std::scoped_lock lock(mutex_);
45 return size_;
46 }

## ◆ Grab()

template<typename T >

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

Definition at line 21 of file pool.h.

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

References impeller::interop::Create().

## ◆ Recycle()

template<typename T >

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

Definition at line 32 of file pool.h.

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

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

- impeller/renderer/pool.h

impeller::interop::Create
ScopedObject< Object > Create(CtorArgs &&... args)
Definition: object.h:160