10-14-2004 06:40 AM
10-14-2004 07:50 AM
10-15-2004 08:03 AM
Executive Overview
As jbrohan mentioned, you cannot add at the beginning of a file without rewriting the entire file in one way or another. You have two choices. You can dynamically overwrite your original file or you can create a new file and copy the the new info into it, followed by a copy of your entire old file. With only 3.5MBytes, this should take about one second.
Engineering Details
Method 1 - use original file
The disadvantage to this method is that it can take a lot of memory, depending upon your record size. It is also a bit more complex to code. The advantage is that it extends your current file, so it minimizes disk space usage and fragmentation.
All large disk operations should be done in pieces or chunks. On Windows operating systems, the ideal chunk size for LabVIEW is about 65,000 bytes, just under the 65,535 boundary. Using another chunk size can slow down your disk operations by an order of magnitude or more.
Create your data. Determine how big it is (how many bytes). Read at least that many bytes from the beginning of your current file and cache it in memory (use chunks if necessary). Now write your new data to the beginning of the file. Read and cache another section and write the section that would have been over-written by your new data. Continue alternately reading and writing until you have rewritten the entire file.
Method 2 - use new file
This method uses less memory than method 1, but uses more disk space and can lead to disk fragmentation. The disk space issue is probably negligible, given the relatively small size of the file. Memory may or may not be.
Open an new file (call it anything you want, you will be renaming it to the old file name). Write your new data into it (use chunks if over 65,000 points in size). Starting at the beginning of the old file, copy the old file into the new file. Use 65,000 byte chunks for maximum speed. Delete the old file. Rename the new file to the old file name (use the Move advanced file function).