PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.cplus > Re: pasing an array pointer and storing as a class member
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Re: pasing an array pointer and storing as a class member

Réponse
 
LinkBack Outils de la discussion
Vieux 16/10/2007, 20h31   #1
stephen b
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: pasing an array pointer and storing as a class member

On 14 Oct, 19:56, "BobR" <removeBadB...@worldnet.att.net> wrote:
> stephen b wrote in message...
>
> > I am using arrays instead of vector<double> because I found the
> > initialisation of many vector<double>s caused brief CPU spikes each
> > time an object is created.

>
> I'm curious. How did you initialize the vectors?
>
> > Arrays seemed less troublesome which is
> > important for real-time DSP stuff.

>
> I think it's the opposite. :-}


really? right, I think I initialised my vectors like this:
vector<double> vec (8192, 0.); so I guess maybe filling the array
with zeros was causing some overhead. I also found arrays to be
slightly more efficient in use although it's probably negligible even
though I'll be using 20 or so per synth.


> Could it be because you are dereferenceing un-initialized data (the arrays)?
> Let's test something. In your FilterSynth() constructor:
>
> FilterSynth(){
> for( int i(0); i < 10; ++i ){
> std::cout<< filtIn[ i ] <<'\n';
> } // for(i)
> } // Ctor
>
> What's your output from that? (I got garbage (UB)).


well with the filter example I fill the array with zeros first but
otherwise just garbage.

Stephen.

  Réponse avec citation
Vieux 17/10/2007, 01h16   #2
BobR
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: pasing an array pointer and storing as a class member


stephen b <kernel@audiospillage.com> wrote in message
news:1192563109.115307.88440@i38g2000prf.googlegro ups.com...
> On 14 Oct, 19:56, "BobR" <removeBadB...@worldnet.att.net> wrote:
> > stephen b wrote in message...
> > > I am using arrays instead of vector<double> because I found the
> > > initialisation of many vector<double>s caused brief CPU spikes each
> > > time an object is created.

> >
> > I'm curious. How did you initialize the vectors?
> >
> > > Arrays seemed less troublesome which is
> > > important for real-time DSP stuff.

> >
> > I think it's the opposite. :-}

>
> really? right, I think I initialised my vectors like this:
> vector<double> vec (8192, 0.); so I guess maybe filling the array
> with zeros was causing some overhead. I also found arrays to be
> slightly more efficient in use although it's probably negligible even
> though I'll be using 20 or so per synth.
>
> > Could it be because you are dereferenceing un-initialized data (the

arrays)?
> > Let's test something. In your FilterSynth() constructor:
> >
> > FilterSynth(){
> > for( int i(0); i < 10; ++i ){
> > std::cout<< filtIn[ i ] <<'\n';
> > } // for(i)
> > } // Ctor
> >
> > What's your output from that? (I got garbage (UB)).

>
> well with the filter example I fill the array with zeros first but
> otherwise just garbage.
> Stephen.
>


By the time you initialize your raw arrays, there should be very little
difference with std::vectors. (you don't need the '0.0' in init, it is the
default.)

Try your tests with this and see how it goes:
This compiles on my system, but of course, you'll need to modify it to use
your base classes, etc.. Just for a suggestion.

class Filter{ public:
// Filter( double *inBlk, double *outBlk ){
// in = inBlk; out = outBlk; }
Filter( std::vector<double> const &inBlk,
std::vector<double> &outBlk )
: in( inBlk.begin() ), out( outBlk.begin() ){}
// void Process(UInt32 inNumFrames) {
void Process( int inNumFrames ){
double y0(0); // for test compile
for( int i(0); i < inNumFrames; ++i){
y0 = *(in)++;
*(out)++ = y0;
} // for(i)
} // Process(int)
private:
// double *in, *out;
std::vector<double>::const_iterator in;
std::vector<double>::iterator out;
};

// If 'in' and 'out' are only used in 'Process', you may want
// a normal constructor and use the following for 'Process':
// void Process( std::vector<double> const &inBlk,
// std::vector<double> &outBlk ){ .... }
// .... and change the call below. Then you wouldn't need the
// iterators in the class (just in the function).

class FilterSynth{ public:
FilterSynth() : filtIn(8192), filtOut(8192), filt( filtIn, filtOut ){}
virtual ~FilterSynth(){} // not needed if base Dtor is virtual.
// virtual UInt32 NextBlock( UInt32 inNumFrames ){
virtual int NextBlock( int inNumFrames ){
// this function is called by another class.
filt.Process( inNumFrames );
return 0;
}
private:
std::vector<double> filtIn;
std::vector<double> filtOut;
Filter filt;
};

This is a little 'loose', but I don't know exactly the problem you are
working.
Hope that s some.
--
Bob R
POVrookie


  Réponse avec citation
Vieux 17/10/2007, 03h27   #3
Andre Kostur
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: pasing an array pointer and storing as a class member

"BobR" <removeBadBobR@worldnet.att.net> wrote in
news:BvcRi.226524$ax1.159736@bgtnsc05-news.ops.worldnet.att.net:

>
> stephen b <kernel@audiospillage.com> wrote in message
> news:1192563109.115307.88440@i38g2000prf.googlegro ups.com...
>> On 14 Oct, 19:56, "BobR" <removeBadB...@worldnet.att.net> wrote:
>> > stephen b wrote in message...
>> > > I am using arrays instead of vector<double> because I found the
>> > > initialisation of many vector<double>s caused brief CPU spikes
>> > > each time an object is created.
>> >
>> > I'm curious. How did you initialize the vectors?
>> >
>> > > Arrays seemed less troublesome which is
>> > > important for real-time DSP stuff.
>> >
>> > I think it's the opposite. :-}

>>
>> really? right, I think I initialised my vectors like this:
>> vector<double> vec (8192, 0.); so I guess maybe filling the array
>> with zeros was causing some overhead. I also found arrays to be
>> slightly more efficient in use although it's probably negligible even
>> though I'll be using 20 or so per synth.
>>
>> > Could it be because you are dereferenceing un-initialized data (the

> arrays)?
>> > Let's test something. In your FilterSynth() constructor:
>> >
>> > FilterSynth(){
>> > for( int i(0); i < 10; ++i ){
>> > std::cout<< filtIn[ i ] <<'\n';
>> > } // for(i)
>> > } // Ctor
>> >
>> > What's your output from that? (I got garbage (UB)).

>>
>> well with the filter example I fill the array with zeros first but
>> otherwise just garbage.
>> Stephen.
>>

>
> By the time you initialize your raw arrays, there should be very
> little difference with std::vectors. (you don't need the '0.0' in
> init, it is the default.)


Keep in mind that std::vector has to do (Well, is very likely to do)
dynamic memory to store its contents. Arrays do not. You might try
std::tr1:array instead...
  Réponse avec citation
Vieux 17/10/2007, 18h43   #4
BobR
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: pasing an array pointer and storing as a class member


Andre Kostur wrote in message...
>
> Keep in mind that std::vector has to do (Well, is very likely to do)
> dynamic memory to store its contents. Arrays do not. You might try
> std::tr1:array instead...


A valid argument. But, sticking 2+ meg in the stack might be a source of his
problem (stack overflow/corruption?).
And if you 'new' the arrays, well, I think std::vector is a good choice.

[ I don't know how C++ sets up the stack, but in assembler, it was precious
realestate. My logic is small things on stack, big things in dynamic(heap).
Feel free to inform/correct me on this point. :-}]
--
Bob R
POVrookie


  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 05h51.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,11610 seconds with 12 queries