Jump to content

Recommended Posts

Posted (edited)

hi all,

Basically I need your advice on some programming issues. I have class called Create_Packet which takes in values from the Main Form. The information is a mix of three Integers, a Byte array(The byte array has a string stored in it) and a Long. Is there a way that i could take all these values and store them in an object(or what ever would be best) and place it in a Queue once its removed from the queue, read back the information in another class called Read_Packet? If it would be possible for the other class to read the information back, how would it retrieve the information, any examples would go a long way

(Please bear in mind im just getting into programming now so if an object is what should be used here, please let me know why)

Any help would be most welcome

Edited by phiban

Posted

An even better approach would be to create a struct of the data you want to store, then create a generic list of that struct, essentially creating an arraylist that's typed to a custom struct.

Posted

yeah i was under the impression that a struct was the way to due to the diffrent data types, how would i make a generic list. Also just for my information, how will the other class Read_Packet be able to extract the diffrent data types?

Posted

I'd just allocate a byte array and use pointers of various types, pointing to different locations within the array, to read the data. This is the most flexible approach, as structs, which seem to be encouraged much for this type of work, fail for strings of variable length, data that can be in different formats depending on other values in the array, etc.

Posted

jcarle was right on. I must disagree with LLXX though, pointers go against the entire idea of managed code and OOP.

A structure is the way to go because your data type has no functionality, no methods, etc. IE: Other objects use this data, this data doesn't do anything on its own.

Your structure should look something like this.

Public Structure PacketData
Public IntegerOne as Integer
Public IntegerTwo as Integer
Public IntegerThree as Integer
Public StringBytes as Byte()
Public OtherNumber as Long
End Structure

Warning: I'm a C# guy myself, so some of this syntax may be a tad bit off.

If you are using .Net 2.0 you can use a System.Collections.Generic.Queue(Of PacketData) to strongly type your queue (See jcarle's post). So to get a set of data out of the queue, would could simply go:

Dim ReadData as PacketData = MyQueue.Dequeue()

If you are still using 1.0 or 1.1 you would need to use a System.Collections.Queue and cast the object from the Dequeue method back to PacketData like"

Dim ReadData as PacketeData = CType(MyQueue.Dequeue(), PacketData)

Posted (edited)
I must disagree with LLXX though, pointers go against the entire idea of managed code and OOP.
Have fun trying to parse varying-format data efficiently :lol:

First example I can think of is TCP/IP packet header/trailers. Some fields are there, some are not, depending on other fields (which themselves may not be present and are dependent on bits in other fields, etc.)

Edited by LLXX

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...