Performance of method calls

Daniel Keep daniel.keep+lists at gmail.com
Fri Dec 1 08:41:59 PST 2006


Mike Capp wrote:
> == Quote from Daniel Keep (daniel.keep+lists at gmail.com)'s article
> 
> 
>>The only thing I really miss when using structures are constructors and
>>destructors.  Any reason why we can't have them, Walter?  Pwetty pweese?
> 
> 
> I think most people use static opCall as a workaround for the lack of struct
> ctors. It's not a perfect substitute (in particular, you don't get invariant
> checks on 'construction') but it's liveable.

True.  What I'm worried about is the performance difference between

 > Foo x = Foo();

and

 > Foo x; x.init();

Ah well.  It's only one extra statement :)

> I doubt very much whether Walter will ever add struct dtors - it requires a bunch
> of extra code to be generated, and with "scope" there's no great need for them.
> 
> cheers
> Mike

I know, I know.  I just wish I could omit `foo.init(); scope(exit) 
foo.cleanup()` every time I make a Foo.  Then again, it would only be 
worse in C :3

*sigh*  This is what happens when someone says "It has to be efficient": 
I go nuts over every little instruction...

	-- Daniel



More information about the Digitalmars-d mailing list