Passing dynamic arrays
Steven Schveighoffer
schveiguy at yahoo.com
Tue Nov 9 04:42:13 PST 2010
On Mon, 08 Nov 2010 21:29:42 -0500, Jesse Phillips
<jessekphillips+D at gmail.com> wrote:
> Well, if you can come up with a good definition for what "increasing the
> size of a class" would do, then maybe it should be added.
>
> It really doesn't matter. Arrays are their own type, the have their own
> semantics. It does help to think of them in terms of slices (which is
> what TDPL refers to them as), yet that does not remove the fact that
> they are in dead a reference type.
>
> Many times familiar terms are used so that a behavior is quickly
> understood. For example it is common to say that arrays in C is just a
> pointer into a memory location. But in reality that is not true.
It depends on your definition of reference type. I agree with Daniel. If
you want to get into academic definitions, yes, 'technically' an array is
a reference, but it's confusing to someone who's not interested in
exploring the theoretical parts of computer science.
I think of an array as a hybrid between a reference and a value type. The
data is passed by reference, the length is passed by value. This mean
changing the length only affects the local copy, but changing the data
affects all arrays that point to that data.
I think it also helps to think of arrays as slices (that's what they are
anyways). There is no more distinction between slices or arrays, they are
one and the same. An array does not own its data, and that is a major
point of confusion. An array always just references data, it never owns
it.
-Steve
More information about the Digitalmars-d
mailing list