Solved

GetChunk, AppendChunk GOTCHA's

Posted on 1998-07-19
4
493 Views
Last Modified: 2008-02-01
I am mucking about with saving and retrieving BLOB's from an Access database with AppendChunk and GetChunk. In the docs it describes using 32k chunks in a loop to fill a byte array. I have jumped the gun and just get the chunk in one large bite (1.4mb) to fill the array. This has worked fine. My question is what are the GOTCHA's, am I messing with something dangerous or if it works it works.
0
Comment
Question by:jarrahjack
  • 2
4 Comments
 
LVL 14

Expert Comment

by:waty
ID: 1466192
In previous version of VB, the max len of a string was 32k.

The way you fo is not the right way, because ready a byte array
has not enough performance.

Try using the following routine.


Sub GetFileFromDB(BinaryField As Field, szFileName As String)
    ' *** Will retrieve an entire Binary field and write it to disk ***
   
    Dim NumChunks    As Long
    Dim TotalSize    As Long
    Dim RemChunk     As Integer
    Dim CurSize      As Integer
    Dim nChunkSize   As Long
    Dim nI           As Integer
    Dim nFile        As Integer
    Dim CurChunk     As String
   
    nChunkSize = 32000    ' Set size of chunk.
   
    ' *** Get field size.
    TotalSize = BinaryField.FieldSize()
    NumChunks = TotalSize \ nChunkSize   ' Set number of chunks.
   
    ' *** Set number of remaining bytes.
    RemChunk = TotalSize Mod nChunkSize
   
    ' *** Set starting size of chunk.
    CurSize = nChunkSize
    nFile = FreeFile ' Get free file number.
   
    Open szFileName For Binary As #nFile  ' Open the file.
    For nI = 0 To NumChunks
       If nI = NumChunks Then CurSize = RemChunk
       CurChunk = BinaryField.GetChunk(nI * nChunkSize, CurSize)
       Debug.Print CurChunk
       Put #nFile, , CurChunk   ' Write chunk to file.
    Next
    Close nFile

End Sub

0
 

Author Comment

by:jarrahjack
ID: 1466193
Thanks for your answer, I know that it is what SHOULD be done. I am not writing to disk but to a byte array in memory which can then be manipulated. I am not really interested in performance. My concern was more of:- will there be a crash because of what I doing, ie. writing a large amount of data in one hit with appendchunk and ditto: reading with getchunk. It works fine on my machine with 64Mb of RAM.
0
 
LVL 9

Accepted Solution

by:
cymbolic earned 150 total points
ID: 1466194
I've done the same with millions of records in processing migrations, and it works fine in one gulp.  However, with very large blocks, you have two problems.  One is you can not release any time for background processing (user waits and wonders whether to cancel your app), and the other is potential memory/swapping problems on busier systems with less memory.  That is your app is more sensitive to low memory/resource environments.  But, hey, why not push Microsoft apps to the limit.  We all know how robust they are and how easy it is to get information and a fix from them when operating out of expected parameters, now don't we?
0
 

Author Comment

by:jarrahjack
ID: 1466195
Just as I thought. But one never knows with MSoft tra la, tra la
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now