hy all, i was wandering if someone of us use some better strategy than mine...

Supposing i have a file with several items(a variable or fixed size structure of data), and i have to delete one of this...

Now I (pseudo):

a- open and read the file to memory
b- point to selected item
c- move all the rest of items in memory above this, in a single block move memory operation
d- subtract from filesize the deleted item size
e- save all back to file

It seems not very fast and i think there's some risk on these operations.
I didn't study nothing about database strategy at school, (i've stopped study at high school, just electronic). I was wandering if there is a better way.

Now i have the particular case to delete variable size items from a file, where the size of every item is inside a header of that item.

Every suggestion/idea/strategy about doing this will be very appreciated.

Hi and THX B7
Posted on 2003-12-06 09:13:04 by Bit7
How about using a linked list.
Create a structure like this
Item STRUCT

.......;the members of data structure
NextItem dd ?
PreviousItem dd ?
Item ENDS

So each item contrains the address in memory of the previous and next item, when you delete an item you set the previous item's NextItem to the address of the item after the one you want to delete. When you want to save the data back to the file you go thru the list saving each item untill you reach the last item (NextItem set to 0)then you set the end of file pointer.
Posted on 2003-12-06 09:52:04 by ENF
thx for the idea, is really better than my way :)
Posted on 2003-12-07 03:55:07 by Bit7