Solved

GetChunk, AppendChunk GOTCHA's

Posted on 1998-07-19
4
499 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

752 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