# ctaAllocBuffer

Allocates memory for data transport with ctaQueueEvent.

#### Prototype

DWORD ctaAllocBuffer ( void **buffer, unsigned size)

Argument | Description
buffer | Address of the pointer to the returned buffer.
size | Requested size of the buffer to allocate.

#### Return values

Return value | Description
SUCCESS |
CTAERR_BAD_ARGUMENT | Invalid parameter, NULL buffer pointer, or 0 size.
CTAERR_NOT_INITIALIZED | Natural Access is not initialized. Call ctaInitialize first.
CTAERR_OUT_OF_MEMORY | Memory allocation error.

#### Details

ctaAllocBuffer allocates memory inside Natural Access. The Natural Access memory allocation mechanism can be used to send data in an event.

If an application sends an event with a shared context handle, the event is received by all context clients (applications or threads). The sending application receives an event with the buffer allocated by the application and no flag in the size field. To free the buffer, the application should use ctaFreeBuffer.

All other context clients receive an event with the Natural Access internal buffer in the event and CTA_INTERNAL_BUFFER in the size field. The clients should use ctaFreeBuffer to free memory allocated with ctaAllocBuffer.

#### Example

#define APPEVN_MESSAGE CTA_USER_EVENT(0x1)
int DemoSendMessage(CTAHD ctahd, unsigned mode, char* strMessage)
{
int ret;
CTA_EVENT event;
memset( &event, 0, sizeof(event) );
event.id = APPEVN_MESSAGE;
event.ctahd = ctahd;
event.value = mode;
event.size = ( strMessage ) ? strlen(strMessage ) : 0;
if( event.size != 0 )
{
event.size += 1;
ret = ctaAllocBuffer( &event.buffer,event.size);
if( ret != SUCCESS )
return ret;
strcpy( (char*)event.buffer,strMessage );
}
return ctaQueueEvent( &event );
}