summaryrefslogtreecommitdiff
path: root/src/memory/memory_resource.cpp
blob: 3351a1b9d6b2c2ede5cfa9e9b0292580cc35d4a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*
 * Copyright 2023 jacqueline <me@jacqueline.id.au>
 *
 * SPDX-License-Identifier: GPL-3.0-only
 */

#include "memory_resource.hpp"

#include <memory_resource>
#include <string>
#include <utility>

#include <esp_heap_caps.h>
#include <stdint.h>

namespace memory {

Resource kSpiRamResource{Capabilities::kSpiRam};

void* Resource::do_allocate(std::size_t bytes, std::size_t alignment) {
  return heap_caps_malloc(bytes, std::to_underlying(caps_));
}

void Resource::do_deallocate(void* p,
                             std::size_t bytes,
                             std::size_t alignment) {
  heap_caps_free(p);
}

bool Resource::do_is_equal(
    const std::pmr::memory_resource& other) const noexcept {
  return this == &other;
}

}  // namespace memory