Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Invalid comment in nrf_memobj.h

I found this in nRF5_SDK_17.0.2_d674dde/components/libraries/memobj/nrf_memobj.h :

/**
* A memory object can consist of multiple chunks with the same size. Each object has a header part
* and a data part. The first element in a memory object is memory object head which has a special header.
* The remaining objects have a header of the same size.
*
@verbatim
_____________________ _____________________ _____________________
| | | | | |
|4 B head header | --> |4 B p_next |------->|4 B p_memobj_pool |
|_____________________| | |_____________________| |_____________________|
| | | | | | |
|4 B p_next |--| | | | |
|_____________________| | | .... | |
| | | data | | data |
| | | | | |
| data | | | | |
| | | | | |
|_____________________| |_____________________| |_____________________|
head mid_element last_element
@endverbatim
*
*/

However, I think that there is a mistake, the head block starts with p_next, and then head header, and not the other way round.

This can be inferred from this definition :

/** @brief Head chunk structure. */
typedef struct
{
memobj_header_t header; ///< Standard header.
memobj_head_header_t head_header; ///< Head-specific header part.
uint8_t data[1]; ///< Data.
} memobj_head_t;

where the usual head is in the first place.
  

  • BTW, I don't know why, but the spacing was lost when I cut & pasted the comment from nrf_memobj.h to the ticket edit window. I used Safari browser.

  • Hi,

    It should be possible to put things in a "code" window through the "insert" menu in the editor:

    /**
     * A memory object can consist of multiple chunks with the same size. Each object has a header part
     * and a data part. The first element in a memory object is memory object head which has a special header.
     * The remaining objects have a header of the same size.
     * 
    @verbatim
     _____________________        _____________________          _____________________
    |                     |      |                     |        |                     |
    |4 B  head header     |  --> |4 B    p_next        |------->|4 B  p_memobj_pool   |
    |_____________________|  |   |_____________________|        |_____________________|
    |                     |  |   |                     |        |                     |
    |4 B    p_next        |--|   |                     |        |                     |
    |_____________________|      |                     |  ....  |                     |
    |                     |      |        data         |        |        data         |
    |                     |      |                     |        |                     |
    |       data          |      |                     |        |                     |
    |                     |      |                     |        |                     |
    |_____________________|      |_____________________|        |_____________________|
             head                      mid_element                  last_element
    @endverbatim
     *
     */

    Thank you for sharing your observations. It is highly appreciated! From what I can tell it looks like you are right. It looks like the "standard header", used by both the head chunk and the other chunks, are the first part of both:

    /** @brief Head chunk structure. */
    typedef struct
    {
        memobj_header_t      header;      ///< Standard header.
        memobj_head_header_t head_header; ///< Head-specific header part.
        uint8_t              data[1];     ///< Data.
    } memobj_head_t;
    
    STATIC_ASSERT(sizeof(memobj_header_t) == NRF_MEMOBJ_STD_HEADER_SIZE);
    
    /** @brief Standard chunk structure. */
    struct memobj_elem_s
    {
        memobj_header_t  header;  ///< Standard header.
        uint8_t          data[1]; ///< Data.
    };

    At least that is my impression after a quick look at the matter. I will forward to the developers for final confirmation and documentation fix.

    Regards,
    Terje

  • Hi Terje,

    Thank you for the editor tips.

    $understood or die "I think that I got it !";

  • Awesome and interesting article. Great things you've always shared with us. Thanks. Just continue composing this kind of post. Baddies East

  • From breathable summer sandals to insulated winter boots, the best kanak footwear - best footwear manufacturer in agra adapts to the weather, ensuring comfort and protection in every season.

Related