Line |
Branch |
Exec |
Source |
1 |
|
|
/** |
2 |
|
|
* @file lib.Allocator.hpp |
3 |
|
|
* @author Sergey Baigudin, sergey@baigudin.software |
4 |
|
|
* @copyright 2016-2022, Sergey Baigudin, Baigudin Software |
5 |
|
|
*/ |
6 |
|
|
#ifndef LIB_ALLOCATOR_HPP_ |
7 |
|
|
#define LIB_ALLOCATOR_HPP_ |
8 |
|
|
|
9 |
|
|
#include "lib.Types.hpp" |
10 |
|
|
#include "sys.Call.hpp" |
11 |
|
|
|
12 |
|
|
namespace eoos |
13 |
|
|
{ |
14 |
|
|
namespace lib |
15 |
|
|
{ |
16 |
|
|
|
17 |
|
|
/** |
18 |
|
|
* @class Allocator |
19 |
|
|
* @brief Memory allocator. |
20 |
|
|
*/ |
21 |
|
|
class Allocator |
22 |
|
|
{ |
23 |
|
|
|
24 |
|
|
public: |
25 |
|
|
|
26 |
|
|
/** |
27 |
|
|
* @brief Allocates memory. |
28 |
|
|
* |
29 |
|
|
* @param size Number of bytes to allocate. |
30 |
|
|
* @return Allocated memory address or a null pointer. |
31 |
|
|
*/ |
32 |
|
593 |
static void* allocate(size_t size) |
33 |
|
|
{ |
34 |
|
593 |
return sys::Call::get().getHeap().allocate(size, NULLPTR); |
35 |
|
|
} |
36 |
|
|
|
37 |
|
|
/** |
38 |
|
|
* @brief Frees allocated memory. |
39 |
|
|
* |
40 |
|
|
* @param ptr Address of allocated memory block or a null pointer. |
41 |
|
|
*/ |
42 |
|
588 |
static void free(void* ptr) |
43 |
|
|
{ |
44 |
|
588 |
return sys::Call::get().getHeap().free(ptr); |
45 |
|
|
} |
46 |
|
|
}; |
47 |
|
|
|
48 |
|
|
} // namespace lib |
49 |
|
|
} // namespace eoos |
50 |
|
|
|
51 |
|
|
#endif // LIB_ALLOCATOR_HPP_ |
52 |
|
|
|