ctaFreeBuffer

Frees internally allocated buffers or buffers allocated with ctaAllocBuffer.

Prototype

DWORD ctaFreeBuffer ( void *buffer)

Argument

Description

buffer

Pointer to a buffer allocated with ctaAllocBuffer, or to an internal buffer.


Return values

Return value

Description

SUCCESS

 

CTAERR_BAD_ARGUMENT

If buffer is NULL.

CTAERR_NOT_INITIALIZED

Natural Access is not initialized. Call ctaInitialize first.


Details

ctaFreeBuffer frees internally allocated buffers and memory allocated with ctaAllocBuffer.

If an event received by ctaWaitEvent contains data, the buffer can be allocated inside Natural Access (data allocated and sent from a Natural Access service). In this case, the flag CTA_INTERNAL_BUFFER is set in the size field. Use ctaFreeBuffer to free the event buffer.

Example

CTAHD commCtahd = NULL_CTAHD,  mediaCtahd = NULL_CTAHD;

void EventLoop()
{
    DWORD ret;

    for(;;)
    {
        CTA_EVENT   event = { 0 };
        int         ctaOwnsBuf = 0;
    
        event.ctahd = commCtahd;      
        if( ret = ctaWaitEvent( commCtahd, &event ) != SUCCESS )
        {
            printf("ctaWaitEvent returns 0x%x -- exiting\n", "ret ); 
            exit( -1 );
        } 
      
        /* In Natural Access server mode, certain event buffers are allocated by
        *  Natural Access and then must be released back to Natural Access.
        */ 
        if ( event.buffer ) 
        {
           if ( ctaOwnsBuf = event.size & CTA_INTERNAL_BUFFER )
           {
               /* This buffer is owned by Natural Access and will need to be
               *  released back to Natural Access after processing of the
               *  buffer is complete. Clear the Natural Access flags from the
               *  size field.
               */
               event.size &= ~CTA_INTERNAL_BUFFER;
           }
        }

               /* Event processing */        
        switch ( event.id )
        {
            case APPEVN_EXCHANGE_NAME:
                          . . .
            default:
                break;                 
 
        }
        
        /* Ensure proper release of Natural Access owned buffers. */
        if ( ctaOwnsBuf )
        {
            ctaOwnsBuf = 0;
            ctaFreeBuffer( event.buffer );
        }
    } 
}