Home All Groups Group Topic Archive Search About

Structure vs Class Objects

Author
2 Apr 2006 6:01 AM
Dennis
If I have a structure like;

Public Structure myStructureDef
     Public b() as Byte
     Public t as String
End Structure

If I pass this structure, will the values in the array b be stored on the
stack or will just a pointer to the array be stored on the stack?  I am
trying to decide whether to use Structures or Pointers.  I know that M'soft
recommends to use a class if the length is over about 16 bytes but does this
include all the array elements or just pointers to the array?
--
Dennis in Houston

Author
2 Apr 2006 12:29 PM
Kevin Westhead
Arrays and strings are both reference types, so they'll be allocated on the
GC heap. I think the 16 byte rule is just one guideline aimed at getting you
to consider whether you really want value type or reference type semantics.
E.g. if you pass myStructureDef to a method, you'll be passing a copy, which
includes a copy of the array and the string. If you assign one instance to
another, again you'll be assigning a copy rather than having both instances
reference the same data. If you find yourself passing myStructureDef
arguments ByRef alot then you should really consider using a reference type
instead. You should also think about how often myStructureDef will be boxed
in your core scenarios.

--
Kevin Westhead

Show quoteHide quote
"Dennis" <Den***@discussions.microsoft.com> wrote in message
news:15C18853-DA91-4CB9-ABC9-7C6D760D5594@microsoft.com...
> If I have a structure like;
>
> Public Structure myStructureDef
>     Public b() as Byte
>     Public t as String
> End Structure
>
> If I pass this structure, will the values in the array b be stored on the
> stack or will just a pointer to the array be stored on the stack?  I am
> trying to decide whether to use Structures or Pointers.  I know that
> M'soft
> recommends to use a class if the length is over about 16 bytes but does
> this
> include all the array elements or just pointers to the array?
> --
> Dennis in Houston
Author
2 Apr 2006 1:40 PM
OHM ( One Handed Man )
A reasoned response.

--
( OHM ) - One Handed Man
AKA Terry Burns - http://TrainingOn.net

Show quoteHide quote
"Kevin Westhead" <mapson.mapson@nospam.nospam> wrote in message
news:uzBiLElVGHA.2208@TK2MSFTNGP15.phx.gbl...
> Arrays and strings are both reference types, so they'll be allocated on
> the GC heap. I think the 16 byte rule is just one guideline aimed at
> getting you to consider whether you really want value type or reference
> type semantics. E.g. if you pass myStructureDef to a method, you'll be
> passing a copy, which includes a copy of the array and the string. If you
> assign one instance to another, again you'll be assigning a copy rather
> than having both instances reference the same data. If you find yourself
> passing myStructureDef arguments ByRef alot then you should really
> consider using a reference type instead. You should also think about how
> often myStructureDef will be boxed in your core scenarios.
>
> --
> Kevin Westhead
>
> "Dennis" <Den***@discussions.microsoft.com> wrote in message
> news:15C18853-DA91-4CB9-ABC9-7C6D760D5594@microsoft.com...
>> If I have a structure like;
>>
>> Public Structure myStructureDef
>>     Public b() as Byte
>>     Public t as String
>> End Structure
>>
>> If I pass this structure, will the values in the array b be stored on the
>> stack or will just a pointer to the array be stored on the stack?  I am
>> trying to decide whether to use Structures or Pointers.  I know that
>> M'soft
>> recommends to use a class if the length is over about 16 bytes but does
>> this
>> include all the array elements or just pointers to the array?
>> --
>> Dennis in Houston
>
>
Author
2 Apr 2006 2:14 PM
Dennis
Thanks for your clarification.  Since I'm using very large arrays, I think I
will use Classses to avoid eating up memory even though I will have to make
several changes in my application.
--
Dennis in Houston


Show quoteHide quote
"Kevin Westhead" wrote:

> Arrays and strings are both reference types, so they'll be allocated on the
> GC heap. I think the 16 byte rule is just one guideline aimed at getting you
> to consider whether you really want value type or reference type semantics.
> E.g. if you pass myStructureDef to a method, you'll be passing a copy, which
> includes a copy of the array and the string. If you assign one instance to
> another, again you'll be assigning a copy rather than having both instances
> reference the same data. If you find yourself passing myStructureDef
> arguments ByRef alot then you should really consider using a reference type
> instead. You should also think about how often myStructureDef will be boxed
> in your core scenarios.
>
> --
> Kevin Westhead
>
> "Dennis" <Den***@discussions.microsoft.com> wrote in message
> news:15C18853-DA91-4CB9-ABC9-7C6D760D5594@microsoft.com...
> > If I have a structure like;
> >
> > Public Structure myStructureDef
> >     Public b() as Byte
> >     Public t as String
> > End Structure
> >
> > If I pass this structure, will the values in the array b be stored on the
> > stack or will just a pointer to the array be stored on the stack?  I am
> > trying to decide whether to use Structures or Pointers.  I know that
> > M'soft
> > recommends to use a class if the length is over about 16 bytes but does
> > this
> > include all the array elements or just pointers to the array?
> > --
> > Dennis in Houston
>
>
>
Author
2 Apr 2006 4:33 PM
Jay B. Harlow [MVP - Outlook]
Kevin,
| E.g. if you pass myStructureDef to a method, you'll be passing a copy,
which
| includes a copy of the array and the string.
As you stated, Arrays & Strings are reference types. The myStructureDef
structure contains a reference to the actual objects on the heap. Not a copy
of the actual object!

If you pass myStructureDef to a method you will be passing a copy of the
structure, which includes a copy of the *references* to the array & the
string objects.  There will only be a single instance of the array & string
object on the heap!

Because Strings are immutable its hard to notice a difference. However
Arrays & most other reference types are mutable, consider the following:

    Public Structure myStructureDef
        Public i As Integer
        Public b() As Byte
        Public t As String
    End Structure

    Private Sub Something(ByVal parameter As myStructureDef)
        parameter.i = 2
        parameter.b(0) = 5
        parameter.b(1) = 6
        parameter.b(2) = 7
    End Sub

        Dim local As myStructureDef
        local.b = New Byte() {1, 2, 3}
        local.t = "Hello"
        Something(local)

"parameter" will be a copy of the "local" myStructureDef, parameter.i is
inline in the structure as its a value type, so changing parameter.i does
not change local.i. However the array that parameter.b references is the
same array that local.b references, so changing an element of the array
"parameter.b(0) = 5" also changes "local.i". However changing the reference
itself, will change the reference itself "parameter.b = New Byte() {4, 5,
6}" will create a new array object on the heap, replacing the reference that
"parameter.b" is...


--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


Show quoteHide quote
"Kevin Westhead" <mapson.mapson@nospam.nospam> wrote in message
news:uzBiLElVGHA.2208@TK2MSFTNGP15.phx.gbl...
| Arrays and strings are both reference types, so they'll be allocated on
the
| GC heap. I think the 16 byte rule is just one guideline aimed at getting
you
| to consider whether you really want value type or reference type
semantics.
| E.g. if you pass myStructureDef to a method, you'll be passing a copy,
which
| includes a copy of the array and the string. If you assign one instance to
| another, again you'll be assigning a copy rather than having both
instances
| reference the same data. If you find yourself passing myStructureDef
| arguments ByRef alot then you should really consider using a reference
type
| instead. You should also think about how often myStructureDef will be
boxed
| in your core scenarios.
|
| --
| Kevin Westhead
|
| "Dennis" <Den***@discussions.microsoft.com> wrote in message
| news:15C18853-DA91-4CB9-ABC9-7C6D760D5594@microsoft.com...
| > If I have a structure like;
| >
| > Public Structure myStructureDef
| >     Public b() as Byte
| >     Public t as String
| > End Structure
| >
| > If I pass this structure, will the values in the array b be stored on
the
| > stack or will just a pointer to the array be stored on the stack?  I am
| > trying to decide whether to use Structures or Pointers.  I know that
| > M'soft
| > recommends to use a class if the length is over about 16 bytes but does
| > this
| > include all the array elements or just pointers to the array?
| > --
| > Dennis in Houston
|
|
Author
2 Apr 2006 7:03 PM
Jay B. Harlow [MVP - Outlook]
Doh! typo

| However the array that parameter.b references is the
| same array that local.b references, so changing an element of the array
| "parameter.b(0) = 5" also changes "local.i".

Should be:

    "parameter.b(0) = 5" also changes "local.b(0)".

--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


Show quoteHide quote
"Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_***@tsbradley.net> wrote in
message news:%23IjauMnVGHA.4740@TK2MSFTNGP14.phx.gbl...
| Kevin,
|| E.g. if you pass myStructureDef to a method, you'll be passing a copy,
| which
|| includes a copy of the array and the string.
| As you stated, Arrays & Strings are reference types. The myStructureDef
| structure contains a reference to the actual objects on the heap. Not a
copy
| of the actual object!
|
| If you pass myStructureDef to a method you will be passing a copy of the
| structure, which includes a copy of the *references* to the array & the
| string objects.  There will only be a single instance of the array &
string
| object on the heap!
|
| Because Strings are immutable its hard to notice a difference. However
| Arrays & most other reference types are mutable, consider the following:
|
|    Public Structure myStructureDef
|        Public i As Integer
|        Public b() As Byte
|        Public t As String
|    End Structure
|
|    Private Sub Something(ByVal parameter As myStructureDef)
|        parameter.i = 2
|        parameter.b(0) = 5
|        parameter.b(1) = 6
|        parameter.b(2) = 7
|    End Sub
|
|        Dim local As myStructureDef
|        local.b = New Byte() {1, 2, 3}
|        local.t = "Hello"
|        Something(local)
|
| "parameter" will be a copy of the "local" myStructureDef, parameter.i is
| inline in the structure as its a value type, so changing parameter.i does
| not change local.i. However the array that parameter.b references is the
| same array that local.b references, so changing an element of the array
| "parameter.b(0) = 5" also changes "local.i". However changing the
reference
| itself, will change the reference itself "parameter.b = New Byte() {4, 5,
| 6}" will create a new array object on the heap, replacing the reference
that
| "parameter.b" is...
|
|
| --
| Hope this helps
| Jay [MVP - Outlook]
| .NET Application Architect, Enthusiast, & Evangelist
| T.S. Bradley - http://www.tsbradley.net
|
|
| "Kevin Westhead" <mapson.mapson@nospam.nospam> wrote in message
| news:uzBiLElVGHA.2208@TK2MSFTNGP15.phx.gbl...
|| Arrays and strings are both reference types, so they'll be allocated on
| the
|| GC heap. I think the 16 byte rule is just one guideline aimed at getting
| you
|| to consider whether you really want value type or reference type
| semantics.
|| E.g. if you pass myStructureDef to a method, you'll be passing a copy,
| which
|| includes a copy of the array and the string. If you assign one instance
to
|| another, again you'll be assigning a copy rather than having both
| instances
|| reference the same data. If you find yourself passing myStructureDef
|| arguments ByRef alot then you should really consider using a reference
| type
|| instead. You should also think about how often myStructureDef will be
| boxed
|| in your core scenarios.
||
|| --
|| Kevin Westhead
||
|| "Dennis" <Den***@discussions.microsoft.com> wrote in message
|| news:15C18853-DA91-4CB9-ABC9-7C6D760D5594@microsoft.com...
|| > If I have a structure like;
|| >
|| > Public Structure myStructureDef
|| >     Public b() as Byte
|| >     Public t as String
|| > End Structure
|| >
|| > If I pass this structure, will the values in the array b be stored on
| the
|| > stack or will just a pointer to the array be stored on the stack?  I am
|| > trying to decide whether to use Structures or Pointers.  I know that
|| > M'soft
|| > recommends to use a class if the length is over about 16 bytes but does
|| > this
|| > include all the array elements or just pointers to the array?
|| > --
|| > Dennis in Houston
||
||
|
|
Author
2 Apr 2006 8:37 PM
Dennis
Kevin,Jay - as a test, I did the following:

'In my Main Program
Public Structure myStruct
    Public b As Byte()
    Public s As String
End Structure
Dim st As myStruct
ReDim st.b(3)
st.b(0) = 1 : st.b(1) = 2 : st.b(2) = 3
st.s = "Original String"
Something(st)
'Break here and check values of st which were, st.s=Original String,
st.b(0)=25, st.b(1)=30, st.b(2)=35

Private Sub Something(ByVal c() As Byte)
   st.s = "New String"
   st.b(0) = 25: st.b(1) = 30: st.b(2) = 35
End Sub

It is obvious that that only a reference to the array object is stored in
the structure and that is what is passed.  Of course the string wasn't
changed since it's immutable (whatever that means).
--
Dennis in Houston


Show quoteHide quote
"Jay B. Harlow [MVP - Outlook]" wrote:

> Doh! typo
>
> | However the array that parameter.b references is the
> | same array that local.b references, so changing an element of the array
> | "parameter.b(0) = 5" also changes "local.i".
>
> Should be:
>
>     "parameter.b(0) = 5" also changes "local.b(0)".
>
> --
> Hope this helps
> Jay [MVP - Outlook]
> ..NET Application Architect, Enthusiast, & Evangelist
> T.S. Bradley - http://www.tsbradley.net
>
>
> "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_***@tsbradley.net> wrote in
> message news:%23IjauMnVGHA.4740@TK2MSFTNGP14.phx.gbl...
> | Kevin,
> || E.g. if you pass myStructureDef to a method, you'll be passing a copy,
> | which
> || includes a copy of the array and the string.
> | As you stated, Arrays & Strings are reference types. The myStructureDef
> | structure contains a reference to the actual objects on the heap. Not a
> copy
> | of the actual object!
> |
> | If you pass myStructureDef to a method you will be passing a copy of the
> | structure, which includes a copy of the *references* to the array & the
> | string objects.  There will only be a single instance of the array &
> string
> | object on the heap!
> |
> | Because Strings are immutable its hard to notice a difference. However
> | Arrays & most other reference types are mutable, consider the following:
> |
> |    Public Structure myStructureDef
> |        Public i As Integer
> |        Public b() As Byte
> |        Public t As String
> |    End Structure
> |
> |    Private Sub Something(ByVal parameter As myStructureDef)
> |        parameter.i = 2
> |        parameter.b(0) = 5
> |        parameter.b(1) = 6
> |        parameter.b(2) = 7
> |    End Sub
> |
> |        Dim local As myStructureDef
> |        local.b = New Byte() {1, 2, 3}
> |        local.t = "Hello"
> |        Something(local)
> |
> | "parameter" will be a copy of the "local" myStructureDef, parameter.i is
> | inline in the structure as its a value type, so changing parameter.i does
> | not change local.i. However the array that parameter.b references is the
> | same array that local.b references, so changing an element of the array
> | "parameter.b(0) = 5" also changes "local.i". However changing the
> reference
> | itself, will change the reference itself "parameter.b = New Byte() {4, 5,
> | 6}" will create a new array object on the heap, replacing the reference
> that
> | "parameter.b" is...
> |
> |
> | --
> | Hope this helps
> | Jay [MVP - Outlook]
> | .NET Application Architect, Enthusiast, & Evangelist
> | T.S. Bradley - http://www.tsbradley.net
> |
> |
> | "Kevin Westhead" <mapson.mapson@nospam.nospam> wrote in message
> | news:uzBiLElVGHA.2208@TK2MSFTNGP15.phx.gbl...
> || Arrays and strings are both reference types, so they'll be allocated on
> | the
> || GC heap. I think the 16 byte rule is just one guideline aimed at getting
> | you
> || to consider whether you really want value type or reference type
> | semantics.
> || E.g. if you pass myStructureDef to a method, you'll be passing a copy,
> | which
> || includes a copy of the array and the string. If you assign one instance
> to
> || another, again you'll be assigning a copy rather than having both
> | instances
> || reference the same data. If you find yourself passing myStructureDef
> || arguments ByRef alot then you should really consider using a reference
> | type
> || instead. You should also think about how often myStructureDef will be
> | boxed
> || in your core scenarios.
> ||
> || --
> || Kevin Westhead
> ||
> || "Dennis" <Den***@discussions.microsoft.com> wrote in message
> || news:15C18853-DA91-4CB9-ABC9-7C6D760D5594@microsoft.com...
> || > If I have a structure like;
> || >
> || > Public Structure myStructureDef
> || >     Public b() as Byte
> || >     Public t as String
> || > End Structure
> || >
> || > If I pass this structure, will the values in the array b be stored on
> | the
> || > stack or will just a pointer to the array be stored on the stack?  I am
> || > trying to decide whether to use Structures or Pointers.  I know that
> || > M'soft
> || > recommends to use a class if the length is over about 16 bytes but does
> || > this
> || > include all the array elements or just pointers to the array?
> || > --
> || > Dennis in Houston
> ||
> ||
> |
> |
>
>
>
Author
3 Apr 2006 1:00 AM
Jay B. Harlow [MVP - Outlook]
Dennis,
| It is obvious that that only a reference to the array object is stored in
| the structure and that is what is passed.
Yes! I believe that is what I stated.

| Of course the string wasn't
| changed since it's immutable (whatever that means).
You changed a reference to the string, you did not change the string.

Immutable means that the object itself is unchangeable (not modifiable).

--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


Show quoteHide quote
"Dennis" <Den***@discussions.microsoft.com> wrote in message
news:62E7D637-2565-4503-AE71-D4C74A68E69C@microsoft.com...
| Kevin,Jay - as a test, I did the following:
|
| 'In my Main Program
| Public Structure myStruct
|    Public b As Byte()
|    Public s As String
| End Structure
| Dim st As myStruct
| ReDim st.b(3)
| st.b(0) = 1 : st.b(1) = 2 : st.b(2) = 3
| st.s = "Original String"
| Something(st)
| 'Break here and check values of st which were, st.s=Original String,
| st.b(0)=25, st.b(1)=30, st.b(2)=35
|
| Private Sub Something(ByVal c() As Byte)
|   st.s = "New String"
|   st.b(0) = 25: st.b(1) = 30: st.b(2) = 35
| End Sub
|
| It is obvious that that only a reference to the array object is stored in
| the structure and that is what is passed.  Of course the string wasn't
| changed since it's immutable (whatever that means).
| --
| Dennis in Houston
|
|
| "Jay B. Harlow [MVP - Outlook]" wrote:
|
| > Doh! typo
| >
| > | However the array that parameter.b references is the
| > | same array that local.b references, so changing an element of the
array
| > | "parameter.b(0) = 5" also changes "local.i".
| >
| > Should be:
| >
| >     "parameter.b(0) = 5" also changes "local.b(0)".
| >
| > --
| > Hope this helps
| > Jay [MVP - Outlook]
| > ..NET Application Architect, Enthusiast, & Evangelist
| > T.S. Bradley - http://www.tsbradley.net
| >
| >
| > "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_***@tsbradley.net> wrote in
| > message news:%23IjauMnVGHA.4740@TK2MSFTNGP14.phx.gbl...
| > | Kevin,
| > || E.g. if you pass myStructureDef to a method, you'll be passing a
copy,
| > | which
| > || includes a copy of the array and the string.
| > | As you stated, Arrays & Strings are reference types. The
myStructureDef
| > | structure contains a reference to the actual objects on the heap. Not
a
| > copy
| > | of the actual object!
| > |
| > | If you pass myStructureDef to a method you will be passing a copy of
the
| > | structure, which includes a copy of the *references* to the array &
the
| > | string objects.  There will only be a single instance of the array &
| > string
| > | object on the heap!
| > |
| > | Because Strings are immutable its hard to notice a difference. However
| > | Arrays & most other reference types are mutable, consider the
following:
| > |
| > |    Public Structure myStructureDef
| > |        Public i As Integer
| > |        Public b() As Byte
| > |        Public t As String
| > |    End Structure
| > |
| > |    Private Sub Something(ByVal parameter As myStructureDef)
| > |        parameter.i = 2
| > |        parameter.b(0) = 5
| > |        parameter.b(1) = 6
| > |        parameter.b(2) = 7
| > |    End Sub
| > |
| > |        Dim local As myStructureDef
| > |        local.b = New Byte() {1, 2, 3}
| > |        local.t = "Hello"
| > |        Something(local)
| > |
| > | "parameter" will be a copy of the "local" myStructureDef, parameter.i
is
| > | inline in the structure as its a value type, so changing parameter.i
does
| > | not change local.i. However the array that parameter.b references is
the
| > | same array that local.b references, so changing an element of the
array
| > | "parameter.b(0) = 5" also changes "local.i". However changing the
| > reference
| > | itself, will change the reference itself "parameter.b = New Byte() {4,
5,
| > | 6}" will create a new array object on the heap, replacing the
reference
| > that
| > | "parameter.b" is...
| > |
| > |
| > | --
| > | Hope this helps
| > | Jay [MVP - Outlook]
| > | .NET Application Architect, Enthusiast, & Evangelist
| > | T.S. Bradley - http://www.tsbradley.net
| > |
| > |
| > | "Kevin Westhead" <mapson.mapson@nospam.nospam> wrote in message
| > | news:uzBiLElVGHA.2208@TK2MSFTNGP15.phx.gbl...
| > || Arrays and strings are both reference types, so they'll be allocated
on
| > | the
| > || GC heap. I think the 16 byte rule is just one guideline aimed at
getting
| > | you
| > || to consider whether you really want value type or reference type
| > | semantics.
| > || E.g. if you pass myStructureDef to a method, you'll be passing a
copy,
| > | which
| > || includes a copy of the array and the string. If you assign one
instance
| > to
| > || another, again you'll be assigning a copy rather than having both
| > | instances
| > || reference the same data. If you find yourself passing myStructureDef
| > || arguments ByRef alot then you should really consider using a
reference
| > | type
| > || instead. You should also think about how often myStructureDef will be
| > | boxed
| > || in your core scenarios.
| > ||
| > || --
| > || Kevin Westhead
| > ||
| > || "Dennis" <Den***@discussions.microsoft.com> wrote in message
| > || news:15C18853-DA91-4CB9-ABC9-7C6D760D5594@microsoft.com...
| > || > If I have a structure like;
| > || >
| > || > Public Structure myStructureDef
| > || >     Public b() as Byte
| > || >     Public t as String
| > || > End Structure
| > || >
| > || > If I pass this structure, will the values in the array b be stored
on
| > | the
| > || > stack or will just a pointer to the array be stored on the stack?
I am
| > || > trying to decide whether to use Structures or Pointers.  I know
that
| > || > M'soft
| > || > recommends to use a class if the length is over about 16 bytes but
does
| > || > this
| > || > include all the array elements or just pointers to the array?
| > || > --
| > || > Dennis in Houston
| > ||
| > ||
| > |
| > |
| >
| >
| >
Author
2 Apr 2006 4:45 PM
AMercer
> E.g. if you pass myStructureDef to a method, you'll be passing a copy, which
> includes a copy of the array and the string. If you assign one instance to
> another, again you'll be assigning a copy rather than having both instances
> reference the same data.

What?  I agree that if you pass a myStructureDef to a method, you will pass
a copy of the structure, but it will contain a copy of a reference to b.  A
new reference to b will be created, not a new copy of the entire array b as
is imiplied by your phrase "which includes a copy of the array and the
string".  Similarly, if you assign one instance of myStructureDef to another,
you will have two references to the same b array.

Consider this:

  Public Sub Test(ByVal z As myStructureDef)
    z.b(1) = CByte(z.b(1) + 1)
    z.t &= "x"
  End Sub

      Dim z, w As myStructureDef
      ReDim z.b(3)
      z.t = "aaa"
      Test(z)
      w = z
      Test(z)

At the end of these operations, z.b(1) and w.b(1) are both 2 because both z
and w refer to the same array object.  On the other hand, because strings are
immutable, and becuase z was passed by value to Test(), z.t and w.t are both
their original value, namely "aaa".  Change the sub to byref, and the
behavior of b() will be unchanged, but the behavior of t will be different.
Author
2 Apr 2006 2:28 PM
Cor Ligthert [MVP]
Dennis,

Is thinking about 16 Bytes really from this time.

Cor

Show quoteHide quote
"Dennis" <Den***@discussions.microsoft.com> schreef in bericht
news:15C18853-DA91-4CB9-ABC9-7C6D760D5594@microsoft.com...
> If I have a structure like;
>
> Public Structure myStructureDef
>     Public b() as Byte
>     Public t as String
> End Structure
>
> If I pass this structure, will the values in the array b be stored on the
> stack or will just a pointer to the array be stored on the stack?  I am
> trying to decide whether to use Structures or Pointers.  I know that
> M'soft
> recommends to use a class if the length is over about 16 bytes but does
> this
> include all the array elements or just pointers to the array?
> --
> Dennis in Houston
Author
2 Apr 2006 4:43 PM
Herfried K. Wagner [MVP]
"Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> schrieb:
> Is thinking about 16 Bytes really from this time.

It's a Microsoft recommendation that definitely makes sense.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
2 Apr 2006 4:56 PM
Cor Ligthert [MVP]
Herfried,
>
> It's a Microsoft recommendation that definitely makes sense.
>
Do you have a real world example for me?
(With as it is possible the advantages in figers of whole seconds and parts
of 1Mb memory.)

All figurs below this quantaties has no sense because I can also not have
influence if the framework 2.1 will be not 1Mb larger than the current
version.

Cor
Author
2 Apr 2006 6:22 PM
Herfried K. Wagner [MVP]
"Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> schrieb:
>> It's a Microsoft recommendation that definitely makes sense.
>
> Do you have a real world example for me?

Sorry, but there must be a set of criteria to base the decision whether to
use classes or structures on.  Otherwise some people would only use
structures and others would never use structures.  In other words, that's
the reason why 'Point' is a structure and 'Form' isn't.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
2 Apr 2006 7:01 PM
Cor Ligthert [MVP]
Herfried,

All decisions should be seen for me in relation to the time that they were
taken.

I can only see this as a reason if it should be used on computers with a
very low amount of memory. Than it is for me a valid criteria.

Just my thought,

Cor


Show quoteHide quote
"Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> schreef in bericht
news:uc1xwJoVGHA.5408@TK2MSFTNGP10.phx.gbl...
> "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> schrieb:
>>> It's a Microsoft recommendation that definitely makes sense.
>>
>> Do you have a real world example for me?
>
> Sorry, but there must be a set of criteria to base the decision whether to
> use classes or structures on.  Otherwise some people would only use
> structures and others would never use structures.  In other words, that's
> the reason why 'Point' is a structure and 'Form' isn't.
>
> --
> M S   Herfried K. Wagner
> M V P  <URL:http://dotnet.mvps.org/>
> V B   <URL:http://classicvb.org/petition/>
Author
3 Apr 2006 12:42 AM
Michael D. Ober
Point has a direct counterpart in the Win32 API.  Making it a structure
parallels the Win32 API.

From the Windows GDI SDK:

POINT

The POINT structure defines the x- and y- coordinates of a point.
typedef struct tagPOINT {
  LONG x;
  LONG y;
} POINT, *PPOINT;

Members
x     Specifies the x-coordinate of the point.
y     Specifies the y-coordinate of the point.

Requirements
  Windows NT/2000/XP: Included in Windows NT 3.1 and later.
  Windows 95/98/Me: Included in Windows 95 and later.
  Header: Declared in Windef.h; include Windows.h.


Mike Ober.

Show quoteHide quote
"Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
news:uc1xwJoVGHA.5408@TK2MSFTNGP10.phx.gbl...
> "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> schrieb:
> >> It's a Microsoft recommendation that definitely makes sense.
> >
> > Do you have a real world example for me?
>
> Sorry, but there must be a set of criteria to base the decision whether to
> use classes or structures on.  Otherwise some people would only use
> structures and others would never use structures.  In other words, that's
> the reason why 'Point' is a structure and 'Form' isn't.
>
> --
>  M S   Herfried K. Wagner
> M V P  <URL:http://dotnet.mvps.org/>
>  V B   <URL:http://classicvb.org/petition/>
>
>