I’m working on a library to make callbacks for webhooks a bit more friendly. In this library, I create a buffer for callback objects with fixed length response topics. The library is being set up to allow users to change the buffer size and response topic length. I was doing some memory use testing and am having trouble understanding the amount of memory used for the response topic char[]
Test code looks like this:
#include "Particle.h"
#include <functional>
class P_Promise{
public:
P_Promise(uint8_t charLen = 20){
responseTopic = new char[charLen];
}
bool inUse;
char* responseTopic;
uint32_t timeoutTime;
std::function<void(const char*, const char*)> successFunc;
std::function<void(const char*, const char*)> errorFunc;
std::function<void(void)> timeoutFunc;
std::function<void(void)> finalFunc;
};
class ParticlePromise{
public:
ParticlePromise(const uint8_t _containerSize = 5, const uint8_t _maxTopicLength = 20){
PromiseContainer = new P_Promise[_containerSize]{_maxTopicLength};
}
private:
P_Promise* PromiseContainer;
};
Here’s a link to my memory use data:
I’ve found that if I hold the buffer size steady at 5 objects, and increase the char[]
by 10, I only get an 8 byte increase in memory use. In my mind, it should be 1 byte per character, which would mean a 50 byte increase in memory use when increasing the char[]
by 10.