Remove memoryUsage()

This commit is contained in:
Benoit Blanchon
2023-07-24 17:21:25 +02:00
parent 2fdacb1ca0
commit 00c9d8680a
43 changed files with 1173 additions and 567 deletions

View File

@ -117,11 +117,16 @@ class SpyingAllocator : public ArduinoJson::Allocator {
: upstream_(upstream) {}
virtual ~SpyingAllocator() {}
size_t allocatedBytes() const {
return allocatedBytes_;
}
void* allocate(size_t n) override {
auto block = reinterpret_cast<AllocatedBlock*>(
upstream_->allocate(sizeof(AllocatedBlock) + n - 1));
if (block) {
log_ << AllocatorLog::Allocate(n);
allocatedBytes_ += n;
block->size = n;
return block->payload;
} else {
@ -132,6 +137,7 @@ class SpyingAllocator : public ArduinoJson::Allocator {
void deallocate(void* p) override {
auto block = AllocatedBlock::fromPayload(p);
allocatedBytes_ -= block->size;
log_ << AllocatorLog::Deallocate(block ? block->size : 0);
upstream_->deallocate(block);
}
@ -144,6 +150,7 @@ class SpyingAllocator : public ArduinoJson::Allocator {
if (block) {
log_ << AllocatorLog::Reallocate(oldSize, n);
block->size = n;
allocatedBytes_ += n - oldSize;
return block->payload;
} else {
log_ << AllocatorLog::ReallocateFail(oldSize, n);
@ -177,6 +184,7 @@ class SpyingAllocator : public ArduinoJson::Allocator {
AllocatorLog log_;
Allocator* upstream_;
size_t allocatedBytes_ = 0;
};
class ControllableAllocator : public ArduinoJson::Allocator {