Skip to content

Better document MemoryPool behaviour #14537

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 28, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions rtos/include/rtos/MemoryPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,19 @@ class MemoryPool : private mbed::NonCopyable<MemoryPool<T, pool_sz> > {
}

/** Allocate a memory block from a memory pool, without blocking.

This method works like `std::malloc` or `std::allocator<T>::allocate` in that the
returned memory block is not initialized. For types with a non-trivial constructor
placement new must be used to construct an object in the returned storage.

Example:
@code
MyObject *obj = pool.alloc();
if (obj) {
new (obj) MyObject(1, 2);
}
@endcode

@return address of the allocated memory block or nullptr in case of no memory available.

@note You may call this function from ISR context.
Expand All @@ -120,6 +133,7 @@ class MemoryPool : private mbed::NonCopyable<MemoryPool<T, pool_sz> > {
}

/** Allocate a memory block from a memory pool, optionally blocking.
@see MemoryPool::try_alloc
@param rel_time timeout value (Kernel::wait_for_u32_forever to wait forever)
@return address of the allocated memory block or nullptr in case of no memory available.

Expand Down Expand Up @@ -149,6 +163,7 @@ class MemoryPool : private mbed::NonCopyable<MemoryPool<T, pool_sz> > {
}

/** Allocate a memory block from a memory pool, blocking.
@see MemoryPool::try_alloc
@param abs_time absolute timeout time, referenced to Kernel::Clock.
@return address of the allocated memory block or nullptr in case of no memory available.

Expand Down Expand Up @@ -264,6 +279,17 @@ class MemoryPool : private mbed::NonCopyable<MemoryPool<T, pool_sz> > {
}

/** Free a memory block.

This method works like `std::free` or `std::allocator<T>::deallocate` in that any
object in the memory is not destroyed. For types with a non-trivial destructor
that destructor must be called manually before freeing the memory.

Example:
@code
obj->~MyObject();
pool.free(obj);
@endcode

@param block address of the allocated memory block to be freed.
@return osOK on successful deallocation, osErrorParameter if given memory block id
is nullptr or invalid, or osErrorResource if given memory block is in an
Expand Down