Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
15 years ago

Q message allocation

This is just a general question about messaging and queues.

How are you guys allocating Q messages? For instance, each message I send is a pointer to a struct. My struct contains an ENUM value and a pointer. In all my message structure is 8 bytes.

When I post to a Q, I send a pointer to one of these message structures.

Should I be using the memory management functions every time and doing dynamic memory allocation of one of these message structures? I don't really know how else to do it without allocating a bunch of global msg structs at compile time.

Any insight to this would be appreciated.

1 Reply

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I prefer to use ring buffers. i do a calculation what ring buffer size is needed and add some safety margin.

    Personally i am not a friend of dynamic memory allocation and freeing in embedded systems.

    Unless you have a serious memory shortage i see nothing wrong with allocating big chunks of memory at compile time. At least so see then very early were potential bottlenecks lie.

    Its also easier to test.