Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Random Access File Question

Status
Not open for further replies.

wcwolff

Technical User
Aug 3, 2004
13
US
I need an opinion. I am writing a (5-10 user) multi-user business application. Files will reside on a Windows 2003 server and accessed by various XP workstation users. For a variety of reasons (not important here) I am using random access shared data files and accessing them them using FileOpen(), FileGet() etc method with structures.

Often, particular records may be kept open for extended times and other times not. My question is this. When a record is in use, is it better to keep the file open until the use of the record is finished or is it better to retreive the record, close the file and then re-open it to write any changes? Concurrency issues have been dealt with.

Thanks in advance for your advise.
 
Well, this depends. If you could ever get into a situation where User1 queries the information, then User2 queries the information. Next User1 updates information, then User2 updates information; then you would need to either lock the records or provide some type of conflict resolution.

The next issue you need to address is expense of the query. Typically a flat file has to be read completely into memory before any operations can be accomplished. If this is going across a network, a relatively small file (one or two MB's) can cause a LOT of traffic. Multiply that times the number of users, and you could easily bring a network to it's knees.

To answer your question, As long as you provide absolute record integrity then you'll be fine. You'll need to add all of the logic to handle this internally because the database will not be there to do the grunt work for you.
 
Thanks! Those are some of the concerns that I have and the reason for asking for opinions. I am concerned about network traffic too vs keeping mutiple file connections open from mutiple users. I should add that I am not using general record locking as it then ties the record up to other users. I am locking/unlocking the record only at write time. Just for info - the average record size being used is a about 1200 bytes.

I am dealing with integrity via record timestamps - reading the current record timestamp vs. the original timestamp when record was initially loaded. If the current time stamp is newer than the original timestamp then record is reloaded before modificaion and writeback.

To read the timestamp only I set up a seperate structure contaning only the timestamp (8 bytes). By recalculating the record number in the file based on 8 bytes rather than the 1200, I can read just time stamp of the current record thus reducing network traffic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top