Skip to content

add custom allocator to make sure that vector arrays go into PSRAM when availeable #1

Closed

Description

@softhack007

std::vector<std::vector<float>> polar_theta; // look-up table for polar angles
std::vector<std::vector<float>> distance; // look-up table for polar distances

void render_polar_lookup_table(float cx, float cy) {
polar_theta.resize(num_x, std::vector<float>(num_y, 0.0f));
distance.resize(num_x, std::vector<float>(num_y, 0.0f));

We need better control of array placement for boards with PSRAM. Normally on esp32, big allocations automatically go into PRSAM. However due to the 2D vector definitions used for the lookup tables, each "row" vector is only 256 bytes and the framework will only put these into PSRAM if there is not enough RAM or PSRAM is very fast (opi_opi mode).

The standard way with vectors seems to be: add a custom allocator to the vector declaration , like the "Mallocator" in this example:
https://learn.microsoft.com/en-us/cpp/standard-library/allocators?view=msvc-170

For compatibility with the vector template class, it seems that operator== and operator!= must be implemented by the Mallocator, too.

The custom allocator should use ps_malloc() and free().

The custom allocator code should only be used on ESP32 with PSRAM, i.e.

#ifdef ESP32
#if defined(BOARD_HAS_PSRAM) && defined(CONFIG_IDF_TARGET_ESP32S3)
[...]
#endif
#endif

Activity

  1. changed the title [-]add custom allocator to make sure that vector arrays go into PSRAM[/-] [+]add custom allocator to make sure that vector arrays go into PSRAM when availeable[/+] on Jan 19, 2026
  2. softhack007 commented on Jan 19, 2026

    @softhack007
    OwnerAuthor

    @ewowi and @netmindz: can you review the proposed changes in PR #2 ? I don't have much experience with C++ vectors, so I'm basically doing this in "blind flight" mode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions