@@ -97,6 +97,19 @@ class MemoryPool : private mbed::NonCopyable<MemoryPool<T, pool_sz> > {
97
97
}
98
98
99
99
/* * Allocate a memory block from a memory pool, without blocking.
100
+
101
+ This method works like `std::malloc` or `std::allocator<T>::allocate` in that the
102
+ returned memory block is not initialized. For types with a non-trivial constructor
103
+ placement new must be used to construct an object in the returned storage.
104
+
105
+ Example:
106
+ @code
107
+ MyObject *obj = pool.alloc();
108
+ if (obj) {
109
+ new (obj) MyObject(1, 2);
110
+ }
111
+ @endcode
112
+
100
113
@return address of the allocated memory block or nullptr in case of no memory available.
101
114
102
115
@note You may call this function from ISR context.
@@ -120,6 +133,7 @@ class MemoryPool : private mbed::NonCopyable<MemoryPool<T, pool_sz> > {
120
133
}
121
134
122
135
/* * Allocate a memory block from a memory pool, optionally blocking.
136
+ @see MemoryPool::try_alloc
123
137
@param rel_time timeout value (Kernel::wait_for_u32_forever to wait forever)
124
138
@return address of the allocated memory block or nullptr in case of no memory available.
125
139
@@ -149,6 +163,7 @@ class MemoryPool : private mbed::NonCopyable<MemoryPool<T, pool_sz> > {
149
163
}
150
164
151
165
/* * Allocate a memory block from a memory pool, blocking.
166
+ @see MemoryPool::try_alloc
152
167
@param abs_time absolute timeout time, referenced to Kernel::Clock.
153
168
@return address of the allocated memory block or nullptr in case of no memory available.
154
169
@@ -264,6 +279,17 @@ class MemoryPool : private mbed::NonCopyable<MemoryPool<T, pool_sz> > {
264
279
}
265
280
266
281
/* * Free a memory block.
282
+
283
+ This method works like `std::free` or `std::allocator<T>::deallocate` in that any
284
+ object in the memory is not destroyed. For types with a non-trivial destructor
285
+ that destructor must be called manually before freeing the memory.
286
+
287
+ Example:
288
+ @code
289
+ obj->~MyObject();
290
+ pool.free(obj);
291
+ @endcode
292
+
267
293
@param block address of the allocated memory block to be freed.
268
294
@return osOK on successful deallocation, osErrorParameter if given memory block id
269
295
is nullptr or invalid, or osErrorResource if given memory block is in an
0 commit comments