cpp-msgpack-light
0.3.0
A light library to serialize MessagePack.
Loading...
Searching...
No Matches
standard_allocator.h
Go to the documentation of this file.
1
/*
2
* Copyright 2024 MusicScience37 (Kenta Kabashima)
3
*
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
7
*
8
* http://www.apache.org/licenses/LICENSE-2.0
9
*
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
15
*/
20
#pragma once
21
22
#include <cstddef>
23
#include <cstdlib>
24
#include <new>
25
26
namespace
msgpack_light
{
27
31
class
standard_allocator
{
32
public
:
39
[[nodiscard]]
void
*
allocate
(
// NOLINT
40
std::size_t size, std::size_t
/*alignment*/
) {
41
if
(size == 0U) {
42
size = 1U;
43
}
44
void
* ptr = std::malloc(size);
45
if
(ptr ==
nullptr
) {
46
throw
std::bad_alloc();
47
}
48
return
ptr;
49
}
50
56
void
deallocate
(
void
* ptr)
noexcept
{
// NOLINT
57
std::free(ptr);
58
}
59
};
60
61
}
// namespace msgpack_light
msgpack_light::standard_allocator
Class of standard allocators to allocate and deallocate memory.
Definition
standard_allocator.h:31
msgpack_light::standard_allocator::allocate
void * allocate(std::size_t size, std::size_t)
Allocate memory.
Definition
standard_allocator.h:39
msgpack_light::standard_allocator::deallocate
void deallocate(void *ptr) noexcept
Deallocate memory.
Definition
standard_allocator.h:56
msgpack_light
Namespace of this project.
Definition
binary.h:33
include
msgpack_light
standard_allocator.h
Generated on
for cpp-msgpack-light by
1.14.0