-
Notifications
You must be signed in to change notification settings - Fork 0
/
memory_check_example.ino
79 lines (68 loc) · 1.74 KB
/
memory_check_example.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include "src/SecuredLinkedList.h"
#include <Arduino.h>
void dumpMemory(String label) {
Serial.print("## "+label+" > ");
// Get the free heap memory
uint32_t freeHeap = ESP.getFreeHeap();
// Get the total heap
uint32_t totalHeap = ESP.getHeapSize();
// Calculate the used memory (heap)
uint32_t heapUsed = totalHeap - freeHeap;
// Calculate the percentage of used memory
float heapUsagePercent = ((float)heapUsed / totalHeap) * 100.0;
// Print memory information
Serial.print("Heap: ");
Serial.print(heapUsed);
Serial.print("/");
Serial.print(totalHeap);
Serial.print(" [");
Serial.print(heapUsagePercent);
Serial.print("%]\r\n");
}
void setup() {
Serial.begin(115200);
while (!Serial) {}
Serial.println("_____________");
dumpMemory("On startup. ");
SecuredLinkedList<int> list = SecuredLinkedList<int>();
dumpMemory("After instantiation");
// REMOVE
Serial.println("# REMOVE");
for(int i = 1; i <= 100; i++) {
list.push(i);
}
dumpMemory("Before ");
for(int i = 1; i <= 100; i++) {
list.remove(0);
}
dumpMemory("After ");
// POP
Serial.println("# POP");
for(int i = 1; i <= 100; i++) {
list.push(i);
}
dumpMemory("Before ");
for(int i = 1; i <= 100; i++) {
list.pop();
}
dumpMemory("After ");
// Shift
Serial.println("# SHIFT");
for(int i = 1; i <= 100; i++) {
list.push(i);
}
dumpMemory("Before ");
for(int i = 1; i <= 100; i++) {
list.shift();
}
dumpMemory("After ");
// CLEAR
Serial.println("# CLEAR");
for(int i = 1; i <= 100; i++) {
list.push(i);
}
dumpMemory("Before ");
list.clear();
dumpMemory("After ");
}
void loop() {}