Solved

GetChunk, AppendChunk GOTCHA's

Posted on 1998-07-19
4
497 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

808 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