Faster Virtual Method Dispatch

Walter Bright newshound at digitalmars.com
Wed Apr 26 01:35:35 PDT 2006


Mike Capp wrote:
> In article <e2mfjd$1f3d$1 at digitaldaemon.com>, Walter Bright says...
>> True, but shared_ptr<> is billed as the C++ answer to gc, and 
>> shared_ptr<> is not intrusive.
> 
> Shrug. I'm finding myself increasingly unconcerned these days with what's
> "billed as the C++ answer". I mean, iostreams?

I know what you mean.


>>> Refcount twiddling is only needed when changing an
>>> "owning" pointer, plus the rare "safety" case 
>> But that means just going back to the old way of being very, very 
>> careful about who "owns" the pointer and who doesn't. Refcounting is 
>> supposed to eliminate that nuisance.
> I'm not sure that's true. Smartpointer refcounting is supposed to make ownership
> rules explicit in code where they can be a) seen and b) automated, instead of
> hidden in documentation.

I can see that point, but I can see that once you stray into such 
optimizations, there's no help from the compiler, and you'll need to be 
very careful. A corollary to that is extra time is spent, and bugs are 
likely.

> In practice, I still make daft array-overrun and fencepost errors from time to
> time, but I've never had a problem with refcounting and ownership. As a first
> approximation: member variables, globals and new'ed locals are owners, and
> everything else isn't. Exceptions to this rule (e.g. double-linked lists) tend
> to be glaringly obvious.

Andrei Alexandrescu has proposed a series of modifications to C++ to 
enable the compiler to enforce such rules, but nobody else seemed much 
interested in it.

>> Sure you could do that, but then slices and shared_ptr's are not 
>> interchangeable.
> 
> True, but again, I'm not especially interested in shared_ptr, and this isn't a
> fundamental problem - you can write intrusive interchangeable string and slice
> classes in C++.

Perhaps, but I've never seen anyone pull it off.


>>> Has there ever been a language that successfully combined 
>>> compacting GC with raw pointers? How would this work? 
>> Oh, it's quite doable <g>.
> 
> I find your ideas intriguing, and would like to subscribe to your newsletter.
> 
> Can you elaborate, or is this a trade secret?

I'd rather not, until I get it working.



More information about the Digitalmars-d mailing list