Added HS_REALLOC macro for generalized realloc() when using PSRAM

When using PSRAM, changing the number of Accessories no longer creates any change to heap usage on internal RAM.  The entire Accessory will be stored in PSRAM.
This commit is contained in:
Gregg 2023-11-21 18:36:51 -06:00
parent 458a4fb357
commit 2bc107032c
3 changed files with 8 additions and 6 deletions

View File

@ -2071,7 +2071,7 @@ SpanCharacteristic *SpanCharacteristic::setValidValues(int n, ...){
va_end(vl); va_end(vl);
s+="]"; s+="]";
validValues=(char *)realloc(validValues, strlen(s.c_str()) + 1); validValues=(char *)HS_REALLOC(validValues, strlen(s.c_str()) + 1);
strcpy(validValues,s.c_str()); strcpy(validValues,s.c_str());
return(this); return(this);
@ -2202,7 +2202,7 @@ void SpanWebLog::vLog(boolean sysMsg, const char *fmt, va_list ap){
else else
log[index].clockTime.tm_year=0; log[index].clockTime.tm_year=0;
log[index].message=(char *)realloc(log[index].message, strlen(buf) + 1); log[index].message=(char *)HS_REALLOC(log[index].message, strlen(buf) + 1);
strcpy(log[index].message, buf); strcpy(log[index].message, buf);
log[index].clientIP=homeSpan.lastClientIP; log[index].clientIP=homeSpan.lastClientIP;

View File

@ -34,10 +34,12 @@
#if defined(BOARD_HAS_PSRAM) #if defined(BOARD_HAS_PSRAM)
#define HS_MALLOC ps_malloc #define HS_MALLOC ps_malloc
#define HS_CALLOC ps_calloc #define HS_CALLOC ps_calloc
#define HS_REALLOC ps_realloc
#define ps_new(X) new(ps_malloc(sizeof(X)))X #define ps_new(X) new(ps_malloc(sizeof(X)))X
#else #else
#define HS_MALLOC malloc #define HS_MALLOC malloc
#define HS_CALLOC calloc #define HS_CALLOC calloc
#define HS_REALLOC realloc
#define ps_new(X) new X #define ps_new(X) new X
#endif #endif
@ -552,7 +554,7 @@ class SpanCharacteristic{
} }
void uvSet(UVal &u, const char *val){ void uvSet(UVal &u, const char *val){
u.STRING = (char *)realloc(u.STRING, strlen(val) + 1); u.STRING = (char *)HS_REALLOC(u.STRING, strlen(val) + 1);
strcpy(u.STRING, val); strcpy(u.STRING, val);
} }
@ -830,13 +832,13 @@ class SpanCharacteristic{
} }
SpanCharacteristic *setDescription(const char *c){ SpanCharacteristic *setDescription(const char *c){
desc = (char *)realloc(desc, strlen(c) + 1); desc = (char *)HS_REALLOC(desc, strlen(c) + 1);
strcpy(desc, c); strcpy(desc, c);
return(this); return(this);
} }
SpanCharacteristic *setUnit(const char *c){ SpanCharacteristic *setUnit(const char *c){
unit = (char *)realloc(unit, strlen(c) + 1); unit = (char *)HS_REALLOC(unit, strlen(c) + 1);
strcpy(unit, c); strcpy(unit, c);
return(this); return(this);
} }

View File

@ -40,7 +40,7 @@ void setup() {
ps_new(Service::AccessoryInformation)(); ps_new(Service::AccessoryInformation)();
ps_new(Characteristic::Identify)(); ps_new(Characteristic::Identify)();
for(int i=0;i<80;i++){ for(int i=0;i<100;i++){
ps_new(SpanAccessory)(); ps_new(SpanAccessory)();
ps_new(Service::AccessoryInformation)(); ps_new(Service::AccessoryInformation)();
ps_new(Characteristic::Identify)(); ps_new(Characteristic::Identify)();