# xMessageBufferCreateStatic example

**URL:** <https://forums.freertos.org/t/xmessagebuffercreatestatic-example/12888>\
**Category:** Kernel\
**Tags:** tutorial\
**Created:** [June 22, 2021, 1:11am UTC](https://forums.freertos.org/t/xmessagebuffercreatestatic-example/12888 "2021-06-22T01:11:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![AndreiCherniaev](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/andreicherniaev/32/573_2.png) [@AndreiCherniaev](https://forums.freertos.org/u/AndreiCherniaev)\
**Post date:** [June 22, 2021, 1:11am UTC](https://forums.freertos.org/t/xmessagebuffercreatestatic-example/12888/1 "2021-06-22T01:11:56Z")

</div>

There is page about [xMessageBufferCreateStatic](https://www.freertos.org/xMessageBufferCreateStatic.html)

I suggest fix errors!

1. ucStorage **g** Buffer != uc **Buffer** Storage != uc **Storage** Buffer

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [June 22, 2021, 1:18pm UTC](https://forums.freertos.org/t/xmessagebuffercreatestatic-example/12888/2 "2021-06-22T13:18:03Z")

</div>

Thanks for pointing this out, we will fix.

---

<div class="post-metadata">

**Author:** ![AndreiCherniaev](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/andreicherniaev/32/573_2.png) [@AndreiCherniaev](https://forums.freertos.org/u/AndreiCherniaev)\
**Post date:** [July 6, 2021, 2:20am UTC](https://forums.freertos.org/t/xmessagebuffercreatestatic-example/12888/3 "2021-07-06T02:20:09Z")

</div>

It is not all about [xMessageBufferCreateStatic](https://www.freertos.org/xMessageBufferCreateStatic.html) page.

"Must point to a uint8\_t array that is at least xBufferSizeBytes + 1 big. This is the array to which messages are copied when they are written to the message buffer. "

But in example

```auto
xMessageBuffer = xMessageBufferCreateStatic( sizeof( ucStorageBuffer ),
                                                 ucStorageBuffer,
                                                 &xMessageBufferStruct );

```

I can’t see + 1 big…

And… “+ 1 big” means + sizeof( size\_t ) [usually 4 bytes] not just +1 byte?

So " The maximum number of bytes that can be stored in the message buffer is actually (xBufferSizeBytes **- 1** ). " need "is actually (xBufferSizeBytes - sizeof(size\_t)). "?

---

<div class="post-metadata">

**Author:** ![richard-damon](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/richard-damon/32/38_2.png) [@richard-damon](https://forums.freertos.org/u/richard-damon)\
**Post date:** [July 6, 2021, 2:49am UTC](https://forums.freertos.org/t/xmessagebuffercreatestatic-example/12888/4 "2021-07-06T02:49:45Z")

</div>

The +1 is bytes, as the buffer needs one always empty byte to distinguish full from empty. The maximum message that can be sent minus the size of configMESSAGE\_BUFFER\_LENGTH\_TYPE which will default to size\_t, so the provided buffer size must be bigger than the largest message by at least that much.

While it defaults to size\_t, I can’t see a reason it can’t normally be changed to unsigned short or unsigned character, as I can’t imagine using a buffer for messages over 65k bytes long.

---

<div class="post-metadata">

**Author:** ![AndreiCherniaev](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/andreicherniaev/32/573_2.png) [@AndreiCherniaev](https://forums.freertos.org/u/AndreiCherniaev)\
**Post date:** [July 13, 2021, 5:44am UTC](https://forums.freertos.org/t/xmessagebuffercreatestatic-example/12888/5 "2021-07-13T05:44:38Z")

</div>

Is example from [xMessageBufferCreateStatic](https://www.freertos.org/xMessageBufferCreateStatic.html) page correct? I can’t see +1 or -1 there

---

<div class="post-metadata">

**Author:** ![hs2](https://avatars.discourse-cdn.com/v4/letter/h/a4c791/32.png) [@hs2](https://forums.freertos.org/u/hs2)\
**Post date:** [July 13, 2021, 5:58am UTC](https://forums.freertos.org/t/xmessagebuffercreatestatic-example/12888/6 "2021-07-13T05:58:06Z")

</div>

Yes, I think so. See the comment::

> /\* Used to dimension the array used to hold the messages. The available space  
> will actually be one less than this, so 999. \*/  
> #define STORAGE\_SIZE\_BYTES 1000
