FSRW and indexing question
Don M
Posts: 1,652
I am writing fixed length (30 bytes) strings to a file on sd card using fsrw. Each new string is stored using the "append" mode. Works great.
Now my question- lets say I wanted to re-write the last string that was stored. Is there some sort of index pointer that is kept track of that I could "back up" and re-store a new string in the place of the last one?
And to take it a step further- would it be possible to re-write any one of those fixed length strings?
Thanks.
Don
Now my question- lets say I wanted to re-write the last string that was stored. Is there some sort of index pointer that is kept track of that I could "back up" and re-store a new string in the place of the last one?
And to take it a step further- would it be possible to re-write any one of those fixed length strings?
Thanks.
Don
Comments
What's the max number of 30 byte records? Can you post an example of a 30 byte record?
http://obex.parallax.com/object/16
This seems like brute force :-). Was thinking of trying to do something more on the fly.
The file size as reported by FSRW is typically 1908 to 2524 bytes (?) The number of 30 byte strings is typically 16 to 30.
"0824 This is one example ",13 It's a basic text string with a carriage return at the end.
I was thinking it would be fairly easy to use the reported file size and subtract backwards to make my way through the strings but I don't know that I can tell FSRW to store the new 30 byte string at x location.
Hmm... I see that but was hoping to use FSRW if possible.
I would describe the method as simplistic. I guess brute force works too. The file is small so disk IO is not too bad; 30*30=900 bytes.
If I understand, the idea is to...
UPDATE file.txt WHERE [the data field] = <old 30 byte> string by SETing the [the data field] to the <new 30 byte> string
To find the 30 byte string, assuming the index is unknown, copy the file contents from the SD card to a memory buffer in the prop.
Loop through the buffer until the old string value is found. The loop count is the index if the old string value.
BYTEMOVE the new value over the old value
Write the buffer back to the the SD card.
If the SD driver has seek capabilities, replace BYTEMOVE with SEEK/WRITE or do both a BYTEMOVE and SEEK/WRITE
Now decide if keeping the buffered data makes sense. If there are a lot of updates, an in memory table might make sense. Maybe create a hash table to speed up the the search...
If the data file has many records, consider ordering the data and use a binary search. However, ordered data makes inserts tricky.