Re: Function Declaration



Dennis,
| If I pass a structure byval that contains both reference and value types,
| what exactly am I passing
A structure is a value type, you are receiving a copy of all the values. If
the structure contains a String field, you get a copy of the reference to a
single copy of the String object on the heap.

| if I change a structure field in my function,
| is the structure field in the calling procedure changed also?
You are changing your copy of the structure values, not the original.

Hope this helps
Jay

"Dennis" <Dennis@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:30779613-D99E-4EEB-938E-777319F0666B@xxxxxxxxxxxxxxxx
| If I pass a structure byval that contains both reference and value types,
| what exactly am I passing and if I change a structure field in my
function,
| is the structure field in the calling procedure changed also?
| --
| Dennis in Houston
|
|
| "Jay B. Harlow [MVP - Outlook]" wrote:
|
| > Mike,
| > In addition to the other comments.
| >
| > I would define the function as:
| >
| > | Public Function CleanSomething(ByVal value As String) As String
| >
| > To help ensure the "fastest" possible function! Remember that ByVal &
ByRef
| > refer to how parameters are passed, while Reference Type & Value Type
refer
| > to how values are stored.
| >
| > ByVal passes a copy of the variable as the parameter.
| > ByRef passes a reference to the variable as the parameter.
| >
| > Reference Types exist on the heap, a variable holds a reference to the
| > actual object on the heap.
| > Value Types exist on the stack or nested inside another object, a
variable
| > holds the actual value.
| >
| >
| > String is a Reference type, which means that a String variable or
parameter
| > holds a reference to the actual string object on the Heap. If you pass a
| > String ByRef to a routine, you are passing a reference to the variable
that
| > holds a reference to the actual string object on the heap. In other
words a
| > reference to a reference to an object. If you pass a String ByVal you
| > passing the reference itself. In other words a reference to an object.
| >
| > I would expect ByRef String to be slightly slower as you are
dereferencing a
| > reference each time you want to access the String's value.
| >
| > When you define your function "As String" you are receiving a copy of
the
| > reference to the actual string object on the heap. There is only one
| > instance of the String on the heap.
| >
| > Hope this helps
| > Jay
| >
| > "Mike Labosh" <mlabosh@xxxxxxxxxxx> wrote in message
| > news:uHx7kbDeFHA.228@xxxxxxxxxxxxxxxxxxxxxxx
| > | >I would first suggest that you use a StringBuilder, rather than
Strings
| > for
| > | >heavy string manipulation.
| > |
| > | Actually, most of the stuff uses Regex's. But I do use StringBuilder
| > where
| > | I can. StringBuilder let me do one of our export batches in half the
time
| > | it used to take :):):)
| > |
| > | > Second, what is your function returning? If it returns a Reference
Type,
| > | > then you are only getting a copy of the pointer to the reference
type,
| > not
| > | > a copy of the reference type itself.
| > |
| > | Pretty much all the method prototypes in this class look like this:
| > |
| > | Public Function CleanSomething(ByRef value As String) As String
| > |
| > | There is one method that returns a Structure, also.
| > |
| > | I just want to make sure I'm returning the return value ByRef for
greater
| > | speed / efficiency.
| > |
| > | --
| > | Peace & happy computing,
| > |
| > | Mike Labosh, MCSD
| > |
| > | "Mr. McKittrick, after very careful consideration, I have
| > | come to the conclusion that this new system SUCKS."
| > | -- General Barringer, "War Games"
| > |
| > |
| >
| >
| >


.



Relevant Pages

  • Re: Abstract class variables question
    ... value can be anything (bool, int, string, etc). ... the heap and _objCurrent is just a pointer to that location. ... reference types, which means that all classes are allocated from the heap. ... As far as boxing and the heap go, I assumed it was a pointer to the heap ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: String Reference Type
    ... Therefore its always allocated in the heap and a variable of string type ... Dim y As String ... As with all classes in this case y and x both reference the same String ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Complex Specified Information - Pitman Formula
    ... Therefore a significant match between a reference and a test ... string is good evidence of non-random production. ... and there are no finite algorithms to compute their digits. ... probabilities of the different symbols the information source can produce. ...
    (talk.origins)
  • Re: Function Declaration
    ... >> | Public Function CleanSomething(ByVal value As String) As String ... >> refer to how parameters are passed, while Reference Type & Value Type ... >> ByRef passes a reference to the variable as the parameter. ... >> actual object on the heap. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: String Reference Type
    ... All unary and binary operators have predefined implementations that are ... Therefore its always allocated in the heap and a variable of string ... As with all classes in this case y and x both reference the same String ... language depandant matter as below. ...
    (microsoft.public.dotnet.framework.aspnet)