mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-29 02:07:32 +02:00
Rename VariantPool
to MemoryPool
This commit is contained in:
@ -5,8 +5,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <ArduinoJson/Memory/Allocator.hpp>
|
||||
#include <ArduinoJson/Memory/MemoryPool.hpp>
|
||||
#include <ArduinoJson/Memory/StringBuilder.hpp>
|
||||
#include <ArduinoJson/Memory/VariantPool.hpp>
|
||||
|
||||
#include <sstream>
|
||||
|
||||
@ -265,12 +265,12 @@ class TimebombAllocator : public ArduinoJson::Allocator {
|
||||
} // namespace
|
||||
|
||||
inline size_t sizeofPoolList(size_t n = ARDUINOJSON_INITIAL_POOL_COUNT) {
|
||||
return sizeof(ArduinoJson::detail::VariantPool) * n;
|
||||
return sizeof(ArduinoJson::detail::MemoryPool) * n;
|
||||
}
|
||||
|
||||
inline size_t sizeofPool(
|
||||
ArduinoJson::detail::SlotCount n = ARDUINOJSON_POOL_CAPACITY) {
|
||||
return ArduinoJson::detail::VariantPool::slotsToBytes(n);
|
||||
return ArduinoJson::detail::MemoryPool::slotsToBytes(n);
|
||||
}
|
||||
|
||||
inline size_t sizeofStringBuffer(size_t iteration = 1) {
|
||||
|
@ -2,8 +2,8 @@
|
||||
// Copyright © 2014-2024, Benoit BLANCHON
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson/Memory/MemoryPoolImpl.hpp>
|
||||
#include <ArduinoJson/Memory/StringBuilder.hpp>
|
||||
#include <ArduinoJson/Memory/VariantPoolImpl.hpp>
|
||||
#include <catch.hpp>
|
||||
|
||||
#include "Allocators.hpp"
|
||||
|
@ -2,9 +2,9 @@
|
||||
// Copyright © 2014-2024, Benoit BLANCHON
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson/Memory/MemoryPoolImpl.hpp>
|
||||
#include <ArduinoJson/Memory/ResourceManager.hpp>
|
||||
#include <ArduinoJson/Memory/ResourceManagerImpl.hpp>
|
||||
#include <ArduinoJson/Memory/VariantPoolImpl.hpp>
|
||||
#include <ArduinoJson/Strings/StringAdapters.hpp>
|
||||
#include <catch.hpp>
|
||||
|
||||
|
@ -2,8 +2,8 @@
|
||||
// Copyright © 2014-2024, Benoit BLANCHON
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson/Memory/MemoryPoolImpl.hpp>
|
||||
#include <ArduinoJson/Memory/ResourceManager.hpp>
|
||||
#include <ArduinoJson/Memory/VariantPoolImpl.hpp>
|
||||
#include <ArduinoJson/Strings/StringAdapters.hpp>
|
||||
#include <catch.hpp>
|
||||
|
||||
|
@ -2,9 +2,9 @@
|
||||
// Copyright © 2014-2024, Benoit BLANCHON
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson/Memory/MemoryPoolImpl.hpp>
|
||||
#include <ArduinoJson/Memory/ResourceManager.hpp>
|
||||
#include <ArduinoJson/Memory/ResourceManagerImpl.hpp>
|
||||
#include <ArduinoJson/Memory/VariantPoolImpl.hpp>
|
||||
#include <catch.hpp>
|
||||
|
||||
#include "Allocators.hpp"
|
||||
|
@ -2,9 +2,9 @@
|
||||
// Copyright © 2014-2024, Benoit BLANCHON
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson/Memory/MemoryPoolImpl.hpp>
|
||||
#include <ArduinoJson/Memory/ResourceManager.hpp>
|
||||
#include <ArduinoJson/Memory/ResourceManagerImpl.hpp>
|
||||
#include <ArduinoJson/Memory/VariantPoolImpl.hpp>
|
||||
#include <catch.hpp>
|
||||
|
||||
#include "Allocators.hpp"
|
||||
|
@ -3,9 +3,9 @@
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson/Memory/Alignment.hpp>
|
||||
#include <ArduinoJson/Memory/MemoryPoolImpl.hpp>
|
||||
#include <ArduinoJson/Memory/ResourceManager.hpp>
|
||||
#include <ArduinoJson/Memory/ResourceManagerImpl.hpp>
|
||||
#include <ArduinoJson/Memory/VariantPoolImpl.hpp>
|
||||
#include <catch.hpp>
|
||||
|
||||
#include "Allocators.hpp"
|
||||
|
@ -36,8 +36,8 @@
|
||||
#include "ArduinoJson/Array/ElementProxy.hpp"
|
||||
#include "ArduinoJson/Array/Utilities.hpp"
|
||||
#include "ArduinoJson/Collection/CollectionImpl.hpp"
|
||||
#include "ArduinoJson/Memory/MemoryPoolImpl.hpp"
|
||||
#include "ArduinoJson/Memory/ResourceManagerImpl.hpp"
|
||||
#include "ArduinoJson/Memory/VariantPoolImpl.hpp"
|
||||
#include "ArduinoJson/Object/MemberProxy.hpp"
|
||||
#include "ArduinoJson/Object/ObjectImpl.hpp"
|
||||
#include "ArduinoJson/Variant/ConverterImpl.hpp"
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ArduinoJson/Memory/ResourceManager.hpp>
|
||||
#include <ArduinoJson/Memory/Allocator.hpp>
|
||||
#include <ArduinoJson/Polyfills/assert.hpp>
|
||||
#include <ArduinoJson/Polyfills/integer.hpp>
|
||||
|
||||
@ -44,7 +44,7 @@ class SlotWithId {
|
||||
SlotId id_;
|
||||
};
|
||||
|
||||
class VariantPool {
|
||||
class MemoryPool {
|
||||
public:
|
||||
void create(SlotCount cap, Allocator* allocator);
|
||||
void destroy(Allocator* allocator);
|
@ -4,12 +4,12 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ArduinoJson/Memory/VariantPool.hpp>
|
||||
#include <ArduinoJson/Memory/MemoryPool.hpp>
|
||||
#include <ArduinoJson/Variant/VariantSlot.hpp>
|
||||
|
||||
ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
|
||||
|
||||
inline void VariantPool::create(SlotCount cap, Allocator* allocator) {
|
||||
inline void MemoryPool::create(SlotCount cap, Allocator* allocator) {
|
||||
ARDUINOJSON_ASSERT(cap > 0);
|
||||
slots_ =
|
||||
reinterpret_cast<VariantSlot*>(allocator->allocate(slotsToBytes(cap)));
|
||||
@ -17,7 +17,7 @@ inline void VariantPool::create(SlotCount cap, Allocator* allocator) {
|
||||
usage_ = 0;
|
||||
}
|
||||
|
||||
inline void VariantPool::destroy(Allocator* allocator) {
|
||||
inline void MemoryPool::destroy(Allocator* allocator) {
|
||||
if (slots_)
|
||||
allocator->deallocate(slots_);
|
||||
slots_ = nullptr;
|
||||
@ -25,7 +25,7 @@ inline void VariantPool::destroy(Allocator* allocator) {
|
||||
usage_ = 0;
|
||||
}
|
||||
|
||||
inline void VariantPool::shrinkToFit(Allocator* allocator) {
|
||||
inline void MemoryPool::shrinkToFit(Allocator* allocator) {
|
||||
auto newSlots = reinterpret_cast<VariantSlot*>(
|
||||
allocator->reallocate(slots_, slotsToBytes(usage_)));
|
||||
if (newSlots) {
|
||||
@ -34,7 +34,7 @@ inline void VariantPool::shrinkToFit(Allocator* allocator) {
|
||||
}
|
||||
}
|
||||
|
||||
inline SlotWithId VariantPool::allocSlot() {
|
||||
inline SlotWithId MemoryPool::allocSlot() {
|
||||
if (!slots_)
|
||||
return {};
|
||||
if (usage_ >= capacity_)
|
||||
@ -44,28 +44,28 @@ inline SlotWithId VariantPool::allocSlot() {
|
||||
return {slot, SlotId(index)};
|
||||
}
|
||||
|
||||
inline VariantSlot* VariantPool::getSlot(SlotId id) const {
|
||||
inline VariantSlot* MemoryPool::getSlot(SlotId id) const {
|
||||
ARDUINOJSON_ASSERT(id < usage_);
|
||||
return &slots_[id];
|
||||
}
|
||||
|
||||
inline SlotCount VariantPool::usage() const {
|
||||
inline SlotCount MemoryPool::usage() const {
|
||||
return usage_;
|
||||
}
|
||||
|
||||
inline void VariantPool::clear() {
|
||||
inline void MemoryPool::clear() {
|
||||
usage_ = 0;
|
||||
}
|
||||
|
||||
inline SlotCount VariantPool::bytesToSlots(size_t n) {
|
||||
inline SlotCount MemoryPool::bytesToSlots(size_t n) {
|
||||
return static_cast<SlotCount>(n / sizeof(VariantSlot));
|
||||
}
|
||||
|
||||
inline size_t VariantPool::slotsToBytes(SlotCount n) {
|
||||
inline size_t MemoryPool::slotsToBytes(SlotCount n) {
|
||||
return n * sizeof(VariantSlot);
|
||||
}
|
||||
|
||||
inline SlotWithId VariantPoolList::allocFromFreeList() {
|
||||
inline SlotWithId MemoryPoolList::allocFromFreeList() {
|
||||
ARDUINOJSON_ASSERT(freeList_ != NULL_SLOT);
|
||||
auto id = freeList_;
|
||||
auto slot = getSlot(freeList_);
|
||||
@ -73,7 +73,7 @@ inline SlotWithId VariantPoolList::allocFromFreeList() {
|
||||
return {slot, id};
|
||||
}
|
||||
|
||||
inline void VariantPoolList::freeSlot(SlotWithId slot) {
|
||||
inline void MemoryPoolList::freeSlot(SlotWithId slot) {
|
||||
slot->free.next = freeList_;
|
||||
freeList_ = slot.id();
|
||||
}
|
@ -4,22 +4,25 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ArduinoJson/Memory/VariantPool.hpp>
|
||||
#include <ArduinoJson/Memory/MemoryPool.hpp>
|
||||
#include <ArduinoJson/Polyfills/assert.hpp>
|
||||
#include <ArduinoJson/Polyfills/utility.hpp>
|
||||
|
||||
#include <string.h> // memcpy
|
||||
|
||||
ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
|
||||
|
||||
using PoolCount = SlotId;
|
||||
|
||||
class VariantPoolList {
|
||||
class MemoryPoolList {
|
||||
public:
|
||||
VariantPoolList() = default;
|
||||
MemoryPoolList() = default;
|
||||
|
||||
~VariantPoolList() {
|
||||
~MemoryPoolList() {
|
||||
ARDUINOJSON_ASSERT(count_ == 0);
|
||||
}
|
||||
|
||||
friend void swap(VariantPoolList& a, VariantPoolList& b) {
|
||||
friend void swap(MemoryPoolList& a, MemoryPoolList& b) {
|
||||
bool aUsedPreallocated = a.pools_ == a.preallocatedPools_;
|
||||
bool bUsedPreallocated = b.pools_ == b.preallocatedPools_;
|
||||
|
||||
@ -50,7 +53,7 @@ class VariantPoolList {
|
||||
swap_(a.freeList_, b.freeList_);
|
||||
}
|
||||
|
||||
VariantPoolList& operator=(VariantPoolList&& src) {
|
||||
MemoryPoolList& operator=(MemoryPoolList&& src) {
|
||||
ARDUINOJSON_ASSERT(count_ == 0);
|
||||
if (src.pools_ == src.preallocatedPools_) {
|
||||
memcpy(preallocatedPools_, src.preallocatedPools_,
|
||||
@ -122,8 +125,8 @@ class VariantPoolList {
|
||||
if (count_ > 0)
|
||||
pools_[count_ - 1].shrinkToFit(allocator);
|
||||
if (pools_ != preallocatedPools_ && count_ != capacity_) {
|
||||
pools_ = static_cast<VariantPool*>(
|
||||
allocator->reallocate(pools_, count_ * sizeof(VariantPool)));
|
||||
pools_ = static_cast<MemoryPool*>(
|
||||
allocator->reallocate(pools_, count_ * sizeof(MemoryPool)));
|
||||
ARDUINOJSON_ASSERT(pools_ != nullptr); // realloc to smaller can't fail
|
||||
capacity_ = count_;
|
||||
}
|
||||
@ -142,7 +145,7 @@ class VariantPoolList {
|
||||
SlotId(poolIndex * ARDUINOJSON_POOL_CAPACITY + slot.id())};
|
||||
}
|
||||
|
||||
VariantPool* addPool(Allocator* allocator) {
|
||||
MemoryPool* addPool(Allocator* allocator) {
|
||||
if (count_ == capacity_ && !increaseCapacity(allocator))
|
||||
return nullptr;
|
||||
auto pool = &pools_[count_++];
|
||||
@ -160,24 +163,24 @@ class VariantPoolList {
|
||||
auto newCapacity = PoolCount(capacity_ * 2);
|
||||
|
||||
if (pools_ == preallocatedPools_) {
|
||||
newPools = allocator->allocate(newCapacity * sizeof(VariantPool));
|
||||
newPools = allocator->allocate(newCapacity * sizeof(MemoryPool));
|
||||
if (!newPools)
|
||||
return false;
|
||||
memcpy(newPools, preallocatedPools_, sizeof(preallocatedPools_));
|
||||
} else {
|
||||
newPools =
|
||||
allocator->reallocate(pools_, newCapacity * sizeof(VariantPool));
|
||||
allocator->reallocate(pools_, newCapacity * sizeof(MemoryPool));
|
||||
if (!newPools)
|
||||
return false;
|
||||
}
|
||||
|
||||
pools_ = static_cast<VariantPool*>(newPools);
|
||||
pools_ = static_cast<MemoryPool*>(newPools);
|
||||
capacity_ = newCapacity;
|
||||
return true;
|
||||
}
|
||||
|
||||
VariantPool preallocatedPools_[ARDUINOJSON_INITIAL_POOL_COUNT];
|
||||
VariantPool* pools_ = preallocatedPools_;
|
||||
MemoryPool preallocatedPools_[ARDUINOJSON_INITIAL_POOL_COUNT];
|
||||
MemoryPool* pools_ = preallocatedPools_;
|
||||
PoolCount count_ = 0;
|
||||
PoolCount capacity_ = ARDUINOJSON_INITIAL_POOL_COUNT;
|
||||
SlotId freeList_ = NULL_SLOT;
|
@ -5,8 +5,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <ArduinoJson/Memory/Allocator.hpp>
|
||||
#include <ArduinoJson/Memory/MemoryPoolList.hpp>
|
||||
#include <ArduinoJson/Memory/StringPool.hpp>
|
||||
#include <ArduinoJson/Memory/VariantPoolList.hpp>
|
||||
#include <ArduinoJson/Polyfills/assert.hpp>
|
||||
#include <ArduinoJson/Polyfills/utility.hpp>
|
||||
#include <ArduinoJson/Strings/StringAdapters.hpp>
|
||||
@ -14,7 +14,7 @@
|
||||
ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
|
||||
|
||||
union VariantSlot;
|
||||
class VariantPool;
|
||||
class MemoryPool;
|
||||
class VariantData;
|
||||
class VariantWithId;
|
||||
|
||||
@ -43,8 +43,7 @@ class ResourceManager {
|
||||
}
|
||||
|
||||
size_t size() const {
|
||||
return VariantPool::slotsToBytes(variantPools_.usage()) +
|
||||
stringPool_.size();
|
||||
return MemoryPool::slotsToBytes(variantPools_.usage()) + stringPool_.size();
|
||||
}
|
||||
|
||||
bool overflowed() const {
|
||||
@ -114,7 +113,7 @@ class ResourceManager {
|
||||
Allocator* allocator_;
|
||||
bool overflowed_;
|
||||
StringPool stringPool_;
|
||||
VariantPoolList variantPools_;
|
||||
MemoryPoolList variantPools_;
|
||||
};
|
||||
|
||||
ARDUINOJSON_END_PRIVATE_NAMESPACE
|
||||
|
@ -13,7 +13,7 @@
|
||||
ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
|
||||
|
||||
union VariantSlot;
|
||||
class VariantPool;
|
||||
class MemoryPool;
|
||||
|
||||
class StringPool {
|
||||
public:
|
||||
|
@ -4,8 +4,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ArduinoJson/Memory/MemoryPool.hpp>
|
||||
#include <ArduinoJson/Memory/StringNode.hpp>
|
||||
#include <ArduinoJson/Memory/VariantPool.hpp>
|
||||
#include <ArduinoJson/Misc/SerializedValue.hpp>
|
||||
#include <ArduinoJson/Numbers/convertNumber.hpp>
|
||||
#include <ArduinoJson/Strings/JsonString.hpp>
|
||||
|
Reference in New Issue
Block a user