RTI Connext C API
Version 5.3.0
|
<<extension>> Octet buffer creation, cloning, and deletion. More...
Functions | |
unsigned char * | DDS_OctetBuffer_alloc (unsigned int size) |
Create a new empty OctetBuffer that can hold up to size octets. | |
unsigned char * | DDS_OctetBuffer_dup (const unsigned char *buffer, unsigned int size) |
Clone an OctetBuffer. | |
void | DDS_OctetBuffer_free (unsigned char *buffer) |
Delete an OctetBuffer. | |
<<extension>> Octet buffer creation, cloning, and deletion.
The functions in this class ensure consistent cross-platform implementations for OctetBuffer creation (DDS_OctetBuffer_alloc()), deletion (DDS_OctetBuffer_free()), and cloning (DDS_OctetBuffer_dup()) that preserve the mutable value type semantics. These are to be viewed as functions that define an OctetBuffer
class whose data is represented by a 'unsigned
char*'.
The following conventions govern the memory management of OctetBuffers in RTI Connext.
OctetBuffer
class functions. The representation of an OctetBuffer in C/C++ unfortunately does not allow programs to detect how much memory has been allocated for a OctetBuffer. RTI Connext must therefore make some assumptions when a user requests that a OctetBuffer be copied into. The following rules apply when RTI Connext is copying into an OctetBuffer.
This requirement can generally be assured by adhering to the following idiom for manipulating OctetBuffers.
Not adhering to this idiom can result in bad pointers, and incorrect memory being freed.
In addition, the user code should be vigilant to avoid memory leaks. It is good practice to:
unsigned char* DDS_OctetBuffer_alloc | ( | unsigned int | size | ) |
Create a new empty OctetBuffer that can hold up to size
octets.
An OctetBuffer created by this function must be deleted using DDS_OctetBuffer_free(). This function will allocate enough memory to hold an OctetBuffer of \p size octets.
size | <<in>> Size of the buffer. |
unsigned char* DDS_OctetBuffer_dup | ( | const unsigned char * | buffer, |
unsigned int | size | ||
) |
Clone an OctetBuffer.
An OctetBuffer created by this function must be deleted using DDS_OctetBuffer_free()
buffer | <<in>> The OctetBuffer to duplicate. |
size | <<in>> Size of the OctetBuffer to duplicate. |
src
== NULL or size <0, this function always returns NULL. Otherwise, upon success it returns a newly created OctetBuffer whose value is src
; upon failure it returns NULL. void DDS_OctetBuffer_free | ( | unsigned char * | buffer | ) |
Delete an OctetBuffer.
buffer
must be either NULL, or must have been created using DDS_OctetBuffer_alloc(), DDS_OctetBuffer_dup()buffer | <<in>> The buffer to delete. |