cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

spectral
Adept II

Which is the best ?

Hi,

I have 2 ways to create a method to get back a result... but which one is the best, in term of memory and performance ?

MyData t;
myFunction(&t);

void myFunction(MyData* data) { .... data.val = 10; ... }

or

MyData t = myFunction();

MyData myFunction() { MyData data; data.val = 10; return data; }

By example, in the first version, I think that we avoid the creation of 2 MyData, but it really depend of the compiler optimization.

0 Likes
5 Replies
himanshu_gautam
Grandmaster

viewon01,

AFAIK,the functions are inlined in openCL.Therefore its better to have smaller functions.The second method would create a variable everytime it is called,so more memory cycles are needed.Also code length increases largely if myfunc is called many times.

Thanks

0 Likes

So, if everything is inlined, maybe it is better to use this version ?
And use reference and not pointers ?

MyData t;
myFunction(t);

void myFunction(MyData& data) { .... data.val = 10; ... }



0 Likes

hi viewon01,

AFAIK references should not be available im openCL.And the code do not build on my system.

 

0 Likes

😞

It should be a good way to optimize the code. Except if the compiler is really good it alread avoid to create a pointer and directly use the 'memory block' !

0 Likes

Yes.But it is not mentioned in the spec.and hence the implementor is not forced to provide this functionality.

0 Likes