Question about ifstreams efficiency

This is a discussion on Question about ifstreams efficiency within the Game Programming forums, part of the General Programming Boards category; Hi I want to make a scripting system that reads from a txt file and acording to that file's contents ...

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    84

    Question about ifstreams efficiency

    Hi

    I want to make a scripting system that reads from a txt file and acording to that file's contents it changes the behavior of the object.

    I have the system worked out in my mind but i need to know, for the sake of efficiency, how am i suposed to do this?

    I was thinking about having an ifstream object inside all my classes objects, and then i could read that file every time the game loop repeated, but i dont know if this is efficient or if it will make my game slow at some point.

    so help me here, are fstreams efficient enought to read/write from them during the execution of a program like a game??

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,672
    That depends what your game does. Reading a lot of text files will not work well in a "game loop" that needs to refresh high resolution scenery in a manner that makes movement look life-like. But you will probably get away with it in simple games like tetris (which involves small objects that aren't rendered all that often).

    Any form of file I/O is inherently reliant on the performance of the device the file is stored on. It doesn't matter whether you use C++ streams, C I/O functions, or I/O functions that are specific to your operating system. Even with advanced caching of modern hard drives, it takes significantly longer (as in orders of magnitude) to read data from a hard drive than to read the same data from RAM (assuming it is already resident in RAM).
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Sunshine, and read this, this, and this before posting again.

  3. #3
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,598
    Scripts are normally 'compiled' into engine specific data structures and then these structures are 'executed' by the script system. I would not recommend real-time parsing of scripts unless you are using Lua or some other language interpreter that is known to be quite fast.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. SDL buffer channels question
    By TriKri in forum Game Programming
    Replies: 3
    Last Post: 12-09-2009, 05:52 PM
  2. Newbie question, C #
    By mate222 in forum C# Programming
    Replies: 4
    Last Post: 12-01-2009, 06:24 AM
  3. another do while question
    By kbpsu in forum C++ Programming
    Replies: 3
    Last Post: 03-23-2009, 01:14 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 10:47 PM
  5. opengl DC question
    By SAMSAM in forum Game Programming
    Replies: 6
    Last Post: 02-26-2003, 09:22 PM

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