CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Jan 2007
    Location
    Italy
    Posts
    156

    [RESOLVED] Editing ASCII files

    Good day to all.

    I'm accessing an ASCII file, a large one, and my application needs to insert a character in a certain position to update data. The question is related to physical memory handling in moving the part of file that follows the newly inserted character... It is the only way to create a new file in which copy the part that precedes the inserted new char, then append the char and finally paste the subsequent original second part of the file? Because of the size of the file, this is not very fast...
    If it is the only way, does anybody have some hint on how to perform it faster?

    Thanks in advances, and nice holidays to all!
    - Buzzyous -

  2. #2
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: Editing ASCII files

    What do you mean byt "LARGE"???

    A quick test on my machine did this for a 100MB vector in under 100mS....
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  3. #3
    Join Date
    Jan 2007
    Location
    Italy
    Posts
    156

    Re: Editing ASCII files

    What about 12 GB?
    - Buzzyous -

  4. #4
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Editing ASCII files

    Quote Originally Posted by Buzzyous View Post
    What about 12 GB?
    Isn't this something you should be trying yourself before assuming it's slow? If it is slow, then show us the code you're using to do this operation.

    Regards,

    Paul McKenzie

  5. #5
    Join Date
    Feb 2007
    Location
    Craiova, Romania
    Posts
    326

    Re: Editing ASCII files

    I cannot think now of a classical IO approach that will make this acceptably fast (from an end user's point of view).

    Have you thought of using MMF's? (Memory Mapped Files). They would make altering such a large file relatively easy, considering the alternative.
    Here's an article to get you started: http://msdn.microsoft.com/en-us/library/ms810613.aspx

    You can post here if you have any more questions about this technique.

  6. #6
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: Editing ASCII files

    Quote Originally Posted by marceln View Post
    IHave you thought of using MMF's? (Memory Mapped Files). They would make altering such a large file relatively easy, considering the alternative.
    Here's an article to get you started: http://msdn.microsoft.com/en-us/library/ms810613.aspx
    As a 64 bit application on a machine with ALOT of memory, that might be feasible.....Unfortunately most "affordable" machines will only support 12GB total RAM....

    But to be honest, I have NEVER seen a 12GB text file.

    If that was printed as a set of books, it would take over 120 meters of shelf space...More than a football (American or European) field is long.
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  7. #7
    Join Date
    Jan 2007
    Location
    Italy
    Posts
    156

    Re: Editing ASCII files

    It is not text file, just ASCII file. I can access data as characters, but data is not necessarily to be interpreted in that form. They can be anything, like imagines, audio, video, etc.
    The solution in the link seems nice, but in any case I found an error in the program; it now works in the times presented by CPUWizard, that are more acceptable than before.

    Thanks to all for the very fructuous help, it really fastened things up for me. As usual, Codeguru is OK.

    Bye to all, until next time!
    - Buzzyous -

  8. #8
    Join Date
    Feb 2007
    Location
    Craiova, Romania
    Posts
    326

    Re: Editing ASCII files

    You managed to do this:
    create a new file in which copy the part that precedes the inserted new char, then append the char and finally paste the subsequent original second part of the file
    with a 12 gb file in under 100 ms?

  9. #9
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: Editing ASCII files

    Quote Originally Posted by Buzzyous View Post
    I

    Bye to all, until next time!

    Dont forget to mark threads as resolved, and to rate those who helped....
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  10. #10
    Join Date
    Jan 2007
    Location
    Italy
    Posts
    156

    Re: Editing ASCII files

    Quote Originally Posted by marceln View Post
    You managed to do this:

    with a 12 gb file in under 100 ms?
    Ahaha! No of course not... in 100 ms for 100Mb of course!
    - Buzzyous -

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured