FileOpen(1, TheFileName$, OpenMode.Binary, OpenAccess.Write)
FilePut(1, Drawings(DrawingIndex))
FileClose(1)
Where Drawings is a Structure and consists of other structures, arrays of arrays etc.
In VB.net this is almost 10 times SLOWER than the equivilant from VB6 In other words, the same basic read/write operations seem to take 10 times longer in VB.net than VB6. Is that right I mean, am I missing something Can I do something to improve speed
I tried using a file stream, but it does not seem to let me write a structure this way.
I broke the structure up wrote each value individually and it got slower.
Thanks,
Tom

File I/O speed in VB.NET vs VB6
dotnet4me2
Try using the classes in the system.io namespace instead save the data it much quicker. Why dont you try to serialize the class instead it much quicker.
http://msdn.microsoft.com/library/default.asp url=/library/en-us/cpref/html/frlrfsystemruntimeserializationformattersbinarybinaryformatterclassserializetopic.asp
Tel
For those interested here is what I did to replace the vb6 code (above):
Dim FileStream As New FileStream(TheFileName$, FileMode.Create) Dim formatter As New BinaryFormatter
formatter.Serialize(FileStream, Drawings(DrawingIndex))
FileStream.Close()
and ahead of the structure declare for the array Drawings put a:
<Serializable()> Structure DrawingType
Need this <Serializable()> declare ahead of all sub structures of drawings also.
Now I am reading/writing at similar speed to Vb6.
Tom
devjames82
I cannot speak for the perf differences between the VB6 File operations and .NET System.IO. However, in .NET, you really only have System.IO.FileStream at your disposal, unless you go through unmanaged interop.
Sub SerializeMyStructureTest()Here is a simple example of serializing a Structure using My.Computer.FileSystem, which uses FileStream under the covers. You may already have tried this approach, so my apologies up front if this is redundant for you.
<Serializable()> _
Structure MyStructure
Dim name As String
Dim age As Integer
End Structure
' Data to write out
Dim myStruct As MyStructure
myStruct.name = "john"
myStruct.age = 21
' Get a binary serializer and a memory stream. Serialize the structure
' to memory and then write all of the bytes out to a file.
Dim bin As New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter()
Dim stream As New System.IO.MemoryStream()
bin.Serialize(stream, myStruct)
My.Computer.FileSystem.WriteAllBytes("c:\test.data", stream.GetBuffer(), False)
' Read it back in to validate that it all worked
Dim bytes As Byte() = My.Computer.FileSystem.ReadAllBytes("c:\test.data")
myStruct = DirectCast(bin.Deserialize(New System.IO.MemoryStream(bytes)), MyStructure)
MsgBox(myStruct.name & " " & myStruct.age) End Sub
Joel Lyons
I've investigated a similar bug like this. The performance hit here is due to the conversion and calculating size of items in structures, multi-dimension arrays VB6 way. We could only improve the performance with single-dimension arrays.
As others have suggested, you should consider using the .NET Framework IO methods for this purpose.
Best regards,