ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  DoubleArray copy or reference?
Posted by Stephan Bielmann on Jun-26-2014 23:23
Hello all,

I may have overseen it in the documentation, does DoubleArray, or any of the Array classes in CD, make a copy of the array passed to it, or simply store a reference, hence only the pointer to that array ?

Thanks, Stephan

  Re: DoubleArray copy or reference?
Posted by Peter Kwan on Jun-27-2014 02:15
Hi Stephan,

The DoubleArray, IntArray and other array classes simply stores the reference. See:

http://www.advsofteng.com/doc/cdcpp.htm#DoubleArray.htm

In C++ or C, if you pass an array pointer a function, there is no way to determine the
length of the array. Often you have to pass an extra parameter for the length of the array.
This is particular inconvenient if you need to "return" the array reference from a subroutine.
So we invented the DoubleArray class, which is simply a wrapper to store the array
reference and its length. It allows the array pointer and length to be returned in a single
variable. It does not "deep copy" the array.

When you pass DoubleArray to the chart (such as passing DoubleArray to addLineLayer),
ChartDirector will deep copy the array. So the array can be released after passing to the
XYChart or PieChart or BaseChart object.

In C++, there is a standard class called "std::vector" that deep copies the array. If you
want to deep copy the array, you may consider to use std::vector instead. It is easy to
convert std::vector to DoubleArray with negligible overhead. For example:

std::vector<double> myVector = .....;

c->addLineLayer(DoubleArray(&(myVector[0]), myVector.size()));

Hope this can help.

Regards
Peter Kwan

  Re: DoubleArray copy or reference?
Posted by Stephan Bielmann on Jun-27-2014 16:12
Hello Peter,

thanks for the explanation.

Kind regards, Stephan