Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Pro VB 6
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Pro VB 6 For advanced Visual Basic coders working in version 6 (not .NET). Beginning-level questions will be redirected to other forums, including Beginning VB 6.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old July 2nd, 2007, 05:14 PM
Friend of Wrox
 
Join Date: Nov 2004
Location: Port Orchard, WA, USA.
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default Treating Memory as a File

I have a routine that concatenates 700+ records onto a string. Of course, this is a way to make a routine really slow, since each concatenation requires writing the entire string to a new string.

To overcome this, I used the FileSystemObject and a TextStream. I write each piece of data that would have been concatenated to a file instead. At the end of the routine I read the whole file back into a string.

It occured to me (since .NET allows using memory as a stream) that there might be a way to write this to RAM instead, but handle that RAM as if it were a file.

Suggestions?
Reply With Quote
  #2 (permalink)  
Old July 2nd, 2007, 05:51 PM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

but you are using vb6?
because what you did is a great idea...maybe using an xml file (that's is loaded into the memory) would do the trick to????

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
Reply With Quote
  #3 (permalink)  
Old July 2nd, 2007, 05:58 PM
Friend of Wrox
 
Join Date: Nov 2004
Location: Port Orchard, WA, USA.
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

I am using VB6.

Sometimes .NET additional functionality is a wrapper for previously existing APIs, sometimes new functionality created by the .NET team.

Figured the question was at least worth a shot. (I seem to recall reading in a VB6 book some cute tricks for handling memory as a file...)
Reply With Quote
  #4 (permalink)  
Old July 2nd, 2007, 06:07 PM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

I think i have some info at work.. but now I'm at home :( i will be back to this if I found some info (be back at work on wendsday)...

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
Reply With Quote
  #5 (permalink)  
Old July 5th, 2007, 11:50 AM
Friend of Wrox
 
Join Date: Nov 2004
Location: Port Orchard, WA, USA.
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

The API process that was niggling at the periphery of my mind was file mapping. Unfortunately, this is the opposite of what I want to do.

It seems to me that if you want to use memory in the way that I have used a file up to now, and you did not know in advance how much room you needed, then what you would have to do is essentially set up a routine to handle memory at a low level in the way that the Internal Drive Electronics handles the disc surface. You would need to establish a protocol for handling blocks of memory as sectors are handled on the disc. You would need each sector to hold info on where the next sector it so be found.

When you needed more room, you would need to allocate a block, anchor it, then fill in the previous block with the info on where this new block is to be found. Essentially you would need to set up a linked list in RAM. (You would not need to implement a "Memory Allocation Table" to duplicate the FAT though.)

Then you would need a process to "walk the list" retrieving the data when you wanted to utilize those data.

Finally, you would need a process to free up the memory when you were no longer using it.

If you created all this, it could be really handy to use. But that's a lot of work...

Still and all, eagerly awaiting what you find at work!
Reply With Quote
  #6 (permalink)  
Old July 5th, 2007, 12:04 PM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there...

let's see.. I have this old application called api-guide.. unfortunately the web site doesn't exist any more (got deprecated when .net comes alive).. but it have almost all api calls there, and a lot has examples..

I can send you this app. (2.2 mb installer only)...

you can find there apis like:
Declare Function lstrcpy Lib "kernel32" Alias "lstrcpyA" (ByVal lpString1 As String, ByVal lpString2 As String) As Long

The lstrcpy function copies a string to a buffer.

· lpString1
Points to a buffer to receive the contents of the string pointed to by the lpString2 parameter. The buffer must be large enough to contain the string, including the terminating null character.

· lpString2
Points to the null-terminated string to be copied.

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
Reply With Quote
  #7 (permalink)  
Old July 27th, 2007, 02:27 PM
Friend of Wrox
 
Join Date: Nov 2004
Location: Port Orchard, WA, USA.
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Here’s what I wound up doing. Astonishingly fast. On a par with using the file system until the size gets really big.
Code:
Option Explicit
Option Base 0       ' Mandates that arrays’ LBound() = 0

Private arStrs()    As String   ' Array of strings.  Each concatenation 
                                ' puts ‘Text’ arg into a new element of 
                                ' this array.
Private curSz       As Long     ' Points to the element to receive
                                ' the Text of a Concatenation.
Private maxSz       As Long     ' Current count of elements 
                                ' in array.  Reading a var is faster than 
                                ' UBound().
Private delta       As Long     ' Number of new, empty strings to add to 
                                ' the array when class has run out of room.
Private NoLongerNew As Boolean  ' False until something is added to the 
                                ' internal data.

Private Sub Class_Initialize()
    maxSz = 100
    If delta = 0 Then delta = 50    ' ChunkSize might have been changed.  
                                    'Want to set delta only
                                    ' when this routine is called automa-
                                    ' tically by the class
    ReDim arStrs(maxSz - 1)         ' actually being initialized.
End Sub

Public Property Let ChunkSize(Value As Long)

    If Value < 1 Then _
        Err.Raise vbObjectError + 2, _
                  "clsStringBuilder_array", _
                  "ChunkSize cannot be less than 1."

    delta = Value

End Property

Public Property Get ChunkSize() As Long
    ChunkSize = delta
End Property

Public Property Let InitialSize(Value As Long)

    If Value < 1 Then _
        Err.Raise vbObjectError + 2, _
                  "clsStringBuilder_array", _
                  "InitialSize cannot be less than 1."

    If NoLongerNew Then _
        Err.Raise vbObjectError + 1, _
                  "clsStringBuilder", _
                  "The object already has data.  Cannot initialize."

    maxSz = Value
    ReDim arStr(maxSz - 1)  ' No Preserve required.

End Property

Public Sub Add(Text As String)

    If (curSz + 1) > maxSz Then
        maxSz = maxSz + delta
        ReDim Preserve arStrs(maxSz - 1)
    End If

    arStrs(curSz) = Text
    curSz = (curSz + 1)

    NoLongerNew = True

End Sub

Public Property Get Text() As String
    Text = Join(arStrs)
End Property

Public Sub Clear()
    NoLongerNew = False
    Class_Initialize  ' Re-initialize the object
End Sub
If you know in advance how many additions you will be making, you can pre-size the array, vastly improving the speed in some cases. If you know that there will not be a lot of addition, you can reduce the chunk size, which sets the additional allocation size when the array gets full. This too can improve performance—and you can have your program decide what initial size and chunksize to use.

In my class module, I made .Text the default property.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Memory akkad C# 0 January 9th, 2007 10:01 AM
xml file in client memory Sakubar Sathik XML 0 April 6th, 2006 05:04 AM
Out of Memory ocabrera70 Classic ASP Components 0 February 15th, 2006 09:08 PM
Out of memory : simplyAns All Other Wrox Books 0 November 9th, 2004 08:56 AM
Memory linguva Access 2 December 19th, 2003 07:22 PM



All times are GMT -4. The time now is 01:40 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.