-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPooledObject.hpp
More file actions
78 lines (57 loc) · 2.37 KB
/
Copy pathPooledObject.hpp
File metadata and controls
78 lines (57 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*******************************************************************************
module: PooledObject
author: digimokan
date: 19 NOV 2018 (created)
purpose: make new/delete calls utilize an object pool
usage: class MyObject : PooledObject<MyObject, 10> { ...
--> for an object pool of 10 objects
--> object pool created with the first call of "new MyObject"
--> object pool destroyed on program termination
*******************************************************************************/
#ifndef POOLED_OBJECT_HPP
#define POOLED_OBJECT_HPP 1
/*******************************************************************************
* SYSTEM INCLUDES
*******************************************************************************/
#include <cstddef>
#include <mutex>
/*******************************************************************************
* USER INCLUDES
*******************************************************************************/
#include "ObjectPool.hpp"
/*******************************************************************************
* INTERFACE
*******************************************************************************/
template <typename Obj, size_t initial_pool_size>
class PooledObject {
public:
// constructors
PooledObject ();
// destructor
virtual ~PooledObject () = default;
// operators
PooledObject (const PooledObject& in) = default;
PooledObject& operator= (const PooledObject& rh) = default;
PooledObject (PooledObject&& in) noexcept = default;
PooledObject& operator= (PooledObject&& rh) noexcept = default;
void* operator new (std::size_t sz);
void operator delete (void* ptr);
// static specialized methods
static void manual_allocate_object_pool ();
static size_t get_peak_size ();
private:
// static fields
static ObjectPool<Obj, initial_pool_size>* object_pool;
static std::once_flag init_flag;
// static helper methods
static void init_and_scope_pool ();
static void delete_pool ();
};
/*******************************************************************************
* IMPLEMENTATION
*******************************************************************************/
#include "PooledObject.hxx"
/*******************************************************************************
* END
*******************************************************************************/
#endif // POOLED_OBJECT_HPP