Page 1 of 1

Alignment reuirement for memory pools

Posted: Fri Jul 06, 2018 11:52 pm
by yusuf.husainy
Hi All,

I have a memory pool object and associated object memory aligned to stkalign_t as well as another pool and associated object memory without any alignment.

On looking at the source code of ChibiOS, I see chPoolAdd() is called by chPoolLoadArray() on loading both above pools after their initialization. The function description for chPoolAdd() says:

Code: Select all

/**
 * @brief   Adds an object to a memory pool.
 * @pre     The memory pool must be already been initialized.
 * @pre     The added object must be of the right size for the specified
 *          memory pool.
 [glow=red]* @pre     The added object must be memory aligned to the size of
 *          @p stkalign_t type.
[/glow] * @note    This function is just an alias for @p chPoolFree() and has been
 *          added for clarity.
 *
 * @param[in] mp        pointer to a @p memory_pool_t structure
 * @param[in] objp      the pointer to the object to be added
 *
 * @api
 */
static inline void chPoolAdd(memory_pool_t *mp, void *objp) {

  chPoolFree(mp, objp);
}


Why is there a requirement that the alignment should be stkalign_t and not the PORT_NATURAL_ALIGN.

My code works with both the pools mentioned above, with and without the objects being aligne to stkalign_t.

My setup:
version: ChibiOS 18.2.0.
platform: simulator posix.

Regards,
Yusuf Husainy,

Re: Alignment reuirement for memory pools

Posted: Sun Jul 08, 2018 2:47 pm
by Giovanni
Hi,

It is a documentation error, PORT_NATURAL_ALIGN is fine.

Moved in bug reports.

Giovanni

Re: Alignment reuirement for memory pools

Posted: Sun Jul 15, 2018 12:53 pm
by Giovanni
Hi,

Fixed in repository.

Giovanni