Skip to content

Commit c05e837

Browse files
committed
fdsdump: add StdAllocator component
1 parent 10cb0ad commit c05e837

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

src/tools/fdsdump/src/aggregator/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ set(AGGREGATOR_SRC
1010
printer.cpp
1111
jsonPrinter.cpp
1212
tablePrinter.cpp
13+
stdAllocator.cpp
1314
)
1415

1516
add_library(aggregator_obj OBJECT ${AGGREGATOR_SRC})
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* @file
3+
* @author Michal Sedlak <[email protected]>
4+
* @brief Simple allocator
5+
*/
6+
7+
#include <aggregator/stdAllocator.hpp>
8+
9+
#include <cassert>
10+
11+
namespace fdsdump {
12+
namespace aggregator {
13+
14+
uint8_t *
15+
StdAllocator::allocate(size_t size)
16+
{
17+
m_blocks.push_back(std::unique_ptr<uint8_t []>(new uint8_t[size]));
18+
return m_blocks.back().get();
19+
}
20+
21+
} // aggregator
22+
} // fdsdump
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* @file
3+
* @author Michal Sedlak <[email protected]>
4+
* @brief Simple allocator
5+
*/
6+
#pragma once
7+
8+
#include <memory>
9+
#include <vector>
10+
11+
namespace fdsdump {
12+
namespace aggregator {
13+
14+
/**
15+
* @brief A simple allocator.
16+
*
17+
*/
18+
class StdAllocator {
19+
public:
20+
StdAllocator() {}
21+
22+
/** @brief Disallow copy constructor. */
23+
StdAllocator(const StdAllocator &) = delete;
24+
/** @brief Disallow move constructor. */
25+
StdAllocator(StdAllocator &&) = delete;
26+
27+
/**
28+
* @brief Allocate bytes.
29+
* @param[in] size The number of bytes
30+
* @return Pointer to the bytes
31+
*/
32+
uint8_t *allocate(size_t size);
33+
34+
private:
35+
std::vector<std::unique_ptr<uint8_t []>> m_blocks;
36+
};
37+
38+
} // aggregator
39+
} // fdsdump

0 commit comments

Comments
 (0)