Developing Apama Applications > Writing Correlator Plug-ins > Advanced Plug-in Functionality in C++ and C > Working with chunk in C
Working with chunk in C
In C, working with chunks is similar. Functions that carry out the functionality that would otherwise be defined within the class methods need to be implemented. There are two specific rules that must be followed.
First a callback function table must be supplied with every user chunk that is created. Here’s an example;

const struct AP_PluginChunk_Callbacks exampleChunkCallbacks = {
  exampleChunkFreeUserData,
  exampleChunkCopyUserData,
};
This specifies the functions that represent the ‘destroy’ and ‘copy’ functions described in the above C++ sections.
The other rule is that the user must implement a chunk ‘constructor’ like method. Its contents or name do not matter, but it must return a specific structure that is obtained through calling the createChunk function. Here’s an example constructor;

AP_PluginChunk* exampleChunkConstructor(
  const AP_PluginContext *ctx, unsigned size)
{
  struct ExampleChunk* data;
 
  data = (struct ExampleChunk*)malloc(
    sizeof(struct ExampleChunk));
  data->size = size;
  data->data = (double *)malloc(sizeof(double) * size);
  printf(
    "ExampleChunk constructor called with size = %u\n",size);
  return ctx->functions
    ->createChunk(ctx,&exampleChunkCallbacks,data);
}
Copyright © Software AG, Darmstadt, Germany and/or Software AG USA Inc., Reston, VA, USA, and/or its Subsidiaries and or/its Affiliates and/or their licensors.
Use, reproduction, transfer, publication or disclosure is prohibited except as specifically provided for in your License Agreement with Software AG.