Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Which one is better/more efficient??

Author
Message
AndrewT
17
Years of Service
User Offline
Joined: 11th Feb 2007
Location: MI, USA
Posted: 24th Jan 2008 01:09 Edited at: 24th Jan 2008 01:09
I'm taking a stab at making DGDK more OOP-ish. I was just curious; for a 'getPosition' function for things such as an object, would it be better to have a single function that returns a coordinate, or a function for X, Y and Z?

Heres what I mean:

This?


Or this?


Is there any advantage to using either??
monotonic
18
Years of Service
User Offline
Joined: 24th Mar 2006
Location: Nottinghamshire, England
Posted: 24th Jan 2008 10:51
I'm not an expert at this so don't quote me but, I would think the first variant would be the fastest. Because calling a function and returning a value (3 times for each co-ordinate) uses more clock cycles than copying and returning a 3 float vector.

Who is your Daddy, and what does he do?
kBessa
18
Years of Service
User Offline
Joined: 8th Nov 2006
Location: Manaus, Amazonas, Brazil
Posted: 24th Jan 2008 13:49
DarkGDK does not have a method to get all three coordinates together, but 3 of them.

So the first one would be calling the 3 methods, and then using only 1 of the coordinates. If you were to use the Y coordinate, again you would be calling all 3 methods again.

I hope I made it clear.

-Thiago
monotonic
18
Years of Service
User Offline
Joined: 24th Mar 2006
Location: Nottinghamshire, England
Posted: 24th Jan 2008 14:53 Edited at: 24th Jan 2008 14:56
Yeah true, but if you needed all three co-ordniates, you would be calling six function in theory.

Just to clarify, in the code snippet below I'm not suggesting that the MyObject.GetPositionX() functions return a pointer to a GDK object, which you then call. I have written it like this to show that within the GetPositionX() functions you will be calling the GDK function and returning the value.



As opposed to:




So it would be faster to use the individual get functions if you only need one of the co-ordinates, but to get all of the co-ordinates the second would be faster.


So it would probably be best if you added both of the variants to allow the coder to choose which is best.

Who is your Daddy, and what does he do?
kBessa
18
Years of Service
User Offline
Joined: 8th Nov 2006
Location: Manaus, Amazonas, Brazil
Posted: 24th Jan 2008 15:22
@monotonic: Your point is valid, include both and let the user decide which one to use at the moment it is needed.

But I'd suggest to write some kind of documentation about this, or there would be some users possibly writing this kind of code:


And THAT would be a great overhead. I've designed a full OOP Wrapper as a plugin to DGDK.NET (LightEngine) and had to think about these possibilities.

-Thiago
AndrewT
17
Years of Service
User Offline
Joined: 11th Feb 2007
Location: MI, USA
Posted: 24th Jan 2008 21:11
Thank you. I've decided to simply implement both.

Login to post a reply

Server time is: 2024-11-19 23:03:09
Your offset time is: 2024-11-19 23:03:09