Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

C# : how to handle huge data generated by a dll written in C

Status
Not open for further replies.

alaindoe

Programmer
May 17, 2011
2
BE
I have a dll written in C code to I use in my C# project.
One returned data structure is like this :
#define WV_MAX_TREND_PARAMETERS 60
#define WV_MAX_TREND_SAMPLES 1501
#define WV_MAX_TIME_CHANGES 24
#define WV_MAX_TREND_HOURS 25
#define WV_LABEL_SIZE 20


typedef struct
{
WV_PARAMETER_ID WvParameterID[WV_MAX_TREND_PARAMETERS]; ;
CHAR Label[WV_MAX_TREND_PARAMETERS][WV_LABEL_SIZE];
int NumberOfTrends;
} WV_TREND_LIST_A;


typedef struct
{
WV_PARAMETER_ID WvParameterID; // parameter id
CHAR Label[WV_LABEL_SIZE]; // label in english
WV_NET_UNITS_OF_MEASURE Units;
CHAR Values[WV_MAX_TREND_SAMPLES][WV_VALUE_SIZE];
} WV_TREND_PARAMETER_DATA_A;
typedef struct
{
WV_TREND_PARAMETER_DATA_A Trend [WV_MAX_TREND_PARAMETERS];
int NumberOfTrends;
int NumSamples;
time_t SampleTimes[WV_MAX_TREND_SAMPLES];
time_t TimeChanges[WV_MAX_TIME_CHANGES];
int NumTimeChanges;
} WV_TREND_DATA_A;

The claas I finally used is as follow :

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)]
public unsafe struct WV_TREND_LIST_A
{
public fixed int WV_Trend_ParameterID[60];
public fixed byte ParamLabel[1200];
public int NumberOfTrends;
}

public unsafe struct WV_TREND_PARAMETER_DATA_A
{
public int paramID;
public fixed byte ParamLabel[20];
public int units;
public fixed byte values[30020];
}
public unsafe struct WV_TREND_DATA_A
{
public WV_TREND_PARAMETER_DATA_A Trend0;
public WV_TREND_PARAMETER_DATA_A Trend1;
public WV_TREND_PARAMETER_DATA_A Trend2;
public WV_TREND_PARAMETER_DATA_A Trend3;
public WV_TREND_PARAMETER_DATA_A Trend4;
public WV_TREND_PARAMETER_DATA_A Trend5;
public WV_TREND_PARAMETER_DATA_A Trend6;
public WV_TREND_PARAMETER_DATA_A Trend7;
public WV_TREND_PARAMETER_DATA_A Trend8;
public WV_TREND_PARAMETER_DATA_A Trend9;
public WV_TREND_PARAMETER_DATA_A Trend10;
public WV_TREND_PARAMETER_DATA_A Trend11;
public WV_TREND_PARAMETER_DATA_A Trend12;
public WV_TREND_PARAMETER_DATA_A Trend13;
public WV_TREND_PARAMETER_DATA_A Trend14;
public WV_TREND_PARAMETER_DATA_A Trend15;
public WV_TREND_PARAMETER_DATA_A Trend16;
public WV_TREND_PARAMETER_DATA_A Trend17;
public WV_TREND_PARAMETER_DATA_A Trend18;
public WV_TREND_PARAMETER_DATA_A Trend19;
public WV_TREND_PARAMETER_DATA_A Trend20;
public WV_TREND_PARAMETER_DATA_A Trend21;
public WV_TREND_PARAMETER_DATA_A Trend22;
public WV_TREND_PARAMETER_DATA_A Trend23;
public WV_TREND_PARAMETER_DATA_A Trend24;
public WV_TREND_PARAMETER_DATA_A Trend25;
public WV_TREND_PARAMETER_DATA_A Trend26;
public WV_TREND_PARAMETER_DATA_A Trend27;
public WV_TREND_PARAMETER_DATA_A Trend28;
public WV_TREND_PARAMETER_DATA_A Trend29;
public WV_TREND_PARAMETER_DATA_A Trend30;
public WV_TREND_PARAMETER_DATA_A Trend31;
public WV_TREND_PARAMETER_DATA_A Trend32;
public WV_TREND_PARAMETER_DATA_A Trend33;
public WV_TREND_PARAMETER_DATA_A Trend34;
public WV_TREND_PARAMETER_DATA_A Trend35;
public WV_TREND_PARAMETER_DATA_A Trend36;
public WV_TREND_PARAMETER_DATA_A Trend37;
public WV_TREND_PARAMETER_DATA_A Trend38;
public WV_TREND_PARAMETER_DATA_A Trend39;
public WV_TREND_PARAMETER_DATA_A Trend40;
public WV_TREND_PARAMETER_DATA_A Trend41;
public WV_TREND_PARAMETER_DATA_A Trend42;
public WV_TREND_PARAMETER_DATA_A Trend43;
public WV_TREND_PARAMETER_DATA_A Trend44;
public WV_TREND_PARAMETER_DATA_A Trend45;
public WV_TREND_PARAMETER_DATA_A Trend46;
public WV_TREND_PARAMETER_DATA_A Trend47;
public WV_TREND_PARAMETER_DATA_A Trend48;
public WV_TREND_PARAMETER_DATA_A Trend49;
public WV_TREND_PARAMETER_DATA_A Trend50;
public WV_TREND_PARAMETER_DATA_A Trend51;
public WV_TREND_PARAMETER_DATA_A Trend52;
public WV_TREND_PARAMETER_DATA_A Trend53;
public WV_TREND_PARAMETER_DATA_A Trend54;
public WV_TREND_PARAMETER_DATA_A Trend55;
public WV_TREND_PARAMETER_DATA_A Trend56;
public WV_TREND_PARAMETER_DATA_A Trend57;
public WV_TREND_PARAMETER_DATA_A Trend58;
public WV_TREND_PARAMETER_DATA_A Trend59;
public int NumberOfTrends;
public int NumSamples;
public fixed int SampleTimes[1501];
public fixed int TimeChanges[24];
public int NumTimeChanges;
}

The code used is as follow and works until it comes to the last part
getTheTrendsData procedure
when intensiating the Trend data
WV_TREND_DATA_A TrendData = new WV_TREND_DATA_A();
and generates a stack overflow


public void GetTheListOfTrends()
{
WV_TREND_LIST_A TrendList = new WV_TREND_LIST_A();
int numberOfTrends = 0;
try
{
int returnTrendList = NATIVE_WV.WvGetAvailableTrends_A(connectionID, ref TrendList);
numberOfTrends = TrendList.NumberOfTrends;
}
catch (Exception error)
{
error.GetType();
}
Lbx_TrendList.Items.Clear();
Lbx_TrendList.Items.Add("Number of Trends = " + numberOfTrends.ToString());
Lbx_TrendList.Items.Add(" --------------------------------------------- ");
Lbx_TrendList.Items.Add(" ");
for (int i = 0; i < numberOfTrends; i++)
{
int paramID = 0;
String label;
unsafe
{
byte[] b = new byte[20];
// Pin the buffer to a fixed location in memory.
paramID = TrendList.WV_Trend_ParameterID;
for (int j=0; j< 20; j++)
{
int index = i*20+j;
b[j]= TrendList.ParamLabel[index];
}
label = System.Text.ASCIIEncoding.ASCII.GetString(b);
}
Lbx_TrendList.Items.Add("Trend Id number " + i.ToString() + " = " + paramID.ToString() +
" Label = " + label);
}

int totalhours = 1;

getTheTrendsData(connectionID, totalhours, TrendList);
}

private void getTheTrendsData(int connectionID, int totalhours, WV_TREND_LIST_A TrendList)
{
// get the actual trends
WV_TREND_DATA_A TrendData = new WV_TREND_DATA_A();


try
{
//Get all the trends
int returnTrendData = NATIVE_WV.WvGetTrendData(connectionID, ref TrendData, totalhours, ref TrendList);
}

catch(Exception error)
{
MessageBox.Show(error.Message);
}

Can anybody help me ?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top