Random Access files - slow

  • Thread starter Thread starter Stuart
  • Start date Start date
S

Stuart

I have converted a VB6 app to VB.NET. It's function is to generate
reports from a Random Access file but the .NET version is pathetically
slow compared to the VB6 version.

I think I need to to get the FileStream class to work with Random Access
Files, but it requires the data Structures to be in a byte array. How
do I convert them?

S.
 
Hi Stuart,

Do you have Option Strict On in top of your program, maybe it is slow
because of the late binding.

I would try to set that if it is not..

Cor
 
Cor said:
Hi Stuart,

Do you have Option Strict On in top of your program, maybe it is slow
because of the late binding.

I would try to set that if it is not..

Cor

Option Strict is off.

I have read that you shouldn't use VB's "FileOpen" method to access
files, and use the System.IO.Stream.... class instead, as it's much
faster. I have used FileStream where I can, but I can't get Random
Access files to work with it, due to the Byte Array requirement.

A report I run in my vb6 app takes 11 seconds. In .Net it's talking 51
seconds!

S.
 
Hi Stuart,

Why not set option Strict on and look what castings you have to add.

Probably you get a much higher performance.

Cor
 
Cor said:
Hi Stuart,

Why not set option Strict on and look what castings you have to add.

Probably you get a much higher performance.

Cor

Doesn't anyone use Random Access files anymore? They are a great way to
store large volumes of fixed length data. Very fast in VB6, QuickBasic,
and Powerbasic. But in .Net it seems to be hopelessly slow. 463% slower
in my case!

S.
 
Did you set option strict on as I asked?

A lot of things are with option strict off much slower so that can be
normal.

Cor
 
Cor said:
Did you set option strict on as I asked?


I tried switching it on, but it won't compile on the FileGet

FileGet(FileCh, MyStructure, MyPointer)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

VB complains at every element of the structure. Yet of I switch off
Option Strict, it compiles, and runs.

Thanks,
Stuart.
 
Stuart said:
I tried switching it on, but it won't compile on the FileGet

FileGet(FileCh, MyStructure, MyPointer)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

VB complains at every element of the structure.

Do you know the reason why it complains?
Yet of I switch off
Option Strict, it compiles, and runs.

Yes, did you wonder why it runs? What is done in the background if it runs?
This may slow down your code.


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
Do you know the reason why it complains?


For each element of my structure, it says something like

Value of type cannot be converted to Double
Value of type cannot be converted to Integer
etc....

Yes, did you wonder why it runs? What is done in the background if it runs?
This may slow down your code.


I take your point. But what do you convert a structure too to satisfy
the compiler?

Stuart.
 
Hi Stuart,

That is the trouble, you have to cast it give it in advance the right type
and not let it find that out at runtime everytime the code uses it.

We agree that that what I now am writting should be standard or a kind of
automatic word processing, but it is not, but I have heard that they intent
to do this in the next version of VB.net.

When it says it has to be a string, you mostly can add after it .ToString
When it say it has to be a double you can set before it Cdbl(xxx)
When it says it has to be a Integer you can set before it Cint(xxxx)

When it is a reference type and it is the same type of object you mostly can
do
directcast (x, y) as sample a textbox derives from controls, and therefore
you can say
directcast (x, textbox).lines when you know that the object you get is a
textbox.

I hope this helps a little bit?

Cor
 
Stuart said:
For each element of my structure, it says something like

Value of type cannot be converted to Double
Value of type cannot be converted to Integer
etc....




I take your point. But what do you convert a structure too to
satisfy the compiler?


Ok, I got it now. With Option strict off, you can pass the structure object
but you would get an exception if a different type would be returned. Option
Strict On prevents you from getting this error at run time.

The other thing is that VB won't return the wrong object, but the compiler
can not know this.

If you enable option strict, you'd have to read each structure member on
your own. Maybe in this case you could put the fileget statement into a
Class/Module that has "option strict off" at it's top (I can't believe I
write this....but this seems to be an exception of the rule), so option
strict is limited to the module and does not affect the whole project.
 
Hi Armin,
If you enable option strict, you'd have to read each structure member on
your own. Maybe in this case you could put the fileget statement into a
Class/Module that has "option strict off" at it's top (I can't believe I
write this....but this seems to be an exception of the rule), so option
strict is limited to the module and does not affect the whole project.


I think that is not the good approach, I will real advice you Armin to set
always Option Strict On in your programs.

This is not for you Stuart, you can do what Armin say, for the time beeing
it is a solution.

Cor
 
Back
Top