On 12/1/2012 3:43 PM, Jonathan M Davis wrote:
Any struct which contains reference types needs them. For instance, a struct
containing int[] needs to dup that array if it doesn't want to have the copy
referring to the same elements as the original and therefore risk having them
be mutated. Arrays with immutable elements don't have that problem, but those
with mutable elements (and to some extent those with const) do have such a
problem, as to structs with classes or structs which are reference types, etc.
I'm surprised that you'd think that postblit constructors were only useful for
implementing reference counting types. IMHO, the language would be crippled
without a postblit or copy constructor for structs.

On the other hand, I'd say you have a pretty expensive design if it required you to allocate memory in order to do a copy. Making copies ought to be a cheap operation.

It's not hard to implement copy-on-write for the referenced data. In fact, with reference counting, you shouldn't need to make those dups.

Reply via email to