Reading file

This is a discussion on Reading file within the Windows Programming forums, part of the Platform Specific Boards category; I need to scan an entire text file and I would like to know which is the best between copying ...

  1. #1
    lyx
    lyx is offline
    Amateur
    Join Date
    Sep 2003
    Posts
    228

    Reading file

    I need to scan an entire text file and I would like to know which is the best between copying the whole thing into memory and loading it part by part.
    The file is not, or at least I don't think it could be, a large file, it is some sort of simple script for some simple tasks... (actually, it does not have a real goal except to make me discover a little more about programming)

    Thanks to all who will answer this.
    Last edited by lyx; 11-21-2003 at 10:07 AM.

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    File IO is slow but if the file is not large compared to the read size, it should not be a problem.

    I prefer to grenerally

    find the file size,
    alloc a buffer,
    open,
    read entire file,
    close file,
    process data,
    free mem.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  3. #3
    30 Helens Agree neandrake's Avatar
    Join Date
    Jan 2002
    Posts
    640
    For windows, lookup the functions

    CreateFile()
    ReadFile()

    I believe those are the functions
    Environment: OS X, GCC / G++
    Codes: Java, C#, C/C++
    AOL IM: neandrake, Email: neandrake (at) gmail (dot) com

  4. #4
    lyx
    lyx is offline
    Amateur
    Join Date
    Sep 2003
    Posts
    228
    novacain >
    Thanks, I think I can do it that way.

    neandrake >
    I already know the functions. ^^ Just posted the question here because maybe I could get some platform specific stuffs but, don't seem to. Thanks anyway.

  5. #5
    ENF
    ENF is offline
    Registered User
    Join Date
    Oct 2003
    Posts
    12
    try file mapping
    CreateFileMapping
    MapViewOfFile

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. opening empty file causes access violation
    By trevordunstan in forum C Programming
    Replies: 10
    Last Post: 10-21-2008, 11:19 PM
  2. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 12:36 PM
  3. Replies: 3
    Last Post: 03-04-2005, 01:46 PM
  4. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 09:46 AM
  5. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21