Uniot Core
0.8.1
Loading...
Searching...
No Matches
GlobalBufferMemoryManager.h
Go to the documentation of this file.
1/*
2 * This is a part of the Uniot project.
3 * Copyright (C) 2016-2023 Uniot <contact@uniot.io>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#pragma once
20
21#include <Arduino.h>
22
23namespace uniot {
24
38 public:
45 static void initialize();
46
54 static void* allocate(size_t size);
55
63 static void deallocate(void* ptr);
64
76 static void* reallocate(void* ptr, size_t newSize);
77
83 static size_t getTotalFreeMemory();
84
90 static size_t getLargestFreeBlock();
91
92 private:
99 struct FreeBlock {
100 size_t size;
101 FreeBlock* next;
102 };
103
105 static constexpr bool DEBUG = false;
106
108 static constexpr size_t BUFFER_SIZE = 4096;
109
111 static uint8_t mGlobalBuffer[BUFFER_SIZE];
112
114 static FreeBlock* mFreeList;
115};
116
117} // namespace uniot
Definition GlobalBufferMemoryManager.h:37
static void * allocate(size_t size)
Allocate memory from the global buffer.
Definition GlobalBufferMemoryManager.cpp:52
static void * reallocate(void *ptr, size_t newSize)
Resize allocated memory.
Definition GlobalBufferMemoryManager.cpp:158
static size_t getLargestFreeBlock()
Get the size of the largest available free block.
Definition GlobalBufferMemoryManager.cpp:211
static void deallocate(void *ptr)
Deallocate previously allocated memory.
Definition GlobalBufferMemoryManager.cpp:115
static void initialize()
Initialize the memory manager.
Definition GlobalBufferMemoryManager.cpp:45
static size_t getTotalFreeMemory()
Get the total free memory available in the buffer.
Definition GlobalBufferMemoryManager.cpp:199
Contains all classes and functions related to the Uniot Core.