Re: Opening large files for small amounts of data



: When I open a file in VB, what really happens? What I mean is that I
: may have a file on a remote server, but still inside of our network,
: that can be over 1 GB in size. If I just need to open it to append a
: small amount of data to it, how much traffic over the network really
: occurs?


AFAIK, it just acquires access to the file with no significant traffic. It
doesn't haul down the file, for example.

: How about for reading a couple of lines from that file (say the last 2
: lines)?



If you're opening in Binary mode and using Seek to move the file pointer to
a specific spot, or using Random Access mode with fixed-size UDTs, you can
access any point or record in the file in random order, forwards or
backwards. If the file is opened for Append, however, the only way to move
to the last couple of lines for reading is to read each line starting from
the beginning. You could, I suppose, try mixing a Seek call after the file
was opened for append but you'd have to handle tracking where the data you
want to read is located.

: Are there things I can do to make sure that I can get the fastest
: access times?

All are fast for access; any sequential file method (input/output/append)
will require reading from the start of the file to reach any point later in
the file (for reading). Naturally append itself automatically expects to add
new data to the end. So if you can bypass any reading of the file's current
data, you're overhead is just that needed to pass the data to be written to
the file.


: How does a computer actually "Open" a file, and how much data is sent
: at that time?

It acquires a handle to the file from the operating system. Probably no more
than a few bytes are involved in the actual work in doing this. The largest
overhead is hauling the file data down to the client system (i.e. a file
read), or re-writing an entire file at the destination (re-writing from
memory, as opposed to copying the file itself).



--

Randy Birch
MS MVP Visual Basic
http://vbnet.mvps.org/
----------------------------------------------------------------------------
Read. Decide. Sign the petition to Microsoft.
http://classicvb.org/petition/
----------------------------------------------------------------------------



.



Relevant Pages

  • Re: Fastest Way to Append Chars to Text File Rows in VB6.0
    ... you might consider reading them also in ... >>> cycle through all these files and append some additional chars at the ...
    (microsoft.public.vb.general.discussion)
  • Re: iterating over a list and printing
    ... Bart Nessux wrote: ... You are reading the entire file in one big string and append it to the list ...
    (comp.lang.python)
  • Re: exporting data to the middle of a text file
    ... for opening text files for either reading, writing or appending. ... only writing/exporting I can find seems to either append the data to ... Woudl it work to rewrite the text file into a new name up to the ...
    (microsoft.public.excel.programming)
  • Query messages turning them off
    ... Reading is fundamental. ... macro did it. ... >generated during an append. ...
    (microsoft.public.access.queries)
  • Re: Curious (Student)
    ... I am reading over *The Design and Implementation of the FreeBSD ... Operating System* right now and it is filled with everything you need ... >> possess an Associate Degree in Electrical Engineering, ... > Sounds like you're going to have fun with the 11000+ packages available! ...
    (freebsd-newbies)