Re: [linux-audio-dev] [ot] [rant] gcc, you let me down one time too many

From: Jussi Laako <jussi.laako@email-addr-hidden>
Date: Wed Jun 08 2005 - 23:35:53 EEST

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@email-addr-hidden>
Received on Thu Jun 9 04:15:13 2005

This archive was generated by hypermail 2.1.8 : Thu Jun 09 2005 - 04:15:13 EEST