# xMessageBufferCreate() API - Meaning of xBufferSizeBytes

**URL:** <https://forums.freertos.org/t/xmessagebuffercreate-api-meaning-of-xbuffersizebytes/7659>\
**Category:** Kernel\
**Created:** [February 8, 2019, 2:13am UTC](https://forums.freertos.org/t/xmessagebuffercreate-api-meaning-of-xbuffersizebytes/7659 "2019-02-08T02:13:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [February 8, 2019, 2:13am UTC](https://forums.freertos.org/t/xmessagebuffercreate-api-meaning-of-xbuffersizebytes/7659/1 "2019-02-08T02:13:42Z")

</div>

**[armandas](https://sourceforge.net/u/armandas/)** wrote on [Friday, February 08, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/c25eef4fb8/#28cf):

The xBufferSizeBytes parameter of the xMessageBufferCreate() needs to be manually increased by sizeof(size\_t). Is there a good technical reason why this increment is not done internally?

E.g. inside xStreamBufferGenericCreate() we have an assert to check the buffer size:

```auto
		if( xIsMessageBuffer == pdTRUE )
		{
			/* Is a message buffer but not statically allocated. */
			ucFlags = sbFLAGS_IS_MESSAGE_BUFFER;
			configASSERT( xBufferSizeBytes > sbBYTES_TO_STORE_MESSAGE_LENGTH );
		}

```

when we could simply increment the size:

```auto
		if( xIsMessageBuffer == pdTRUE )
		{
			/* Is a message buffer but not statically allocated. */
			ucFlags = sbFLAGS_IS_MESSAGE_BUFFER;
			xBufferSizeBytes += sbBYTES_TO_STORE_MESSAGE_LENGTH;
		}

```

---

<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:** [February 8, 2019, 3:51am UTC](https://forums.freertos.org/t/xmessagebuffercreate-api-meaning-of-xbuffersizebytes/7659/2 "2019-02-08T03:51:30Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Friday, February 08, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/c25eef4fb8/#28cf/c1c6):

The way the parameter works is described on the API function’s  
documentation page:

[https://www.freertos.org/xMessageBufferCreate.html](https://www.freertos.org/xMessageBufferCreate.html)

The user needs to know how it works as, for example, if you wanted to  
store two messages, just adding one additional lot of  
sbBYTES\_TO\_STORE\_MESSAGE\_LENGTH bytes is not going to help (as two lots  
would be needed), and possible just confuse. It is considered best to  
let the application writer define the buffer’s size explicitly.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [February 8, 2019, 4:07am UTC](https://forums.freertos.org/t/xmessagebuffercreate-api-meaning-of-xbuffersizebytes/7659/3 "2019-02-08T04:07:19Z")

</div>

**[armandas](https://sourceforge.net/u/armandas/)** wrote on [Friday, February 08, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/c25eef4fb8/#28cf/c1c6/7bd0):

Thank you for the answer. I had missed the fact that you can store multiple messages in the buffer.
