Matt,
FoxProMatt_MattSlay wrote:Robert - "At shutdown" could be too late to mimic current VFP behavior.
Presently in VFP, as soon as you issue REPLACE command, the data is written to file right then (unless Table Buffering is used). To delay that write-to-disk operation at all would not be in line with how VFP works now, and it could have effects on VFP apps, as you never know what kind of other code people might execute following a REPLACE command that expects to find the data already written to disk.
So you say that if I write:
Code: Select all
REPLACE FirstName WITH "Matt"
REPLACE LastName WITH "Slay"
that FoxPro will issue 2 writes to the DBF ? I find that hard to believe.
I suspect that FoxPro will update a buffer in memory and when it detects that you are ready then it will update the DBF and its indexes.
If It would not do that and if there is an index on LastName+FirstName then these 2 write operations would involve 4 writes:
1) Update FirstName in the DBF
2) Update the index with the new Firstname and old LastName
3) Update LastName in the DBF
4) Update the index again with the new FirstName and new LastName
Even when you ignore the performance fit this would take, it also does not make much sense to write a partial transaction to disk (e.g. only an updated FirstName).
Most implementations of file sharing that I have seen do it differently:
1) Write the fields to a local buffer and mark the buffer "Hot"
2) When the record pointer is moved or the file is "committed" then a "GoCold" operation is performed. In this operation:
a) the buffer is written to disk
b) the "before" and "after" results of each index expression are calculated. When these are different then the old key is deleted from the index and the new key is inserted.
The only thing that happens immediately is an Append:
1) The header of the DBF is locked
2) A blank record is added to the end of the DBF this record is locked
3) The record count in the header of the DBF is updated
4) The header is unlocked
In the "GoCold" operation after an append the system "knows" that it does not have to delete old index keys and only insert the new index keys.
But maybe you are right. I will use a tool such as ProcMon from Sysinternals to look and see what VFP is doing.
Robert