[GH-ISSUE #1000] Feature Idea: self allocated (statically) declared parameters #852

Open
opened 2026-02-28 01:27:20 +03:00 by kerem · 0 comments
Owner

Originally created by @Bilgus on GitHub (Jan 31, 2020).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1000

Parameters are alloc'd and copied from the source variable
it would be nice to have the option to supply the buffer myself
especially considering the eeprom code I'm using already makes a copy of the structure from flash

the changes I made are from the dev branch

WiFiManager.h:
class WiFiManagerParameter
public:
WiFiManagerParameter(const char *id, const char *label, char *buffer, int length); WiFiManagerParameter(const char *id, const char *label, char *buffer, int length, const char *custom); WiFiManagerParameter(const char *id, const char *label, char *buffer, int length, const char *custom, int labelPlacement);
protected:
void init_buf(const char *id, const char *label, char *buffer, int length, const char *custom, int labelPlacement);

private:
bool _allocd;

WifiManager.cpp

WiFiManagerParameter::WiFiManagerParameter(const char *id, const char *label, char *buffer, int length) { init_buf(id, label, buffer, length, "", WFM_LABEL_BEFORE); }

WiFiManagerParameter::WiFiManagerParameter(const char *id, const char *label, char *buffer, int length, const char *custom) { init_buf(id, label, buffer, length, custom, WFM_LABEL_BEFORE); }

WiFiManagerParameter::WiFiManagerParameter(const char *id, const char *label, char *buffer, int length, const char *custom, int labelPlacement) { init_buf(id, label, buffer, length, custom, labelPlacement); }

void WiFiManagerParameter::init(const char *id, const char *label, const char *defaultValue, int length, const char *custom, int labelPlacement) { _id = id; _label = label; _labelPlacement = labelPlacement; _customHTML = custom; setValue(defaultValue,length); _allocd = true; }

void WiFiManagerParameter::init_buf(const char *id, const char *label, char *buffer, int length, const char *custom, int labelPlacement) { _id = id; _label = label; _labelPlacement = labelPlacement; _customHTML = custom; _length = length; _value = buffer; _allocd = false; if (length > 0) buffer[length-1] = '\0'; else _value = NULL; }

WiFiManagerParameter::~WiFiManagerParameter() { if (_value != NULL && _allocd) { delete[] _value; } _length=0; // setting length 0, ideally the entire parameter should be removed, or added to wifimanager scope so it follows }

Originally created by @Bilgus on GitHub (Jan 31, 2020). Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1000 Parameters are alloc'd and copied from the source variable it would be nice to have the option to supply the buffer myself especially considering the eeprom code I'm using already makes a copy of the structure from flash the changes I made are from the dev branch WiFiManager.h: class WiFiManagerParameter public: ` WiFiManagerParameter(const char *id, const char *label, char *buffer, int length); WiFiManagerParameter(const char *id, const char *label, char *buffer, int length, const char *custom); WiFiManagerParameter(const char *id, const char *label, char *buffer, int length, const char *custom, int labelPlacement);` protected: ` void init_buf(const char *id, const char *label, char *buffer, int length, const char *custom, int labelPlacement);` private: ` bool _allocd;` WifiManager.cpp `WiFiManagerParameter::WiFiManagerParameter(const char *id, const char *label, char *buffer, int length) { init_buf(id, label, buffer, length, "", WFM_LABEL_BEFORE); }` `WiFiManagerParameter::WiFiManagerParameter(const char *id, const char *label, char *buffer, int length, const char *custom) { init_buf(id, label, buffer, length, custom, WFM_LABEL_BEFORE); }` `WiFiManagerParameter::WiFiManagerParameter(const char *id, const char *label, char *buffer, int length, const char *custom, int labelPlacement) { init_buf(id, label, buffer, length, custom, labelPlacement); }` `void WiFiManagerParameter::init(const char *id, const char *label, const char *defaultValue, int length, const char *custom, int labelPlacement) { _id = id; _label = label; _labelPlacement = labelPlacement; _customHTML = custom; setValue(defaultValue,length); _allocd = true; }` `void WiFiManagerParameter::init_buf(const char *id, const char *label, char *buffer, int length, const char *custom, int labelPlacement) { _id = id; _label = label; _labelPlacement = labelPlacement; _customHTML = custom; _length = length; _value = buffer; _allocd = false; if (length > 0) buffer[length-1] = '\0'; else _value = NULL; }` `WiFiManagerParameter::~WiFiManagerParameter() { if (_value != NULL && _allocd) { delete[] _value; } _length=0; // setting length 0, ideally the entire parameter should be removed, or added to wifimanager scope so it follows }`
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/WiFiManager#852
No description provided.