NEED: File reading sample (total file into memory at once). 
Author Message
 NEED: File reading sample (total file into memory at once).

I need a sample of reading an entire file into one HUGE string (maybe
300K+) at once using PBDLL 5.0.   I've got an application that does a
lot of file searching and I thought it might be faster to read the
entire file in at once rather than a record at a time.

thanks

To send me Email ... remove any (anti-spam) X's in my address



Sat, 03 Nov 2001 03:00:00 GMT  
 NEED: File reading sample (total file into memory at once).
As PB/DLL 5.0 can create strings up to 2Gb, just use BINARY mode,
fetch the lentgh of the file, and grab it all with one GET$ statement.
Note that this is a quick-n-dirty approach, and not a typically
network friendly aproach.  To keep network traffic from bogging down,
limit your chunks to 8k (rule of thumb value).

Off the top of my head:

DIM x AS LONG, a AS STRING
x = FREEFILE
OPEN "MYFILE.DAT" FOR BINARY AS #x
GET$ #x, LOF(x), a
CLOSE #1

A can be up to 2Gb without a problem, provided Windows has enough
space to enlarge the swap file if necessary, once your data "segment"
exceeds available physical memory size.
You may wish to add error testing, etc, just to make it fail-safe.

Quote:

>I need a sample of reading an entire file into one HUGE string (maybe
>300K+) at once using PBDLL 5.0.   I've got an application that does a
>lot of file searching and I thought it might be faster to read the
>entire file in at once rather than a record at a time.

>thanks

>To send me Email ... remove any (anti-spam) X's in my address

Lance
powerbasic Support

-------------------------------------------------------------------------
PowerBASIC, Inc.      | 800-780-7707 Sales | "We put the Power in Basic!"
316 Mid Valley Center | 831-659-8000 Voice | http://www.powerbasic.com



Sun, 04 Nov 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Q: simple example of read file->convert char(s)->write file needed

2. I need a background task to process a file once a day

3. need sample for file-upload via http with auth

4. Reading a file into memory

5. Read/Writes to memories/register files for PIC core

6. PythonWin and read-only memory mapped files

7. Memory leak in file.read() on Solaris?

8. Help needed: File is too large to fit in the memory

9. Reading from input file writing to output file

10. how to read one file, print to two files

11. reading ascii file and creating topspeed file in application designer - gasman.zip (0/2)

12. Read FAX files (Tiff,G3,g4..), for split in 1 page files

 

 
Powered by phpBB® Forum Software