Visual Basic Development Bookmark and Share   
 Home > Visual Basic Interop and Upgrade > Does the declare of arrays in structure are correct ?
 

Does the declare of arrays in structure are correct ?

Does the declare of arrays in structure are correct ? ?
Has it other better solution ? instead of using redim for multi-arrays type in structure?


Public Class Form_Main

Public Structure hiddenneuron
Public ot, da As Single ' ot - output, da - delta
Public bs, dbs, ubs As Single ' bs - bias, dbs - dbias, ubs - bias update value
Public wt(), dwt(), uwt() As Single ' wt - weight, dwt - dweight, uwt - weight update value
Public er, per As Single ' er - error, per - preious error
Public se(), pse() As Single ' se - slope, pse - preious slope
End Structure

' net elements
Public il() As inputneuron ' il - input layer
Public hl(,) As hiddenneuron ' hl - hidden layer
Public ol() As outputneuron ' ol - output layer
Public ot() As Single ' ot - desire output
Public Const maxlayer As Integer = 3 ' maxium hidden layer
Public lsize As Integer ' number of hidden layer

Public Sub init_gobal()
isize = 2 ' test
hsize(0) = 2 ' test
osize = 1 ' test - should be reading from config file

lsize = 0
For l = 0 To maxlayer - 1
If hsize(l) > 0 Then lsize += 1
Next

ReDim il(isize - 1)
ReDim ol(osize - 1)
ReDim ot(osize - 1)

For l = 0 To lsize - 1
ReDim hl(l, hsize(l) - 1)
If l = 0 Then
wsize = isize - 1
Else
wsize = hsize(l - 1) - 1
End If
For n = 0 To hsize(l) - 1
ReDim hl(l, n).wt(wsize)
ReDim hl(l, n).dwt(wsize)
ReDim hl(l, n).uwt(wsize)
ReDim hl(l, n).se(wsize)
ReDim hl(l, n).pse(wsize)
Next
Next

wsize = hsize(lsize - 1) - 1
For n = 0 To osize - 1
ReDim ol(n).wt(wsize)
ReDim ol(n).dwt(wsize)
ReDim ol(n).uwt(wsize)
ReDim ol(n).se(wsize)
ReDim ol(n).pse(wsize)
Next
End Sub
End Class
ksw1973  Wednesday, October 28, 2009 1:47 PM
Hi ,

Using array in Structure is one correct usage. Please have a look at the following article about some tricks between structures and classes.
http://msdn.microsoft.com/en-us/library/aa289521(VS.71).aspx

Array Elements: Because an array is a reference type, its elements are all allocated on the heap, whether they are value or reference types. However, an array of value types is allocated contiguously, which improves locality of reference and reduces the risk of processor cache misses. Consequently, there is a preference for structures over classes as array elements.

You can also read this article about Collections Best Practices.
http://msdn.microsoft.com/en-us/magazine/cc163377.aspx


Best regards,
Riquel
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
Riquel_Dong  Monday, November 02, 2009 9:00 AM
Hi ,

Using array in Structure is one correct usage. Please have a look at the following article about some tricks between structures and classes.
http://msdn.microsoft.com/en-us/library/aa289521(VS.71).aspx

Array Elements: Because an array is a reference type, its elements are all allocated on the heap, whether they are value or reference types. However, an array of value types is allocated contiguously, which improves locality of reference and reduces the risk of processor cache misses. Consequently, there is a preference for structures over classes as array elements.

You can also read this article about Collections Best Practices.
http://msdn.microsoft.com/en-us/magazine/cc163377.aspx


Best regards,
Riquel
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
Riquel_Dong  Monday, November 02, 2009 9:00 AM

You can use google to search for other answers

Custom Search

More Threads

• install the database
• VB.Net / VB6 / Win32 API Problems
• Problem with MsgBox - incorrect return value
• As Any equivalent
• Interop Forms Toolkit: support for ownerform argument for Show()????
• Interop.Access: Report: Retrieving values of the properties of the controls of an existing MSAccess report
• converted vb 6.0 data environment
• I want to debug a dll created in VS 2005 from application created in VS 6.0
• calling vb.net class library from vb 6.0
• Loading symbols for microsoft.interopformstools.dll.....slow