Quantcast
Channel: LabWindows/CVI topics
Viewing all articles
Browse latest Browse all 5355

memory leak with callback function

$
0
0

Hi,

I am fairly new to LabWindows and the ninetv library, i have mostly been working with LabVIEW.

I am trying to create a basic (no GUI) c++ client that sets up subscriptions to several network variables publishing DAQ data from a PXI.

The data for each variable is sent in a cluster and contains various datatypes along with a large int16 2D array for the data acquired(average array size is 100k in total, and the average time between data sent is 10ms). I have on average 10 of these DAQ variables.

I am passing the same callback function as an arguement to all of these subscriptions(CNVCreateSubcription).

It reads all the correct data, but i have one problem which is that i am experiencing a memory leak in the callback function that i pass to the CNVCreateSubscription.

I have reduced the code one by one line and found the function that actually causes the memory leak, which is a CNVGetStructFields(). At this point in the program the data has still not been passed to the clients variables.

 

This is a simplified version of the callback function, where i just unpack the cluster and get the data (only showing from one field in the cluster in the example, also not showing the decleration).

The function is passed into to the subscribe function, like so:

 

static void CNVCALLBACK SubscriberCallback(void * handle, CNVData data, void * callbackData);

 

CNVCreateSubscriber (url.c_str(), SubscriberCallback, NULL, 0, CNVWaitForever, 0 , &subscriber);

 

 

static void CNVCALLBACK SubscriberCallback(void * handle, CNVData data, void * callbackData)
{


int16_t daqValue[100000];

long unsigned int nDims;
long unsigned int daqDims[2];
CNVData fields[1];
CNVDataType type;
unsigned short int numFields;

 

CNVGetDataType(data, &type, &nDims);
CNVGetNumberOfStructFields (data, &numFields);
CNVGetStructFields (data, fields, numFields); // <-------HERE IS THE PROBLEM, i can comment out the code after this point and it still causes a memory leak.

CNVGetDataType(fields[0], &type, &nDims);

CNVGetArrayDataDimensions(fields[0], nDims, acqDims);
CNVGetArrayDataValue(fields[0], type, daqValue, daqDims[0]*daqDims[1]);

CNVDisposeData(data);

 

 

At the average settings i use all my systems memory (4GB) within one hour. 

 

My question is, have any else experienced this and what could the problem/solution to this be?

 

Thanks.


Viewing all articles
Browse latest Browse all 5355


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>