473,386 Members | 1,790 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,386 software developers and data experts.

file parsing algorithms in vb.net?

Hello!

Maybe someone is able to give me a little hint on this:
I've written a vb.net app which is mainly an interpreter for specialized
CAD/CAM files.
These files mainly contain simple movement and drawing instructions like
"move to's" and "change color's" optionally followed by one or more numeric
(int or float) arguments. My problem is that the parsing algorithm I've
currently implemented is extremely slow.

Basically I'm aproaching these files as follows:

Read 2 bytes from disk and check if these bytes match any known command.
This is done in a large Select Case-statement (about 30 "cases").
If this statement finds a "move to" command, for example, then I'm trying to
extract the arguments.
Please see the following code extract:

Do While ((IsNumeric(strThisChar)) Or (strThisChar = ",") Or _
(strThisChar =".") Or (strThisChar = "-") Or (strThisChar = " "))

If ((IsNumeric(strThisChar)) Or (strThisChar = ".") Or _
(strThisChar = "-")) Then
' this character belongs to the current argument

If ((Len(aryValues(lValueIdx)) = 0) And (strThisChar = ".")) Then

aryValues(lValueIdx) = "0"

strThisChar = "," ' Workaround: this value will become float

End If

aryValues(lValueIdx) += strThisChar ' Here I'm simply concentrating the
values

strThisChar = m_HPGLFile.ReadChar ' this is my input filestream

Else ' finished one argument

lValueIdx += 1

ReDim Preserve aryValues(lValueIdx)

strThisChar = m_HPGLFile.ReadChar

End If

Loop

As you can see, I'm building an array with all arguments that are following
the command.
How would you code such a file parsing algorithm? I strongly believe that my
extensive Select Case-statement and the "argument reader" shown above are my
main bottlenecks. These functions are called thousands of times during file
parsing...

Any hints would be greatly appreciated ;-)

Greetings,
Christoph Bisping
Nov 20 '05 #1
1 2427
Christoph,
One thing I would suggest is that you do *not* read bytes, parse them,
read bytes, parse them, etc.
It would probably speed up your code tremendously to read the entire
file into memory (a collection or array of bytes or something else),
*then* close the file and parse the data you've already read into
memory. All those file access might be costing you a lot of performance,
and you really shouldn't leave files open for any longer than absolutely
necessary.

Christoph Bisping wrote:
Hello!

Maybe someone is able to give me a little hint on this:
I've written a vb.net app which is mainly an interpreter for specialized
CAD/CAM files.
These files mainly contain simple movement and drawing instructions like
"move to's" and "change color's" optionally followed by one or more numeric
(int or float) arguments. My problem is that the parsing algorithm I've
currently implemented is extremely slow.

Basically I'm aproaching these files as follows:

Read 2 bytes from disk and check if these bytes match any known command.
This is done in a large Select Case-statement (about 30 "cases").
If this statement finds a "move to" command, for example, then I'm trying to
extract the arguments.
Please see the following code extract:

Do While ((IsNumeric(strThisChar)) Or (strThisChar = ",") Or _
(strThisChar =".") Or (strThisChar = "-") Or (strThisChar = " "))

If ((IsNumeric(strThisChar)) Or (strThisChar = ".") Or _
(strThisChar = "-")) Then
' this character belongs to the current argument

If ((Len(aryValues(lValueIdx)) = 0) And (strThisChar = ".")) Then

aryValues(lValueIdx) = "0"

strThisChar = "," ' Workaround: this value will become float

End If

aryValues(lValueIdx) += strThisChar ' Here I'm simply concentrating the
values

strThisChar = m_HPGLFile.ReadChar ' this is my input filestream

Else ' finished one argument

lValueIdx += 1

ReDim Preserve aryValues(lValueIdx)

strThisChar = m_HPGLFile.ReadChar

End If

Loop

As you can see, I'm building an array with all arguments that are following
the command.
How would you code such a file parsing algorithm? I strongly believe that my
extensive Select Case-statement and the "argument reader" shown above are my
main bottlenecks. These functions are called thousands of times during file
parsing...

Any hints would be greatly appreciated ;-)

Greetings,
Christoph Bisping


--
================================================== ================
Sam J. Marrocco
Sr. Visual Effects Artist/R&D
Travelling Pictures/GTN
Inferno, Flame, Maya, All that cool stuff!
"The fact that no one understands you doesn't make you an artist."
================================================== ================

Nov 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

26
by: Chris Lasher | last post by:
Hello, I have a rather large (100+ MB) FASTA file from which I need to access records in a random order. The FASTA format is a standard format for storing molecular biological sequences. Each...
5
by: SROSeaner | last post by:
I have a text file that is the result of using XMLHTTP object to pull back a page of search results from a search engine. So I have the entire results page in HTML, and want to break out each hit...
2
by: Cigdem | last post by:
Hello, I am trying to parse the XML files that the user selects(XML files are on anoher OS400 system called "wkdis3"). But i am permenantly getting that error: Directory0: \\wkdis3\ROOT\home...
2
by: Sean Bartholomew | last post by:
i am trying to parse.....: ifstream newFans ("/Volumes/iBook Apps/Users/me/Library/Mail/POP-blaha@blah.blah.com/INBOX.mbox/mbox", ios::in|ios::binary|ios::ate); so that i could create a tab...
1
by: Stork via DotNetMonster.com | last post by:
Hi, Just a little background info, I am working on a WinForms program that allows users to have an eletronic version of my catalog, since while they are actually looking at peices they need...
8
by: Jean-Marie Vaneskahian | last post by:
Reading - Parsing Records From An LDAP LDIF File In .Net? I am in need of a .Net class that will allow for the parsing of a LDAP LDIF file. An LDIF file is the standard format for representing...
9
by: cabrenner | last post by:
I am new to SQL Server, and migrating part of an Access application to SSE. I am trying to insert a comma delimited file into SSE 2005. I am able to run a BULK INSERT statement on a simple file,...
5
AdrianH
by: AdrianH | last post by:
Assumptions I am assuming that you know or are capable of looking up the functions I am to describe here and have some remedial understanding of C++ programming. FYI Although I have called...
1
AdrianH
by: AdrianH | last post by:
Assumptions I am assuming that you know or are capable of looking up the functions I am to describe here and have some remedial understanding of C programming. FYI Although I have called this...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...

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.