By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,646 Members | 2,105 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,646 IT Pros & Developers. It's quick & easy.

Really slow filestream

P: 6
Hello all, I'm new here and I've searched a lot before posting my question, but I can't seem to find a solution to my problem.

I'm working on a database program that I created myself, I created my own file format and I store information about clients in there. So far, so good, but when I try to search the content of my file, that's where it becomes slow....I try to check if a byte is > than 0 in every client's profile....there are 100 000 clients and the file size is about 200mb.

It goes something like this....

Dim objFile As New System.IO.FileStream("Clients.pcf", IO.FileMode.Open)

For i = 0 To 99999
If Results(i) Then
objFile.Position = (Jump * i) + position
If objFile.ReadByte() > 0 Then
Results(i) = False
End If
End If

Results() is an array of Bool and is used to indicate if the client matches what I'm looking for. It is used several times by different Subs.
Jump indicates the length of each client's profile in bytes.
Position indicates where the information is located within the client's profile.

My computer is old (1gHz), but still, a task like that takes almost 30 seconds...I found out that this line slows everything down: objFile.Position = (Jump * i) + position, but a multiplication is not supposed to take that long (I've tried it separately) and if I click a second time on the button that handles that event, it takes less that a second to get my results....

I've even looked at the CPU usage and it goes up only for the second....what's happening? Is VB copying my file somewhere?

I must say that I'm more that confused right now....I'm sorry if this is a long post, but it's a pretty complex situation and I would appreciate every suggestion.
Dec 12 '07 #1
Share this Question
Share on Google+
1 Reply

Expert 5K+
P: 8,434
It's not the multiplication that would be taking the time, but repositioning the file pointer.

A couple of thoughts come to mind.
  • If you can spare the RAM, you might save heaps of time by loading the entire file into an array.
  • I think you'll find that the filestream is designed for flexibility, not speed. You can probably improve performance considerably by using good old-fashioned Binary mode. That is...
    Open "MyFile" For Binary Access Read Write Lock Write As #1
    Positioning is very quick in binary mode.
Dec 13 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.