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
Esp32S3 : How to improve external RAM usage ?
-
- Posts: 229
- Joined: Thu Jul 14, 2022 5:15 am
-
- Posts: 1709
- Joined: Mon Oct 17, 2022 7:38 pm
- Location: Europe, Germany
Re: Esp32S3 : How to improve external RAM usage ?
There are several options:
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.
- 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.
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: Baidu [Spider], Majestic-12 [Bot] and 94 guests