By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,952 Members | 1,722 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,952 IT Pros & Developers. It's quick & easy.

removing data in files

P: n/a
I am searching some info about accessing files with stdio functions.

I am able to open a file, read in it with freaf, write in it with
fwrite, modifying its data in "r+" mode ( without truncation nor
appending ), but I have never found how to remove a piece of data
inside a file, like having sequences "aaaa" "xxxx" "bbbb", and needing
to removi second sequence to end with "aaaa" "bbbb", WITHOUT rewriting
the whole file...

Is that possible ? really..
for example, how databases like sqlite do to delete rows so quickly in
big files ? maybe they don't rewrite all the data, do they ?

Somebody told me about "externals data structures" but I didn't found
what he wanted to mean.

Apr 18 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
bl******@gmail.com wrote:
I am able to open a file, read in it with freaf, write in it with
fwrite, modifying its data in "r+" mode ( without truncation nor
appending ), but I have never found how to remove a piece of data
inside a file, like having sequences "aaaa" "xxxx" "bbbb", and needing
to removi second sequence to end with "aaaa" "bbbb", WITHOUT rewriting
the whole file...
Ah, ye antient and extincte art of faqqe-readinge...
<http://c-faq.com/osdep/insdelrec.html>
for example, how databases like sqlite do to delete rows so quickly in
big files ? maybe they don't rewrite all the data, do they ?


Nope. Generally, they just mark the row "deleted", and only really
delete the marked rows in one great periodical purging operation, or
they re-use marked rows.

Richard
Apr 18 '06 #2

P: n/a

<bl******@gmail.com> wrote in message
news:11**********************@z34g2000cwc.googlegr oups.com...
I am searching some info about accessing files with stdio functions.

I am able to open a file, read in it with freaf, write in it with
fwrite, modifying its data in "r+" mode ( without truncation nor
appending ), but I have never found how to remove a piece of data
inside a file, like having sequences "aaaa" "xxxx" "bbbb", and needing
to removi second sequence to end with "aaaa" "bbbb", WITHOUT rewriting
the whole file...

Is that possible ? really..
No. At some point, the entire file has to be rewritten with the changes.
for example, how databases like sqlite do to delete rows so quickly in
big files ? maybe they don't rewrite all the data, do they ?


The answer to how quickly they do it is: linked-lists.

Text editors and spreadsheets usually break the data up into smaller pieces,
such as a "line" or "cell". These smaller pieces are then inserted into a
linked-list of data structures, called "nodes", where one of the elements of
the structure is a "line" or a "cell". Each node also contains other
elements, such as pointers to the other data structures, to be able to
create the linked-list. To delete a "line" or "cell", they delete the node
from the linked list (by changing the pointers in two nodes to "skip" the
deleted node). To delete text within a single "line" or "cell", they use
functions like memcpy or memset to directly manipulate the contents of the
"line" or "cell".
Rod Pemberton
Apr 18 '06 #3

P: n/a
On Tue, 18 Apr 2006 16:13:33 -0400, "Rod Pemberton"
<do*********@sorry.bitbuck.cmm> wrote:

<bl******@gmail.com> wrote in message
news:11**********************@z34g2000cwc.googleg roups.com...
I am searching some info about accessing files with stdio functions.

I am able to open a file, read in it with freaf, write in it with
fwrite, modifying its data in "r+" mode ( without truncation nor
appending ), but I have never found how to remove a piece of data
inside a file, like having sequences "aaaa" "xxxx" "bbbb", and needing
to removi second sequence to end with "aaaa" "bbbb", WITHOUT rewriting
the whole file...

Is that possible ? really..
No. At some point, the entire file has to be rewritten with the changes.
for example, how databases like sqlite do to delete rows so quickly in
big files ? maybe they don't rewrite all the data, do they ?


The answer to how quickly they do it is: linked-lists.


<OT> An even quicker method used by some databases is to simply mark
the row "deleted". The slot may then be reused, or cleaned up at some
later time. </OT>
Text editors and spreadsheets usually break the data up into smaller pieces,
such as a "line" or "cell". These smaller pieces are then inserted into a
linked-list of data structures, called "nodes", where one of the elements of
the structure is a "line" or a "cell". Each node also contains other
elements, such as pointers to the other data structures, to be able to
create the linked-list. To delete a "line" or "cell", they delete the node
from the linked list (by changing the pointers in two nodes to "skip" the
deleted node). To delete text within a single "line" or "cell", they use
functions like memcpy or memset to directly manipulate the contents of the
"line" or "cell".
Rod Pemberton


--
Al Balmer
Sun City, AZ
Apr 18 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.