D - more or less power than C++?

Tyler Knott Tyler_member at pathlink.com
Mon Mar 6 20:49:26 PST 2006


In article <dui6d5$2134$1 at digitaldaemon.com>, Johan Granberg says...
>
>Hasan Aljudy wrote:
>>> Because then i would have to call a method to read bar and that would 
>>> bee inefective. 
>> 
>> You know, CPUs are fast now a days, a single function call is not 
>> "ineffective".
>
>That argument does not hold if you are in a tight loop it will matter.

Why not just use a method to return a pointer to the private member and use that
within your hypothetical tight loop, then use proper get/set methods when CPU
time is not important?  It shouldn't use any more CPU time than referencing the
member directly (because both the object reference and pointer need to be
deferenced before what they referenced can be used through them).  Or what about
copying the member to a temporary variable in the scope above the loop's, using
the temporary variable within the loop, then setting the member to the value of
the temporary var when the loop is finished?  (And even if there is an exception
thrown and you still want the member to be set to the same value as the temp
var, you could use on_scope_failure to call the set method in that event.)





More information about the Digitalmars-d mailing list