Re: ArrayList vs. List<>

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Jon Harrop <jon@xxxxxxxxxxxxxxxxx> wrote:
Jon Skeet [C# MVP] wrote:
Well, it's not just a C# thing - boxing/unboxing is a CLR concept too.
(FWIW, the same terminology applies in Java - I've never heard of
reference-to-reference conversions being described as boxing before.)

I'm from a functional programming background most recently and, to me,
boxing means referring to a block of memory by pointer and it is only used
in reference to the internal run-time representations of a language
implementation.

Right. It's certainly nothing like that.

In the case of C# (and the CLR), the word "box" seems to have quite a
different meaning where (correct me if I'm wrong) some types have been
given special status as so-called "value" types (probably in the interests
of performance) that are not inherited from the almost-universal type
Object, and regaining the flexibility of a universal type by wrapping a
value type in an object is referred to as "boxing".

Well, it's not just about performance. See
http://pobox.com/~skeet/csharp/memory.html
and
http://pobox.com/~skeet/csharp/references.html
for more description - but there may be "gotchas" in there where the
same word is used for different meanings in functional code.

Frans' statement seems to have been about referential transparency
then.

Do you mean Jon Davis' statement? The only statement I saw Frans making
was to say that strings aren't boxed because they're already reference
types.

Frans' statement really confused me because I understood the first half to
mean that strings are handled as an inline char array (unboxed) but the
second half means that strings are handled as a pointer to a char array.

In fact, I think he was saying that strings are immutable values passed by
reference. That's pretty much the simplest decent representation of a
string so it makes sense. If you wanted to handle huge strings with
variable-length chars then a more sophisticated data structure could be
swapped in transparently.

Strings are indeed immutable, but they're not passed by reference in
the formal description of those semantics. Instead, the reference is
passed by value.

See http://pobox.com/~skeet/csharp/parameters.html for a rather more
detailed description.

--
Jon Skeet - <skeet@xxxxxxxxx>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
.



Relevant Pages

  • Re: ArrayList vs. List<>
    ... boxing means referring to a block of memory by pointer and it is only used ... array of complex numbers is represented as a float array internally in the ... was to say that strings aren't boxed because they're already reference ... mean that strings are handled as an inline char array but the ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Complex Specified Information - Pitman Formula
    ... between the reference string and the test string. ... I *know* what sequences actually exist or possibly could ... There are only test strings that you compare to ...
    (talk.origins)
  • Re: Complex Specified Information - Pitman Formula
    ... between the reference string and the test string. ... I *know* what sequences actually exist or possibly could ... There are only test strings that you compare to ...
    (talk.origins)
  • Re: Complex Specified Information - Pitman Formula
    ... you go out to analyze any other sequences. ... other reference you give. ... is it possible for a set of reference strings to miss a non- ... sequences is likely to be non-random in origin. ...
    (talk.origins)
  • Re: Complex Specified Information - Pitman Formula
    ... you go out to analyze any other sequences. ... other reference you give. ... is it possible for a set of reference strings to miss a non- ... sequences is likely to be non-random in origin. ...
    (talk.origins)