Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • A ArduinoJson
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 24
    • Issues 24
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 0
    • Merge requests 0
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Benoît Blanchon
  • ArduinoJson
  • Merge requests
  • !700

Allow passing allocator instance into dynamic buffer

  • Review changes

  • Download
  • Email patches
  • Plain diff
Closed Administrator requested to merge github/fork/Adam5Wu/feature/custom_allocator into master Mar 12, 2018
  • Overview 1
  • Commits 1
  • Pipelines 0
  • Changes 1

Created by: Adam5Wu

I've encountered a scenario and found this feature useful.

  • I am writing a utility which provides a more high-level API to allow user program to manipulate json more easily.
    1. I do like to enable user program to specify a buffer limit, however there is no uniform value across all use cases.
    2. In my utility workflow, I need to pass the json buffer instance to the user program so they can load arbitrary json structure using parse() method

I think templating and static json buffer is a possibility, however, the syntax can get quite messy for the callback passing the static json buffer instance. Also, templating cannot support runtime reconfiguration.

So I played around with the dynamic json buffer and allocator, basically creating my own allocator which counts the number of bytes allocated and stops giving out more memory when limit reached. It seems to work well.

This patch basically allows to write a single run-time-configurable-limit allocator and pass it into the DynamicJsonBufferBase.

Alternatively, instead of:

TAllocator _allocator;

the DynamicJsonBufferBase can declare:

TAllocator &_allocator;

This would allow even more runtime flexibility (allocator behavior can be reconfigured even after dynamic json buffer has been created).

Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: github/fork/Adam5Wu/feature/custom_allocator