473,396 Members | 2,158 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

The old Structure/Class Argument

I recently wrote a VB.NET application using VS2005. I needed to be able
to build linked lists in memory of items that were represented by a
group of variables. For example,

Friend Structure foo
Dim var1 As String
Dim var2 As Integer
Dim var3 As Boolean
End Structure

I needed several structures, each with a different mix of number of
members and the datatypes. Now, these structures could have been
implemented as classes. But I do not know how multiple instances of a
class can be linked together so I can process them in a standard For
Each/Next loop.

I see one guideline of whether to use a Class or a Structure is if the
Structure is less or equal to 16 bytes. Several of these structures
will be larger than that, so I am open to converting the code to use
classes instead of structures if someone can give me some pointers on
how to link instances of a class together.

TIA,

Jan 13 '06 #1
6 1165
Use a collection

Tom

za***@construction-imaging.com wrote:
I recently wrote a VB.NET application using VS2005. I needed to be able
to build linked lists in memory of items that were represented by a
group of variables. For example,

Friend Structure foo
Dim var1 As String
Dim var2 As Integer
Dim var3 As Boolean
End Structure

I needed several structures, each with a different mix of number of
members and the datatypes. Now, these structures could have been
implemented as classes. But I do not know how multiple instances of a
class can be linked together so I can process them in a standard For
Each/Next loop.

I see one guideline of whether to use a Class or a Structure is if the
Structure is less or equal to 16 bytes. Several of these structures
will be larger than that, so I am open to converting the code to use
classes instead of structures if someone can give me some pointers on
how to link instances of a class together.

TIA,

Jan 13 '06 #2

Well if i see your structure i would say just leave it as a structure as it
would only hurt the performance of your app to convert this to a class

Basically, classes are reference types and structs are value types.
Reference types get stored differently than value types. Value types are
stored more efficiently on the stack vs classes on the heap using structures
will also save the GC some trips :-) as it does not need to reclaim memory
want to know in detail when to use a class or when to use a structure ???

watch this video
http://msdn.microsoft.com/netframewo...ichtypesystem/
regards

Michel Posseth [MCP]

<za***@construction-imaging.com> schreef in bericht
news:11**********************@o13g2000cwo.googlegr oups.com...
I recently wrote a VB.NET application using VS2005. I needed to be able
to build linked lists in memory of items that were represented by a
group of variables. For example,

Friend Structure foo
Dim var1 As String
Dim var2 As Integer
Dim var3 As Boolean
End Structure

I needed several structures, each with a different mix of number of
members and the datatypes. Now, these structures could have been
implemented as classes. But I do not know how multiple instances of a
class can be linked together so I can process them in a standard For
Each/Next loop.

I see one guideline of whether to use a Class or a Structure is if the
Structure is less or equal to 16 bytes. Several of these structures
will be larger than that, so I am open to converting the code to use
classes instead of structures if someone can give me some pointers on
how to link instances of a class together.

TIA,

Jan 13 '06 #3
I am. A collection of structures.

Sorry, I forgot to mention that.

I would prefer to use multiple instances of a class to emulate a
collection but I can't figure out how to link the multiple instances.

Jan 13 '06 #4
Zacks,

I assume that you a List wants of those.

http://msdn2.microsoft.com/en-us/lib...us,VS.80).aspx

Although that I never use a structure and would use a class
\\\
Friend Structure foo
Dim var1 As String
Dim var2 As Integer
Dim var3 As Boolean
End Structure
Private mylist As New List(Of foo)
///
I hope this helps,

Cor
Jan 13 '06 #5
Is a List better than a Collection?

You mention that you would use a class, but in your example code you
used a structure. Can you:

Class foo
<define each member of the former structure as a property>
End Structure
Private mylist As New List(Of foo)

(Thanks for the pointer to the new List class, anyway. I will research
it)

Jan 13 '06 #6
>
You mention that you would use a class, but in your example code you
used a structure. (To integrate your sample)

Can you:
Class foo
<define each member of the former structure as a property>
End Structure
Private mylist As New List(Of foo)

(Thanks for the pointer to the new List class, anyway. I will research
it)


Yes, Yes (however not end structure but end class) see the link I gave
there is very much information.

I hope this helps,

Cor
Jan 13 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Yoramo | last post by:
hello I'm calling Win32 API methods like "SendMessage" in this method there are the lParam & wParam parameters, sometimes I need to pass a structure address in the lParam or wParam. the only...
26
by: Brett | last post by:
I have created a structure with five fields. I then create an array of this type of structure and place the structure into an array element. Say index one. I want to assign a value to field3 of...
3
by: Steve | last post by:
Hello, I created a public Structure in a Standard Module and also an array of Structures. Then I load data into the array of structures in a public sub that I call on the Form load event. ...
4
by: Dave Cullen | last post by:
I want to call a function using my own data type as an argument. The declaration for my function looks like this: Public Function CreateCardInfo(ByVal data As WoData) VB.NET balks at this,...
10
by: David Fort | last post by:
Hi, I'm upgrading a VB6 app to VB.net and I'm having a problem with a call to a function provided in a DLL. The function takes the address of a structure which it will fill in with values. I...
8
by: SP | last post by:
The following code crashes after I add the two nested FOR loops at the end, I am starting to learn about pointers and would like to understand what I'm doing wrong. I think the problem is the way...
4
by: gordon | last post by:
Hi I am still fairly new to C#.net and I sometimes make basic program design mistakes - particularyly in the context of paying attention to OOP principles. At the moment I am working on an...
17
by: Jason Doucette | last post by:
I am converting a C-style unit into a C++ class. I have an implementation function that was defined in the .cpp file (so it was hidden from the interface that exists in the .h file). It uses a...
4
by: eBob.com | last post by:
In my class which contains the code for my worker thread I have ... Public MustInherit Class Base_Miner #Region " Delegates for accessing main UI form " Delegate Sub DelegAddProgressBar(ByVal...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.