The "no gc" crowd

Jonathan M Davis jmdavisProg at gmx.com
Wed Oct 9 20:55:07 PDT 2013


On Wednesday, October 09, 2013 20:04:50 Jacob Carlborg wrote:
> On 2013-10-09 19:10, Andrei Alexandrescu wrote:
> > Again: USER CODE SHOULD HAVE NO BUSINESS CASTING CASUALLY TO GET WORK
> > DONE.
> 
> I agree. Doesn't "new shared(X)", or something like that, already work?

That depends. It works with objects I think (for both shared and immutable), 
but you definitely have to cast to immutable if you want an immutable array or 
AA.

Also, casting _away_ shared is going to be a very common operation due to how 
shared works. In order to use shared, you basically have to protect the 
variable with a mutex or synchronized block, cast away shared, and then use it 
as thread-local for whatever you're doing until you release the lock (in which 
case, you have to be sure that there are no more thread-local references to 
the shared object). As such, while it might be possible to construct stuff 
directly as shared, it's going to have to be cast to thread-local just to use 
it in any meaningful way. So, at this point, I don't think that it even 
vaguely flies to try and make it so that casting away shared is something that 
isn't typically done. It's going to be done about as often as shared is used 
for anything other than very basic stuff.

As things stand, I don't think that it's even vaguely tenable to claim that 
casting should be abnormal with regards to immutable and shared. There will 
definitely have to be language changes if we want casting to be abnormal, and I 
think that the two main areas which would have to change would be the 
initialization of immutable arrays and AAs (since that outright requires 
casting at this point), and shared would probably have to have a major 
redesign, because it's outright unusable without casting it away.

- Jonathan M Davis


More information about the Digitalmars-d mailing list