7 #include "fwMemory/BufferAllocationPolicy.hpp" 9 #include "fwMemory/ByteSize.hpp" 10 #include "fwMemory/exception/Memory.hpp" 17 void BufferMallocPolicy::allocate(BufferType& buffer,
18 BufferAllocationPolicy::SizeType size)
24 buffer = malloc( size );
31 if (buffer ==
nullptr)
34 "Cannot allocate memory (" 42 void BufferMallocPolicy::reallocate(BufferType& buffer,
43 BufferAllocationPolicy::SizeType size)
48 newBuffer = realloc( buffer, size );
55 if (newBuffer == NULL && size > 0)
58 "Cannot allocate memory (" 66 void BufferMallocPolicy::destroy(BufferType& buffer)
74 BufferAllocationPolicy::sptr BufferMallocPolicy::New()
76 return BufferAllocationPolicy::sptr(
new BufferMallocPolicy);
81 void BufferNewPolicy::allocate(BufferType& buffer,
82 BufferAllocationPolicy::SizeType size)
88 buffer =
new char[size];
91 catch (std::bad_alloc& ba)
94 "bad_alloc caught: " << ba.what());
100 void BufferNewPolicy::reallocate(BufferType& buffer,
101 BufferAllocationPolicy::SizeType size)
103 FwCoreNotUsedMacro(buffer);
104 FwCoreNotUsedMacro(size);
106 "Reallocation not managed for buffer allocated with 'new' operator.");
111 void BufferNewPolicy::destroy(BufferType& buffer)
113 delete[]
static_cast<char*
>(buffer);
119 BufferAllocationPolicy::sptr BufferNewPolicy::New()
121 return BufferAllocationPolicy::sptr(
new BufferNewPolicy);
126 void BufferNoAllocPolicy::allocate(BufferType& buffer,
127 BufferAllocationPolicy::SizeType size)
129 FwCoreNotUsedMacro(buffer);
130 FwCoreNotUsedMacro(size);
132 "No Allocation Policy should not be called.");
137 void BufferNoAllocPolicy::reallocate(BufferType& buffer,
138 BufferAllocationPolicy::SizeType size)
140 FwCoreNotUsedMacro(buffer);
141 FwCoreNotUsedMacro(size);
143 "No Allocation Policy should not be called.");
148 void BufferNoAllocPolicy::destroy(BufferType& buffer)
150 FwCoreNotUsedMacro(buffer);
151 SLM_ASSERT(
"No Alloc Policy should not be called", 0);
156 BufferAllocationPolicy::sptr BufferNoAllocPolicy::New()
158 return BufferAllocationPolicy::sptr(
new BufferNoAllocPolicy);
Conversion helper for size in bytes Converts string to number of bytes and vice-versa. This class is also able to manage conversions between units standards (IEC, SI)
The namespace fwMemory contains tools to manage memory. Use for dump.
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
Implements an exception class for fwMemory.