• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

bblanchon / ArduinoJson / 4469075312

pending completion
4469075312

push

github

Benoit Blanchon
`MemoryPool` calls the `Allocator` directly

52 of 52 new or added lines in 3 files covered. (100.0%)

3283 of 3299 relevant lines covered (99.52%)

6203.28 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

77.78
/src/ArduinoJson/Memory/Allocator.hpp
1
// ArduinoJson - https://arduinojson.org
2
// Copyright © 2014-2023, Benoit BLANCHON
3
// MIT License
4

5
#pragma once
6

7
#include <ArduinoJson/Namespace.hpp>
8

9
#include <stdlib.h>  // malloc, free
10

11
ARDUINOJSON_BEGIN_PUBLIC_NAMESPACE
12

13
class Allocator {
14
 public:
15
  virtual void* allocate(size_t size) = 0;
16
  virtual void deallocate(void* ptr) = 0;
17
  virtual void* reallocate(void* ptr, size_t new_size) = 0;
18

19
 protected:
20
  ~Allocator() = default;
21
};
22

23
namespace detail {
24
class DefaultAllocator : public Allocator {
25
 public:
26
  void* allocate(size_t size) override {
1,953✔
27
    return malloc(size);
1,953✔
28
  }
29

30
  void deallocate(void* ptr) override {
1,953✔
31
    free(ptr);
1,953✔
32
  }
1,953✔
33

34
  void* reallocate(void* ptr, size_t new_size) override {
×
35
    return realloc(ptr, new_size);
×
36
  }
37

38
  static Allocator* instance() {
1,983✔
39
    static DefaultAllocator allocator;
40
    return &allocator;
1,983✔
41
  }
42

43
 private:
44
  DefaultAllocator() = default;
45
  ~DefaultAllocator() = default;
46
};
47
}  // namespace detail
48

49
ARDUINOJSON_END_PUBLIC_NAMESPACE
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc