File tree Expand file tree Collapse file tree 1 file changed +7
-3
lines changed Expand file tree Collapse file tree 1 file changed +7
-3
lines changed Original file line number Diff line number Diff line change @@ -84,27 +84,30 @@ class AllocatorLog {
84
84
85
85
class SpyingAllocator : public ArduinoJson ::Allocator {
86
86
public:
87
+ SpyingAllocator (
88
+ Allocator* upstream = ArduinoJson::detail::DefaultAllocator::instance())
89
+ : _upstream(upstream) {}
87
90
virtual ~SpyingAllocator () {}
88
91
89
92
void * allocate (size_t n) override {
90
93
_log << AllocatorLog::Allocate (n);
91
94
auto block = reinterpret_cast <AllocatedBlock*>(
92
- malloc (sizeof (AllocatedBlock) + n - 1 ));
95
+ _upstream-> allocate (sizeof (AllocatedBlock) + n - 1 ));
93
96
block->size = n;
94
97
return block->payload ;
95
98
}
96
99
97
100
void deallocate (void * p) override {
98
101
auto block = AllocatedBlock::fromPayload (p);
99
102
_log << AllocatorLog::Deallocate (block->size );
100
- free (block);
103
+ _upstream-> deallocate (block);
101
104
}
102
105
103
106
void * reallocate (void * p, size_t n) override {
104
107
auto block = AllocatedBlock::fromPayload (p);
105
108
_log << AllocatorLog::Reallocate (block->size , n);
106
109
block = reinterpret_cast <AllocatedBlock*>(
107
- realloc (block, sizeof (AllocatedBlock) + n - 1 ));
110
+ _upstream-> reallocate (block, sizeof (AllocatedBlock) + n - 1 ));
108
111
block->size = n;
109
112
return block->payload ;
110
113
}
@@ -128,6 +131,7 @@ class SpyingAllocator : public ArduinoJson::Allocator {
128
131
};
129
132
130
133
AllocatorLog _log;
134
+ Allocator* _upstream;
131
135
};
132
136
133
137
class ControllableAllocator : public ArduinoJson ::Allocator {
You can’t perform that action at this time.
0 commit comments