Visual Basic >
Visual Basic Forums
>
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
Answers
- 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.- Marked As Answer byRiquel_DongModeratorWednesday, November 04, 2009 11:03 AM
All Replies
- 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.- Marked As Answer byRiquel_DongModeratorWednesday, November 04, 2009 11:03 AM


