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

Jussi Laako jussi.laako at pp.inet.fi
Wed Jun 8 16:35:53 EDT 2005

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

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>
        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",

    return 0;

Jussi Laako <jussi.laako at pp.inet.fi>

More information about the linux-audio-dev mailing list