- Notifications
You must be signed in to change notification settings - Fork7.8k
-
Boardany Device Descriptionesp32s3 dev module Hardware Configurationno connections except UART0 and power Versionlatest stable Release (if not listed below) TypeBug IDE NameArduino IDE Operating SystemWindows 10 Flash frequency80 PSRAM enabledyes Upload speed115200 Descriptionclass EspClass of Arduino Core (Esp.cpp) has getters for heap size/free size/etc, which for some reason return values of internal memory only. In particular, on my esp32s3 these return values below 300kb, while malloc() can allocate up to 8MB. Proposed fix is extremely simple: Replace MALLOC_CAP_INTERNAL with MALLOC_CAP_DEFAULT in functions: [code] uint32_t EspClass::getFreeHeap(void) { uint32_t EspClass::getMinFreeHeap(void) { uint32_t EspClass::getMaxAllocHeap(void) { It would be better if we can get real sizes with ::getFreeHeap(). For rare cases when we need to know INTERNAL memory sizes, we can use specific queries, like uint32_t EspClass::getSRAMSize(void) Sketchuint32_t size1 = ESP.getHeapSize();uint32_t size2 = heap_caps_get_total_size(MALLOC_CAP_DEFAULT);if (size2 != size1) Serial.printf("size1=%lu, size2=%lu\r\n",size1,size2) Debug MessageOther Steps to ReproduceNo response I have checked existing issues, online documentation and the Troubleshooting Guide
|
BetaWas this translation helpful?Give feedback.
All reactions
Replies: 1 comment 1 reply
-
There are different reasons why this is so:
|
BetaWas this translation helpful?Give feedback.
All reactions
-
But now SPIRAMis available to malloc, so may be it is good idea to update these getters? How I see this: user calls getter function to query memory size and then calls malloc() or new(). In this case it is safe to replace _INTERNAL to _DEFAULT - getter will return values larger than before so it should not break any existing code. It is also seems right to hide all these internal/spi/etc things from the class user. If it is heap - it is heap and we should return actual size. For those rare cases when user requires INTERNAL memory (for DMA buffers for example) - he/she will likely use heap_caps_malloc(). Since SPIRAM is under malloc()/MALLOC_CAPS_DEFAULT now, may be it is worth to remove ...Psram() functions entirely, from class ESP: it will make programming more transparent. Users don't have to think about SPI/INTERNAL RAM at all. They just call getHeapSize() or getHeapFreeSize() and then do (or don't) allocations. Just an opinion. |
BetaWas this translation helpful?Give feedback.
All reactions
This discussion was converted from issue #12010 on November 11, 2025 09:20.