Re: String Reference Type

Tech-Archive recommends: Fix windows errors by optimizing your registry



Hi

No means no as in NO (false), then it should be true types. Sorry for my bad
spelling.

A data type of refernese type is not actually a value. It refers to a value.
A value type is actually a real value. A referense refers to or as in C
points to a value. In all programming languages I stumpled except one you
can have two types of parameters. Call by value or cal by referense. In
Basic you use "ByVal" for call by value and "ByRef" (i guess) for call by
referense. The only exception I know is Smalltalk that uses only referenses.
Every data in Smalltalk is dynamicly created.

As for the C++ code I mentioned gets more complicated when you deal with
classes.

See this example in C++ code. Note I'm not a VB programm only used it for a
small program back in 1998.

class TItem
{
private int& item;

// Default constructor
public TItem():
item( *new int; )
{}

// Copy contructor
public TItem( TItem& anInt ):
item( *new int(anInt); )
{}

public ~TItem() { delete *item; }

public int get() { return item; }
public void set( int anItem ) { item = anItem; }
}



// If you didnä't define the copy and default constructors above
// This function would fail to compile since it is call by value.
void aFunction( TItem item )
{
// CODE
}


Now having said this about C++ it is essential to know if all parameters in
C# is treated as referenses or if you can use both cal by value and call by
referense.




"RN1" <rn5a@xxxxxxxxxxxxxx> skrev i meddelandet
news:6bde7973-75f8-478d-9ed0-db864a9e317c@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On Feb 10, 4:38 am, "Jonathan Wood" <jw...@xxxxxxxxxxxxxxxx> wrote:
Lars,

No, Strings in Pascal (and ADA as I reacll) are tru types.

This appears to be to me but I don't know what "no" refers to, or what
"tru
types" are.

I could be wrong but it seems to me you are confusing terms. I'm not that
familiar with Delphi but a reference in C++ is different from a .NET
reference type. I don't know the exact criteria used to determine value or
reference type, but to me a reference type is a pointer, and so any type
that requires a pointer seems it would be a good candidate. And as far as
I'm concerned, all strings require pointers, whether they are made
available
to the language that uses them or not. (Certainly, it wouldn't make sense
to
ever store a string in a register or even on the stack.)

ANSI Pascal string at least the old ANSI pascal string type looks as follow

[YXXXXXXXX....XXX]

Where Y is a Byte giving 0..255 as the length of the string. X is caracters
all ANSI strings are arrays. In Delphi which is base on pascal I recall old
ansi Pascal string was replaced with ShortString or some thing. If you use
Delphi 2.0 or later the arrays for the caracters are as you say stored in
array that the string points to. It's been a while sine I dugg into the ANSI
defenitions for C++ but the only string type I know of in C++ is made of
template classes. Old C has no string type at all, hence the need for
pointers to awways.


Don't know about C# but I hope the compiler takes care of this. By
references or not is not of interest. What is of interest is if you have
the option to use call by value for strings or if all parameters are
treated as references. Can you use call by value in C# how do you use
call
by value?

I do know what call by referense and call by value is. What I don't know
(yet) is if C# can use both as C++ can. To me C# looks reminds me of both VB
and C++.


According tohttp://www.knowdotnet.com/articles/referencetypes2.html, "One
of the most common mistakes developers make when learning .NET is
confusing
Reference and Value Types with Passing values by Reference or Value."
Again,
I think you are confusing terms.

Read the page, good that the authour describes "Deep and Shallow Clones"
what I mentioned as Deep Copy or Shallow Copy. Some thing you learn when
studing basics in Object Oriented Program (OOP) as I did. Thet's when I
learned Smalltalk. If you use Delphi for example evey object of type class
that you pass in the parameter list is in fact a referense. The Deep Copy
versus Shallow copy of objects are not an easy thing to deal with. This can
mess up a lot for you if you don't know. Imagine if you uses a String class
that used Shallow Copy only. Setting

S2 = S1;
S1 = S3;

Would give the result that S1 and S2 had the same value as S3. As I
understand from the page you refered me to C# is doing a Deep Copy. If you
know OOP this should not be that hard to understand. If you don't know about
OOP then you need to study OOP and the problem with Deep Copy versus Shallow
Copy.

Good wuestion about the DIM variable.

In C/C++, Delphi the referense that points to DIM is owned by the functions.
Once you exit the function the reference varialbe dissapears.

The even better question is who owns the pbject you created and where is
that destroid. Does C# come with a garbadge collection like Java, Ada and
Smalltalk. This problem is the main problem OOP using C++ since you have to
destroy the objects you create. What happens when you destroy (delete []
object) and then still have a referense that points (refers) to the deleted
object. (Oooops)


When it comes to data types and algoritms there is really no differense
between a referense and a pointer. Basicly it's the same thing although C++
mess up this for you with the use of pointers. It has to to be backward
compatible with C. The referense types (int&) in C++ is the same as (int&).
The following classes is not the same whenit comes to copy contructors and
default constructors.

class X {
private
int* i;
}

class Y {
private
int& i;
}


X x1(1);
X x2;
Y y1(2);
Y y2

x1=x2; // OK

y1=y2; // Compiler error ,canät generate default and copy condtructors.


What is the similar for this in C#? Can this code be wxecuted i C#?


Lars




--
Jonathan Wood
SoftCircuits Programminghttp://www.softcircuits.com

OK...now suppose I have the following code:

<script runat="server">
Class MyInt
Public MyValue As Integer
End Class

Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs)
Dim x As New MyInt

...................
...................
...................
End Sub
</script>

If I am not wrong, the Dim line in the Page_Load sub "creates space in
the heap & returns a pointer (say, 0x000001)". To whom does the Dim
line return the pointer?

Please correct me if I am wrong.


.



Relevant Pages

  • Re: String Reference Type
    ... Then the C# String class works as the ANSI string it "should be". ... Doesn it invoke the Copyconstructor and default constructors as ... Why do you even care if the string is referense typeor value type. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Modify a .doc document with a macro without Word ?
    ... Const LL_ITEMPTR = 4 ' Pointer to the item ... Public Sub Add(Item As Variant, Optional Key As String, Optional Before As Variant, Optional After As Variant) ... Dim lpArray As Long ' Pointer to the first element of the array ... Dim lpItem As Long ' Pointer to the item ...
    (microsoft.public.scripting.vbscript)
  • Re: Passing a String as Pointer
    ... UBound' which seems correct as a string is being passed. ... UBound of a pointer may be. ... '* Normally Levenshtein edit distance is symmetric. ... Dim above As Integer, left As Integer, diag As Integer, cell As ...
    (microsoft.public.word.vba.general)
  • Re: Pointers in vb6
    ... then mszReaders is converted to a pointer to a byte ... ByVal lpString1 As String, ByVal lpString2 As Long) As Long ... Dim hContext As Long ...
    (microsoft.public.pocketpc.developer)
  • Re: Fallbeispiel1, VB6 - VB.NET
    ... Private Function concat2As String ... Dim i As Integer, r As Integer, c As Integer ... tb = LeftB$(Buffer, Pointer - 1) ...
    (microsoft.public.de.vb)