nngn
Loading...
Searching...
No Matches
realloc.h
Go to the documentation of this file.
1#ifndef NNGN_UTILS_ALLOC_REALLOC_H
2#define NNGN_UTILS_ALLOC_REALLOC_H
3
4#include <cstdlib>
5
6#include "utils/concepts.h"
7
8#include "base.h"
9
10namespace nngn {
11
18template<trivial T = char>
19struct reallocator : stateless_allocator<reallocator<T>> {
20 using value_type = T;
21 using pointer = std::add_pointer_t<value_type>;
22 pointer allocate(std::size_t n) noexcept;
23 pointer reallocate(pointer p, std::size_t n) noexcept;
24 void deallocate(pointer p, std::size_t) noexcept { free(p); }
25};
26
27template<trivial T>
28auto reallocator<T>::allocate(std::size_t n) noexcept -> pointer {
29 return static_cast<pointer>(malloc(n * sizeof(T)));
30}
31
32template<trivial T>
33auto reallocator<T>::reallocate(pointer p, std::size_t n) noexcept -> pointer {
34 return static_cast<pointer>(realloc(p, n * sizeof(T)));
35}
36
37}
38
39#endif
Definition fundamental.h:41
local n
Definition dump_lights.lua:5
#define T(f0, f1, f2)
Definition audio.cpp:7
Base class for allocators, implements a few basic operations.
Definition base.h:49
Simple allocator which supports reallocation.
Definition realloc.h:19
pointer reallocate(pointer p, std::size_t n) noexcept
Definition realloc.h:33
void deallocate(pointer p, std::size_t) noexcept
Definition realloc.h:24
pointer allocate(std::size_t n) noexcept
Definition realloc.h:28
T value_type
Definition realloc.h:20