Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > removing data in files

Reply
Thread Tools

removing data in files

 
 
blubzouf@gmail.com
Guest
Posts: n/a
 
      04-18-2006
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.

 
Reply With Quote
 
 
 
 
Richard Bos
Guest
Posts: n/a
 
      04-18-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) 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
 
Reply With Quote
 
 
 
 
Rod Pemberton
Guest
Posts: n/a
 
      04-18-2006

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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


 
Reply With Quote
 
Al Balmer
Guest
Posts: n/a
 
      04-18-2006
On Tue, 18 Apr 2006 16:13:33 -0400, "Rod Pemberton"
<(E-Mail Removed)> wrote:

>
><(E-Mail Removed)> wrote in message
>news:(E-Mail Removed) 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Removing Duplicate Files RBF Computer Support 13 09-09-2013 07:06 PM
Removing GPO setting from XP machine after removing from Domain Piet Slaghekke Computer Support 4 01-02-2007 08:58 PM
removing a namespace prefix and removing all attributes not in that same prefix Chris Chiasson XML 6 11-14-2006 05:08 PM
removing code blocks from autogenerated files with ant ion Java 2 02-08-2005 07:22 PM
Outlook Express removing files I want to send rpaulsen Computer Support 2 06-30-2004 02:03 PM



Advertisments