CppServer 1.0.5.0
C++ Server Library
Loading...
Searching...
No Matches
memory.inl
Go to the documentation of this file.
1
9namespace CppServer {
10namespace Asio {
11
12inline void* HandlerStorage::allocate(size_t size)
13{
14 // Check if the storage is not already used and has enough capacity
15 if (!_in_use && (size < sizeof(_storage)))
16 {
17 _in_use = true;
18 return &_storage;
19 }
20
21 // Otherwise allocate memory in the heap
22 return ::operator new(size);
23}
24
26{
27 // Free storage if memory block was allocated from it
28 if (ptr == &_storage)
29 {
30 _in_use = false;
31 return;
32 }
33
34 // Otherwise free memory in the heap
35 ::operator delete(ptr);
36}
37
38template <typename THandler>
43
44} // namespace Asio
45} // namespace CppServer
Asio allocate handler wrapper.
Definition memory.h:133
Asio handler storage.
Definition memory.h:27
void deallocate(void *ptr)
Deallocate memory buffer.
Definition memory.inl:25
void * allocate(size_t size)
Allocate memory buffer.
Definition memory.inl:12
AllocateHandler< THandler > make_alloc_handler(HandlerStorage &storage, THandler handler)
Helper function to wrap a handler object to add custom allocation.
Definition memory.inl:39
C++ Server project definitions.
Definition asio.h:56