473,408 Members | 1,861 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

VB.NET Really Slow Filestream

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
Next

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.

Thank you
Dec 12 '07 #1
5 2334
Plater
7,872 Expert 4TB
It's doing a file seek. Which means it is going through and reading every byte on it's way to that location.
You might have better luck with a native API call, but I doubt it.
200mb is a pretty big file, 30seconds to scan through the whole thing sounds pretty fast to me.
Dec 12 '07 #2
Well, then how do people manage to search through files faster than that?
Dec 12 '07 #3
Plater
7,872 Expert 4TB
Well, then how do people manage to search through files faster than that?
The API Calls might be faster (or maybe there's a better way in .NET) but not as a Stream object I don't think.

Who scans files faster then that?
Dec 12 '07 #4
Well, a Database works a whole lot faster than that...

How is that possible?

(Keep in mind that my Database knowledge is pretty low, I'm trying to do things on my own without using SQL or Access or stuff like that)
Dec 12 '07 #5
Shashi Sadasivan
1,435 Expert 1GB
Databases use data structures like B+ trees.
They help in indexing/locating records/data.
Currently the only sort of structure that you have is that each record is barely a line (hopefully on a certain length only) and hence you have to go through each line.
To simplify your search you would have to change the way you look for files.
Either create an index, or you could create multiple files and based on certain condition you would need to only access certain files
Dec 12 '07 #6

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

Similar topics

9
by: Tom | last post by:
I am working with the this object as oppose to the StreamReader object becuase I need to access a file (to find the contents) while an external application is updating the file. When I was...
13
by: Stuart | last post by:
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...
4
by: Marty | last post by:
Hi, I use a streamwriter object to write in a text files hundreds time per seconds. When my file get very big, can this process is subject to slow down my application? Here is part of my...
7
by: Nathan Sokalski | last post by:
I am having a problem saving an image with the same name it originally had. I have two similar versions of my code, one in which I close the FileStream used to open the original image before saving,...
5
by: Eric Cadwell | last post by:
Is there a faster way to write the last 100K of a large file? This code takes almost two minutes to run on my machine. int buffer = 100000; int length = 2000000000; string file =...
5
by: rony_16 | last post by:
Hi, I have a problem downloading a file . after i connect to the website and get the stream , i treing to write the file on the HD. public void SaveStreamToFile(string filePath, Stream stream) {...
1
by: fcharby | last post by:
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...
8
by: =?Utf-8?B?RnJhbms=?= | last post by:
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...
10
by: cellus205 | last post by:
Hows it going everyone. Im still pretty new to vb .net, and am having a little trouble. I am loading a tab delimited txt file into an access database, and parsing the text to extract some of the...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.