freepooma-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

UserFunction question


From: Renato Fernandes Cantão
Subject: UserFunction question
Date: 02 Sep 2002 19:08:49 -0300

Hello Guys!

I've been dealing with UserFunction, but I have a question: suppose I'm
using a UserFunction to manipulate Array's of big elements, like that:

typedef Array< 2 >              InnerType_t;
typedef Array< 1, InnerType_t > BigType_t;

class Operation
{
   public:
      // returning reference to avoid construction/destruction 
      // repetition

      inline InnerType_t& operator( const InnerType_t& t ) const
      {
         p = t * t;   // stupid example...

         return p;
      }

   private:
      InnerType_t p;   // initialized in some manner in the constructor
};

And then:

main()
{
   BigType_t Big1( 1000 ), Big2( 1000 );

   for( int i = 0; i < 1000; i++ )
   {
      Big1( i ).initialize( 100, 100 );
      Big2( i ).initialize( 100, 100 );
   }

   // fill the array's here...

   UserFunction< Operation > F;

   Big2 = F( Big1 );
}

F runs through Big1, applies Operation.operator() in each Big1( i ) --
2D Array's with 10000 elements each -- and finally *copies* the result
to Big2( i ). Correct? I'm interested on this subject cause I do lots of
operations with Arrays of Arrays, usually through loops. Loops are
faster, cause -- I guess -- UserFunction has to copy the InnerType_t's
between Big1 and Big2.

An approach like:

void operation( const InnerType_t& t, InnerType_t& p )
{
   p = t * t;
}

void applyOperation( const BigType_t& Big1, BigType_t& Big2 )
{
   const int n = Big1.length( 0 );

   for( int i = 0; i < n; i++ )
   {
      operation( Big1( i ), Big2( i ) );
   }
}

is faster.

So the question: is there a way to avoid this copying behavior, and so
mimic the loop above, but still using UserFunction?

Thanks a lot, Cantao!

-- 
                     '''
                    (o o)
+--------------oOOO--(_)----------------------+
| Renato F. Cantao!                           |
| Depto. de Matematica Aplicada               |
| IMECC - UNICAMP                             |
| Sala 215 - Predio da Pos-graduacao - Lado B |
+--------------------------OOOo---------------+
                   |__|__|
                    || ||
                   ooO Ooo   Linux User #207462


reply via email to

[Prev in Thread] Current Thread [Next in Thread]