473,387 Members | 1,585 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

File manipulation

I was wondering what the best method of updating a file was.

heres my prob, ive got a file with say 1million urls and I want to
take the first 10,000 and store them in memory. I want to 10k of urls
to be taken out an the file to be updated. is there anyway i could
move the beggining of the file?? What would b the most efficient way
of updating the file??

thanks for any help in advanced.
Jul 22 '05 #1
3 1591
Chad wrote:
I was wondering what the best method of updating a file was.

heres my prob, ive got a file with say 1million urls and I want to
take the first 10,000 and store them in memory. I want to 10k of urls
to be taken out an the file to be updated. is there anyway i could
move the beggining of the file?? What would b the most efficient way
of updating the file??

thanks for any help in advanced.


You can always append to a file to update it.
If the file consists of fixed sized records then
you can position to a record and write a new value
to the file (assuming the file has random access).

Read about:
seekp
seekg
fseek
tellp
tellg
ftell

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.comeaucomputing.com/learn/faq/
Other sites:
http://www.josuttis.com -- C++ STL Library book

Jul 22 '05 #2
Chad wrote:
I was wondering what the best method of updating a file was.

heres my prob, ive got a file with say 1million urls and I want to
take the first 10,000 and store them in memory. I want to 10k of urls
to be taken out an the file to be updated. is there anyway i could
move the beggining of the file??
No. You have to copy all the following data back to the beginning. Or
you could somehow mark your first 10,000 urls as removed so you can
just ignore them the next time you read.
What would b the most efficient way of updating the file??


Open a new file and copy all the data you want to stay to that new file.
Then rename the new file so it overwrites the old one. The latter is
usually an atomic operation, which means that if something happens (a
crash e.g.) during your update operation, the user will not get corrupt
data.

Jul 22 '05 #3
Chad wrote:

I was wondering what the best method of updating a file was.

heres my prob, ive got a file with say 1million urls and I want to
take the first 10,000 and store them in memory. I want to 10k of urls
to be taken out an the file to be updated. is there anyway i could
move the beggining of the file?? What would b the most efficient way
of updating the file??

There's not way in standard C++ (nor in most implementations) to remove
anything from the start or middle of a file. Some systems provide
extensions that let you truncate files, but that's OT here. Your only
way to do this is to copy the file. Load your lines into memory, update
them, write them out to a new file, deal with the next batch or copy the
remaining portion of the original file to the new one.

A performance improvement would be if you had a way to categorized the
URLs, so you could break things up into smaller files.

Brian Rodenborn
Jul 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Paul Moore | last post by:
Does anyone know of a Python library which handles sound file formats (MP3, Ogg, FLAC are the three I'm nost interested in). I'd like something that can manipulate "metadata" - stuff like artist,...
7
by: Dennis C. Drumm | last post by:
I would like to be able to update an xml file located on my hosted server from my local computer. The server requires a user name and password to access the web site for writing or updating...
1
by: ma740988 | last post by:
Trying to some of my reading on file manipulation (ifstream/ofstream/fstream) into action. So now consider. # include <iostream> # include <fstream> # include <cstring> # include <sstream> ...
2
by: PFI | last post by:
Hi, I recently installed SQL Server 2005 Enterprise Edition (9.0.1399) and I have problems on queries concerning system file manipulation... For example, when I try to increase the Log File of...
4
by: magix | last post by:
Dear Guru, I'm not so good in file manipulation, but would like to seek for help here. I have following basic code of command line argument as starting point (the code below output the...
1
by: scubber | last post by:
hi, im new (as you're going to painfully aware of in a minute) to programming and was wondering if anyone could help with this little problem: i am trying to read a number of values which are...
0
by: L'eau Prosper Research | last post by:
Press Release: L'eau Prosper Research (Website: http://www.leauprosper.com) releases new TradeStation 8 Add-on - L'eau Prosper Market Manipulation Profiling Tools Set. L'eau Prosper Market...
0
by: L'eau Prosper Research | last post by:
NEW TradeStation 8 Add-on - L'eau Prosper Market Manipulation Profiling Tools Set By L'eau Prosper Research Press Release: L'eau Prosper Research (Website: http://www.leauprosper.com) releases...
1
by: tourist.tam | last post by:
Hi, I am trying to read a file using a BufferedStream and avoiding at maximum the use of string manipulation. I need now some help understanding on how to use byte array to hold the data and...
15
by: pakerly | last post by:
How would i do this, convert a test file to excel? Lets say my text file has fields like this: NUMBER NAME ADDRESS PHONE 11002 Test1 ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.