On Wed, 2005-06-08 at 22:09 +0300, Jussi Laako wrote:
And you can still access the individual samples by
using vData[n]
without significant performance penalty compared to a simple float
array. And I say "significant" here just because it also performs bounds
checking. It could be made even equally fast by changing the operator[]
implementation.
I wanted to make sure that this thing is clear, so I'll clarify it even
further.
You can derive a new class from the template and overload the []
operator to perform exactly same as in C. After compilation the result
is the same no matter if the template or C array is used.
Except that the template automatically resizes, is aligned to
architecture optimal boundary size, automatically selects asm SIMD
optimizations for current runtime architecture, etc.
#include <dsp/DSPVector.hh>
template <class TOwnVector_t> class clOwnVector :
public clDSPVector<TOwnVector_t>
{
public:
TOwnVector_t & operator[] (size_t uIndex)
{
return (clDSPVector<TOwnVector_t>::GetRawPtr()[uIndex]);
}
};
int main (int argc, char *argv[])
{
float fpInit[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f };
clOwnVector<float> vecOwn;
vecOwn.Put(fpInit, 5);
vecOwn *= vecOwn;
printf("%g %g %g %g %g\n",
vecOwn[0],
vecOwn[1],
vecOwn[2],
vecOwn[3],
vecOwn[4]);
return 0;
}
--
Jussi Laako <jussi.laako(a)pp.inet.fi>