Skip to main content

Past Blast

Featured Products

Windows Mobile Developer Controls
Windows Mobile Developer Controls
Stay in touch using the DEVBUSS RSS feeds.
 

News

Windows Mobile Developer Controls
Windows Mobile Developer Controls

Size Matters!

Written by Dwayne Lamb  [author's bio]  [read 34007 times]
Edited by Derek

Page 1  Page 2  Page 3 

Public Sub BackupAndStrip()
'Triggered by 1st button
Dim i As Integer
Dim fso As New FileSystemObject
Dim OrigFile As File
Dim Origts As TextStream
Dim Newts As TextStream
Dim LineStr As String
Dim TrimLine As String
Dim FirstChar As String

'Back up each file first
For i = 1 To 10
FileCopy Files(i), AppPath & BackDir & JustFileName(Files(i))
Next i


'Then strip out unwanted lines and leading spaces
'from each file into a new file
For i = 1 To 10
Set OrigFile = fso.GetFile(Ffiles(i))
Set Origts = OrigFile.OpenAsTextStream(ForReading)
Set Newts = fso.CreateTextFile(FPath & "tmp", True, False)
While Not Origts.AtEndOfStream
LineStr = Origts.ReadLine
TrimLine = Trim(LineStr)
FirstChar = Left(TrimLine, 1)
If FirstChar <> "'" And FirstChar <> "" Then
'Add the trimmed line of code to the new file
Newts.WriteLine (TrimLine)
End If
Wend
Next i
End Sub

Public Function JustFileName(PathStr As String) As String
Dim FNameLen As Integer
FNameLen = Len(PathStr) - InStrRev(PathStr, "\")
JustFileName = Right(PathStr, FNameLen)
End Function

Public Sub ReplaceOrig()
'Triggered by 2nd button
'Use this routine to copy the new stripped files
'into your development environment
Dim i
For i = 1 To 10
FileCopy Files(i) & "tmp", Files(i)
Next i
End Sub

Public Sub RestoreBackup()
'Triggered by 3rd button
'Use this routine to copy the files you backed up
'back to your development environment
Dim i As Integer

For i = 1 To 10
FileCopy AppPath & BackDir & JustFileName(Files(i)), Files(i)
Next i
End Sub

Add these routines to a form with three buttons and you have yourself a stripper. Make sure you modify the file array to contain the actual file names from your project and be the right size for the number of files you are using. From that point on, you can give your stripper whatever features you so choose.

Remember to close the project or the eVB IDE and reopen before you strip and be careful about when you save your files and where.

I personally didn't build a front end that would select the project file and then read the frm and bas files from it, etc. I simply hard coded the file names into an array and hard coded the appropriate directory paths in where needed. I leave it as an exercise for the reader to make a more versatile interface and decide how far they want to strip. Naturally, I take no responsibility for your code if you use these routines or information described in this article.

I mentioned I also did some code profiling. Because size and speed are probably important to you when developing applications for devices like the Pocket PC with limited storage and processing power, I recommend that you give a few code analyzers and a performance profilers a test-drive to see what they can do. In my quest to speed up the players in Morris, I was asking around about these tools and an associate suggested I try Project Analyzer and VB Watch from Aivosto at http://www.aivosto.com/. In minutes after running their Project Analyzer, I was able to identify the dead wood in my code and easily remove unused procedures and variables. This obviously is another way to ultimately reduce the size of your distributed vb file. It took a little longer (but not much) to set up and interpret their VB Watch add-in for VB 6. This performance profiler product allowed me to quickly pinpoint the five procedures that were doing the most work when my application was running. I used three simple techniques to modify those five procedures. I flattened the logic inside some, for others I changed them to inline code. In one case I pre-calculated and cached the values in an array instead of continuously calculating them on the fly. I was able to quickly bring down the time it took for my computer players to make their moves to times that I am now very happy with.

The pregnant pauses are gone and Morris is now about 100 KB slimmer. The most important lesson learned from all of this is to make sure that you Backup and Strip. Perhaps Microsoft will release a service patch that incorporates the necessary logic into the compiler ** or ** maybe they will give us a .NET version of VB for the Pocket PC platform and we won't care anymore.

The thread that started this whole exercise also contained a number of known performance issues that related to eVB but exploring that topic is beyond the scope of this article. I hope that someone with more experience in eVB and embedded devices will give that topic the attention it deserves. A detailed list of sluggish eVB and Pocket PC calls structures and coding techniques would make optimizing eVB code easier.

If you are interested in downloading Morris you can find him in all three common processor versions on www.handango.com or www.pocketgear.com.

Morris at Handango

** Update 24 Sep 2001 **

Besides the sample code provided with the article I later created a small utility for those who do not have the time or interest in building their own utility to remove the waste space from their eVB project files. If you would prefer to save time and effort by using this utility you can find it at either of the following two links or from links from our web site at http://www.visualbyte.com.

PocketGear

Handango

Previous Page