[Prev][Next][Index][Thread]
Re: Need help with Class-Allocated Slots
Hugh Greene wrote:
.....
> Well, all the DRM says (in the one place I looked -- it's infamous for
> having relevant information spread across several separate pages!) is
>
> class allocation specifies there is only one storage location
> used by all the general instances of the class. All the
> instances share a single value for the slot. If the value is
> changed in one instance, all the instances see the new value.
>
> I *think* there's no value for the slot until the first (successful) call
> to "make". (At the moment we can't tell. If we make such slots
> accessible via classes, presumably they have to be initialised whenever
> the class is "ready", even if no instances exist?) It's not clear (to me,
> from the above) whether or not the value could be GCd at any point where
> all instances have been GCd. To put it another way, I think you could GC
> it and not be inconsistent with the DRM.
If there is only one storage location then it would seem that it is
independent of the existance of the instances. In other words it is a
"global variable" and subjects to the permanent non-GCness of such
values. While "weak" globals are likely useful I don't see
them mentioned.
To me the DRM seems to connote the notion of permitting
a lazy initialization of class slots. That would have to be changed with
"instantless" access. Since the DRM doesn't give a mechanism of
accessing a slot without any instances, it doesn't matter if the class slot
is lazily initialized. The DRM says class slots can be initialized
"before or during the creation of the first instance". If there's to be
"instantless" acess then this that "during" probably needs to be dropped
(likewise the initialization if absent from initialization arg list).
This may also open up some vulgarities if the initialization expression
is nontrival and introduces ordering problems. Which may have been
some of the rationale for allowing this to be done "just in time".
Lyman
Follow-Ups:
References: