Re: Roll your own std::vector ???




"Joanna Carter [TeamB]" <joanna@xxxxxxxxxxxx> wrote in message
news:eJ9oimiIHHA.1124@xxxxxxxxxxxxxxxxxxxxxxx
"Peter Olcott" <NoSpam@xxxxxxxxxxxxx> a écrit dans le message de news:
pVihh.19892$Rj.19203@xxxxxxxxxxxxxxx

| The commonly understood basic principle where an array name is
| one-and-the-same-thing as an array address.

In that case, that would appear to be the principle for all .NET types. The
variable that you see *is* the object that the variable points to. There is
no indirection on the surface, even though the underlying framework may
involve such.

I think the thing that you are having trouble with is this lack of
indirection; when it comes to C#, you need to try to forget about ->, & and
* and simply think of variables as being one and the same as the object
which they hold. For the sake of your comprehension, forget about pointers
and addresses :-)

One can't forget about this completely otherwise ones makes the mistake of
taking a shallow copy to be one-and-the-same-thing as a deep copy. I think that
..NET may have simplified this somewhat in some ways, I am currently not sure of
exactly how they did this. The way that this problem is typically simplified is
to always provide all of the overhead of a deep copy just in case that is what
was wanted.


| Yes that is what I was talking about, they are both pointers within the
| underlying architecture.

Maybe but that should not concern you; forget pointers :-)).

Yet then one must still wonder about the shallow versus deep copy problem, and
avoiding the overhead of the deep copy, when it is not needed. The best solution
at this point in time for applications programming might be to simply always do
a deep copy, and make doing a shallow copy syntactically impossible. There are
cases on systems programming where this would be unacceptable.


| > As I said in my previous post, the contents of value types are copied on
| > assignment, but those of reference types are simply "pointed to" by the
| > second reference.
|
| Array.Copy(ia, temp, ia.Length);
| ia = temp;
|
| So the last statement contains two reference types, even though the
underlying
| type of array element may be a value type or a reference type ???

Array is a reference type, regardless of the type that it holds. See Jon's
post as well.

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer




.



Relevant Pages

  • Re: Roll your own std::vector ???
    ... | The commonly understood basic principle where an array name is ... For the sake of your comprehension, forget about pointers ... but those of reference types are simply "pointed to" by the ... | type of array element may be a value type or a reference type ??? ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: arrays = pointers?
    ... pointers, but they don't want you to, because of the demons you can ... reference types by default have their ... reference which means it can replace the original array with another one. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Differance between Array and Pointers
    ... Well, except that arrays tend to be much larger than pointers, and the ... An array is a contiguous region of memory containing N elements of M ... indexing vs. a loop). ...
    (comp.arch.embedded)
  • [RFCv2][PATCH] flexible array implementation
    ... I call it a flexible array. ... storage for pointers to the second level. ... all locking must be provided by the caller. ... make sure to pass in &ptr instead of ptr. ...
    (Linux-Kernel)
  • [RFC][PATCH] flexible array implementation v4
    ... I call it a flexible array. ... so never does an order>0 allocation. ... storage for pointers to the second level. ... all locking must be provided by the caller. ...
    (Linux-Kernel)