#include <ArduinoJson.h>
#include <esp_heap_caps.h>

struct SpiRamAllocator : ArduinoJson::Allocator 
{
  void* allocate(size_t size) override 
  {
    Serial.printf("Json - PSRAM - Allocating %u Memory", size);
    return ps_malloc(size);
  }

  void deallocate(void* pointer) override 
  {
    Serial.printf("Json - PRAM - Freeing Memory");
    heap_caps_free(pointer);
  }

  void* reallocate(void* ptr, size_t new_size) override 
  {
    Serial.printf("Json - PSRAM - Rellocating %u Memory", new_size);
    return ps_realloc(ptr, new_size);
  }
};