mirror of
https://github.com/wled/WLED.git
synced 2025-07-12 21:36:32 +00:00
Reduce memory fragmentation
This commit is contained in:
parent
076449a33d
commit
3d6fe0a565
@ -144,10 +144,13 @@ Segment& Segment::operator= (Segment &&orig) noexcept {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool IRAM_ATTR Segment::allocateData(size_t len) {
|
bool IRAM_ATTR Segment::allocateData(size_t len) {
|
||||||
if (data && _dataLen == len) return true; //already allocated
|
if (data && _dataLen >= len) { // already allocated enough (reduce fragmentation)
|
||||||
|
if (call == 0) memset(data, 0, len); // erase buffer if called during effect initialisation
|
||||||
|
return true;
|
||||||
|
}
|
||||||
//DEBUG_PRINTF("-- Allocating data (%d): %p\n", len, this);
|
//DEBUG_PRINTF("-- Allocating data (%d): %p\n", len, this);
|
||||||
deallocateData();
|
deallocateData();
|
||||||
if (len == 0) return(false); // nothing to do
|
if (len == 0) return false; // nothing to do
|
||||||
if (Segment::getUsedSegmentData() + len > MAX_SEGMENT_DATA) {
|
if (Segment::getUsedSegmentData() + len > MAX_SEGMENT_DATA) {
|
||||||
// not enough memory
|
// not enough memory
|
||||||
DEBUG_PRINT(F("!!! Effect RAM depleted: "));
|
DEBUG_PRINT(F("!!! Effect RAM depleted: "));
|
||||||
@ -156,7 +159,7 @@ bool IRAM_ATTR Segment::allocateData(size_t len) {
|
|||||||
}
|
}
|
||||||
// do not use SPI RAM on ESP32 since it is slow
|
// do not use SPI RAM on ESP32 since it is slow
|
||||||
data = (byte*) malloc(len);
|
data = (byte*) malloc(len);
|
||||||
if (!data) { DEBUG_PRINTLN(F("!!! Allocation failed. !!!")); return false; } //allocation failed
|
if (!data) { DEBUG_PRINTLN(F("!!! Allocation failed. !!!")); return false; } // allocation failed
|
||||||
Segment::addUsedSegmentData(len);
|
Segment::addUsedSegmentData(len);
|
||||||
//DEBUG_PRINTF("--- Allocated data (%p): %d/%d -> %p\n", this, len, Segment::getUsedSegmentData(), data);
|
//DEBUG_PRINTF("--- Allocated data (%p): %d/%d -> %p\n", this, len, Segment::getUsedSegmentData(), data);
|
||||||
_dataLen = len;
|
_dataLen = len;
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// version code in format yymmddb (b = daily build)
|
// version code in format yymmddb (b = daily build)
|
||||||
#define VERSION 2312020
|
#define VERSION 2312160
|
||||||
|
|
||||||
//uncomment this if you have a "my_config.h" file you'd like to use
|
//uncomment this if you have a "my_config.h" file you'd like to use
|
||||||
//#define WLED_USE_MY_CONFIG
|
//#define WLED_USE_MY_CONFIG
|
||||||
|
Loading…
x
Reference in New Issue
Block a user