Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

GetChunk, AppendChunk GOTCHA's

Posted on 1998-07-19
4
Medium Priority
?
502 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 600 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

670 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