Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: PowerBuilder
Expertise: Beginner
May 29, 1997

Max file size PB can open

Question:
I need to develop a program interfaced with a Sybase database. First I have to open a huge ASCII file (size ranges from 20 to 100 MB) to read and convert it to a preformatted ASCII file for the database.

Can PB open such a large ASCII file if my PC has 32 MB of memory? If so, how?

Answer:
The size of the file makes no difference to PowerBuilder, because it reads only 32K chunks at a time. Obviously if you read the whole file in 32K chunks and tried to store them in memory as one continuous block, you'd have problems.

Assuming your data has some kind of structure to it, you can read the data in 32K chunks and process as much of the first chunk as possible, then append the next chunk to the end of what's left of the chunk, and continue until you process the whole file.

The following code will read a large file into a blob variable. I suggest that instead of concatenating the chunks into the blob, you perform only the processing you need to do.

integer fnum, loops, i
long flen, bytes_read, new_pos
blob b, tot_b

// Set a wait cursor
SetPointer(HourGlass!)

// Get the file length, and open the file
flen = FileLength(sle_filename.Text)
fnum = FileOpen(sle_filename.Text,  &
	StreamMode!, Read!, LockRead!)

// Determine how many times to call FileRead 
IF flen > 32765 THEN
   IF Mod(flen, 32765) = 0 THEN
      loops = flen/32765
   ELSE
      loops = (flen/32765) + 1
   END IF
ELSE
   loops = 1
END IF

// Read the file
new_pos = 1
FOR i = 1 to loops
   bytes_read = FileRead(fnum, b)

   // Here you perform your processing on the current chunk
   tot_b = tot_b + b
NEXT

FileClose(fnum)
DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date