Esp32S3 : How to improve external RAM usage ?

ThomasESP32
Posts: 229
Joined: Thu Jul 14, 2022 5:15 am

Esp32S3 : How to improve external RAM usage ?

Postby ThomasESP32 » Mon Jun 12, 2023 6:39 am

Good morning,

I have a program running on an Esp32S3 having 2Mo of external RAM.
I have found how to use this external RAM with dynamic allocation using the heaps_caps_malloc function.

However, I would like to improve this memory usage and I am wondering if there is the possibility to put more things
in it, for example classes memory.

In order to instantiate classes, I am using the new operator and it seems that the classes are instantiated into internal RAM
by default.
Is there the possibility to overload the new operator so that classes memory is allocated using the heaps_caps_malloc function
or something like that ?
Do you know how to do it (If it is possible ?)

Best regards,

Thomas TRUILHE

MicroController
Posts: 1709
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: Esp32S3 : How to improve external RAM usage ?

Postby MicroController » Mon Jun 12, 2023 9:07 am

There are several options:
  • You can use "placement new" to initialize an object at an address you provide, e.g. from an allocation in external RAM.
  • With standard containers like std::list, you can provide an allocator to be used.
  • You can provide "class-specific overloads" of new for individual classes.
  • You can also globally "replace" the new operator, but that would affect all C++ allocations.
Moving individual objects to external RAM may not be very useful as instances are usually relatively small, unless they contain bigger arrays members.
For classes which have array member fields, you could consider replacing the array with a pointer and malloc/free the required memory in the constructor/destructor of the class, so that the object's instance can be standard-allocated in internal RAM but the array resides in external RAM.

Who is online

Users browsing this forum: No registered users and 111 guests