Re: ArrayList vs. List<>
- From: Jon Skeet [C# MVP] <skeet@xxxxxxxxx>
- Date: Wed, 16 May 2007 21:26:41 +0100
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
.
- Follow-Ups:
- Re: ArrayList vs. List<>
- From: Jon Harrop
- Re: ArrayList vs. List<>
- References:
- ArrayList vs. List<>
- From: Zytan
- Re: ArrayList vs. List<>
- From: Cor Ligthert [MVP]
- Re: ArrayList vs. List<>
- From: Jon Davis
- Re: ArrayList vs. List<>
- From: Frans Bouma [C# MVP]
- Re: ArrayList vs. List<>
- From: Jon Harrop
- Re: ArrayList vs. List<>
- From: Jon Skeet [C# MVP]
- Re: ArrayList vs. List<>
- From: Jon Harrop
- Re: ArrayList vs. List<>
- From: Jon Skeet [C# MVP]
- Re: ArrayList vs. List<>
- From: Jon Harrop
- Re: ArrayList vs. List<>
- From: Jon Skeet [C# MVP]
- Re: ArrayList vs. List<>
- From: Jon Harrop
- ArrayList vs. List<>
- Prev by Date: Re: Paint Event - Wrong X and Y...
- Next by Date: Re: file transfer with sockets
- Previous by thread: Re: ArrayList vs. List<>
- Next by thread: Re: ArrayList vs. List<>
- Index(es):
Relevant Pages
|