Stopping FastLineSeries deallocation/reallocation of memory

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Bill Anderson
Newbie
Newbie
Posts: 6
Joined: Wed Jul 02, 2003 4:00 am

Stopping FastLineSeries deallocation/reallocation of memory

Post by Bill Anderson » Tue May 02, 2006 12:49 pm

I am using FastLineSeries to plot arrays of up to 1,000,000 points, but I plot them as they are acquired in a data acquisition system, about 2000 pts every 100 msec. To do this I am using FastLineSeries->AddXY() to add points every 100 msec, and FastLineSeries->Clear() to clear the chart every minute or so.


When I watch the "Mem Usage" value in the Windows Task Manager I see it slowly increase as the plotting begins (indicating additional memory allocation) and this continues up to when the plot is Cleared() at which time the "Mem Usage" rapidly drops down (deallocation). Then gradually the "Mem Usage" begins increasing again when plotting again starts. This repeated deallocation/reallocation of memory is very wasteful.

Is there any way I can control when the deallocation occurs, but have allocation continue if more is eventually needed?


Alternatively, I understand I could use Direct Dynamic Arrays and use SetLength() to directly allocate the memory once and maybe change its size when needed.

Do I need to upgrade from version 6.0 to 7 to use SetLength() and Direct Dynamic Arrays?


I am using C++Builder 6 and VCL TeeChart Pro 6.0.


Thank you.
Bill Anderson

Pep
Site Admin
Site Admin
Posts: 3303
Joined: Fri Nov 14, 2003 5:00 am
Contact:

Post by Pep » Thu May 04, 2006 8:59 am

Hi Bill,

well, AddXY method is the slowest way to add points to series. The best solution would be to use dynamic arrays. Here is the code you can use with the TeeChart Pro v6 :

Code: Select all

void __fastcall TDynArrays::Button1Click(TObject *Sender)
{
// TChartValues
DynamicArray<double> X;
DynamicArray<double> Y;
// number of points }
int Num = 10000;
// allocate our custom arrays }
X.Length = Num;
Y.Length = Num;
// fill data in our custom arrays }
X[0] = 0;
Y[0] = random(10000);
for (int t=1; t<Num;t++)
{
X[t] = t;
Y[t] = Y[t-1]+random(101)-50;
}
// set our X array }
Series1->XValues->Value =(TChartValues)(X); // <-- the array
Series1->XValues->Count = Num; // <-- number of points
Series1->XValues->Modified = true; // <-- recalculate min and max
// set our Y array }
Series1->YValues->Value = (TChartValues)(Y); // <-- the array
Series1->YValues->Count = Num; // <-- number of points
Series1->YValues->Modified = true; // <-- recalculate min and max
Chart1->UndoZoom(); // <-- remove zoom (optional)
// Show data
Series1->Repaint();
}

Bill Anderson
Newbie
Newbie
Posts: 6
Joined: Wed Jul 02, 2003 4:00 am

Stopping FastLineSeries deallocation/reallocation of memory

Post by Bill Anderson » Thu May 04, 2006 12:31 pm

Thanks Pep,

I'll try this out now. May have some more questions in the future, because I plot my part of my graph every 100 msec rather than all at once.

Cheers,

Bill

Bill Anderson
Newbie
Newbie
Posts: 6
Joined: Wed Jul 02, 2003 4:00 am

Stopping FastLineSeries deallocation/reallocation of memory

Post by Bill Anderson » Mon May 08, 2006 11:12 am

Hi Pep,

I earlier sent a message to the Forum on using FastLineSeries to plot arrays of up to 1,000,000 points, but I plot them as they are acquired in a multitasking data acquisition system in real-time, at about 2000 pts every 100 msec.

You suggested that I use Dynamic Arrays instead of the AddXY() method.

However, I found that the requirement to Repaint() the WHOLE array (ie when adding the last 2000 pts to a Dynamic Array of 1,000,000 pts) made it much slower than my AddXY() method. The Repaint() of the WHOLE Dynamic Arrays takes about 50 msec!


I have two questions now...

1) When using Dynamic Arrays, is there any way to add say 2000pts at the end of the arrays and then plotting ONLY the NEW POINTS ADDED (like happens with the AddXY() method)?


2) Getting back to my original question... Is there any way I can control the minimum amount of memory that a FastLineSeries has so that the wasteful deallocation/reallocation cycle does not have to occur when plotting large plots using the AddXY() method 100msec at a time in a multitasking environment?

I recall reading that there was such a function, but I can't remember it and can't find it in your documentation.


Thanks,

Bill

Post Reply