summaryrefslogtreecommitdiff
path: root/docs/ref/msg/nng_msg_realloc.adoc
blob: bf6e48316de6f19a5a3164ed5e02c56d274d89f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
## nng_msg_realloc

Reallocate a message.

### Synopsis

```c
#include <nng/nng.h>

int nng_msg_realloc(nng_msg *msg, size_t size);
```

### Description

The `nng_msg_realloc` function re-allocates a message so that it has a body of length _size_.
This message attempts to avoid extra allocations, and will reuse the existing memory when possible.

Reallocation is guaranteed to succeeed new length is less than xref:nng_msg_capacity.adoc[`nng_msg_capacity`].

TIP: `nng_msg_realloc` is suitable for creating space for direct writing of data.
When appending many small pieces of data to a message using xref:nng_msg_append.adoc[`nng_msg_append`], allocations may be reduced by first using xref:nng_msg_reserve.adoc[`nng_msg_reserve`] to create sufficient space.

NOTE: Reallocation invalidates any previously obtained pointers to the message body or header.

### Return Values

This function returns 0 on success, and non-zero otherwise.

### Errors

[horizontal]
`NNG_ENOMEM`:: Insufficient free memory exists to reallocate a message.

### See Also

xref:nng_msg_append.adoc[nng_msg_append],
xref:nng_msg_body.adoc[nng_msg_body],
xref:nng_msg_insert.adoc[nng_msg_insert],
xref:nng_msg_len.adoc[nng_msg_len],
xref:nng_msg_reserve.adoc[nng_msg_reserve],
xref:nng_msg_trim.adoc[nng_msg_trim]