H.264 Codec for ESP32-S3
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | List of all members
RAMAllocatorH264< T > Class Template Reference

STL-compatible allocator that uses internal RAM (DRAM) allocation. More...

#include <RAMAllocatorH264.h>

Classes

struct  rebind
 Rebind allocator to different type. More...
 

Public Types

using value_type = T
 The type of objects this allocator can allocate.
 

Public Member Functions

 RAMAllocatorH264 () noexcept
 Default constructor.
 
template<class U >
 RAMAllocatorH264 (const RAMAllocatorH264< U > &) noexcept
 Copy constructor from different allocator type.
 
T * allocate (std::size_t n)
 Allocate memory for n objects of type T in internal RAM.
 
void deallocate (T *p, std::size_t) noexcept
 Deallocate memory previously allocated by this allocator.
 

Detailed Description

template<typename T = uint8_t>
class esp_h264::RAMAllocatorH264< T >

STL-compatible allocator that uses internal RAM (DRAM) allocation.

RAMAllocatorH264 is a custom C++ allocator that allocates memory from internal DRAM using heap_caps_aligned_calloc with MALLOC_CAP_INTERNAL. This ensures allocation from fast internal memory rather than external PSRAM.

This allocator is useful for ESP32 platforms when you specifically want small, frequently-accessed buffers to be stored in fast internal RAM rather than slower external PSRAM.

Template Parameters
TThe type of objects to allocate
Note
On ESP-IDF platforms, uses heap_caps_aligned_calloc for internal RAM allocation
On Arduino platforms, the heap_caps functions are shimmed to standard malloc/free
Memory is zero-initialized (calloc behavior)
Provides proper alignment for the allocated type

Example usage:

// Use with std::vector for small, fast buffers
std::vector<uint32_t, RAMAllocatorH264<uint32_t>> smallBuffer;
smallBuffer.resize(256); // Small buffer in fast internal RAM
// Or use the convenience alias
RAMVec<uint32_t> fastBuffer;
fastBuffer.resize(256);
Header-only C++ allocator that uses internal RAM (DRAM) on ESP32.
std::vector< T, RAMAllocatorH264< T > > RAMVec
Convenience type alias for vectors using RAMAllocatorH264.
Definition: RAMAllocatorH264.h:150

Member Typedef Documentation

◆ value_type

using value_type = T

The type of objects this allocator can allocate.

Constructor & Destructor Documentation

◆ RAMAllocatorH264() [1/2]

RAMAllocatorH264 ( )
inlinenoexcept

Default constructor.

Constructs a RAMAllocatorH264. No initialization needed.

◆ RAMAllocatorH264() [2/2]

RAMAllocatorH264 ( const RAMAllocatorH264< U > &  )
inlinenoexcept

Copy constructor from different allocator type.

Allows construction from RAMAllocatorH264 of different type U. Required for STL allocator requirements.

Template Parameters
UThe type parameter of the source allocator
Parameters
otherSource allocator (unused)

Member Function Documentation

◆ allocate()

T * allocate ( std::size_t  n)
inline

Allocate memory for n objects of type T in internal RAM.

Attempts to allocate memory in the following priority order:

  1. Internal RAM using heap_caps_aligned_calloc (if available)
  2. Aligned allocation using aligned_alloc (C11)
  3. Standard calloc as fallback

All allocated memory is zero-initialized.

Parameters
nNumber of objects of type T to allocate
Returns
Pointer to allocated memory
Exceptions
std::bad_allocif allocation fails
Note
Memory is aligned by 16
On ESP32, prefers internal DRAM allocation over PSRAM

◆ deallocate()

void deallocate ( T *  p,
std::size_t   
)
inlinenoexcept

Deallocate memory previously allocated by this allocator.

Frees memory that was allocated by allocate(). Uses heap_caps_free which works for both internal RAM and regular heap allocations.

Parameters
pPointer to memory to deallocate (can be nullptr)
nNumber of objects (ignored, but required by allocator interface)
Note
Safe to call with nullptr
The size parameter n is ignored as heap_caps_free doesn't need it

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