#include <SdFat.h>
class heapDebugger {
private:
public:
auto printHeapAddr(void*, const char*, int) -> void;
};
heapDebugger _heapDebugger;
SdFat _SdFat; // example object
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
int value = 5; // Eine Variable
int *ptr1 = &value; // ptr1 enthält die Adresse von value
int *ptr2 = ptr1; // ptr2 enthält nun auch die Adresse von value, die gleiche wie ptr1
// Example with pointer variable
_heapDebugger.printHeapAddr(ptr1, __FILE__, __LINE__);
// Example with SdFat Object
_heapDebugger.printHeapAddr(&_SdFat, __FILE__, __LINE__);
}
void loop() {
// put your main code here, to run repeatedly:
}
/**
* @brief get Heap Addr of any pointer
*
* @param p use & operator if you want to pass a no pointer datatype
* @param _FILE please pass __FILE__
* @param _LINE please pass __LINE__
*/
auto heapDebugger::printHeapAddr(void* p, const char* _FILE, int _LINE) -> void
{
if(!Serial)
return;
char HeapAddr[10];
sprintf(HeapAddr,"%p",(void*)p);
Serial.print("Pointer Address : " + String(HeapAddr) + " | ");
Serial.print("In File "+ String(_FILE));
Serial.println(" at Line " + String(_LINE));
}