www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - immutable and RC

reply Marco Leise <Marco.Leise gmx.de> writes:
Is it possible to write a wrapper for file handles, that is
immutable if we don't plan to swap out the handle and the ref
count is in some external data structure and only accessed
in ctors/dtors of the struct ?
It would look quite a bit like some sort of head immutable,
but with no access to the mutable parts.

The motivation is that immutable is inherently shared, so it
simplifies code where a file handle might be used by several
threads but synchronization is ensured by the operating system
or at a higher level in our code.
(Otherwise one would have to reimplement read, write,
handle, ... with the exact same code, but `shared` attached or
cast away `shared`, which is wrong.)

-- 
Marco
Oct 14 2014
parent "Kagamin" <spam here.lot> writes:
A file handle is usually a plain integer, it doesn't make much 
sense to annotate it with attributes.
Oct 16 2014