• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.

Archived

This topic is now archived and is closed to further replies.

level10boy

File I/O

5 posts in this topic

Does anyone know what the fastest possible file I/O technique is available to a C/C++ programmer. Everyone I speak to seems to have different opinions on the matter but from what I gather, C''s stream I/O is the winner. If anyone can back this up or knows better than me, please reply to me and you will be forever in my debt. Thankz level10boy
0

Share this post


Link to post
Share on other sites
Whatever proprietary mechanism the OS provides is likely to have the overall best performance.

... I don''t think C has a stream IO... streaming is kinda a C++ thing.

The fopen/fseek/fclose functions are a bit (ok alot) faster than the fstream class.

I''d expect Windows file IO handled with asynchronous completion ports to yield the best performance, but it''s just a hunch.

It kinda depends on what you''re doing; some things are only possible with event driven asynchrous IO; suppose you want to stream data off disk and do something with it more frequently than 1ms intervals (and not use all available cpu power).

And some things it just doesn''t matter, like read a text file (unless they''re friggin'' huge).

Magmai Kai Holmlor
- The disgruntled & disillusioned
0

Share this post


Link to post
Share on other sites
i don''t know if they are the fastest, but i love em, ifsteam, and ofstream. i mean you can write whole objects, and structs to bianary files and load them in a few verry easy lines.


  
ifstream fin;
ofstream fout;

bool SaveMap(FileType &SaveingMap, char* Filename)
{
fout.open(Filename, ios::binary);
if(!fout)
{
MessageBox(NULL, "ERROR SAVING MAP", "Error", MB_OK);
return 0;
}

fout.write((char*) &SaveingMap, sizeof(FileType));
fout.close();
return 1;
}

/////////////////////////////////////////////////////////////////////

bool LoadMap(FileType &LoadingMap, char* Filename)
{
fin.open(Filename, ios::binary);
if(!fin)
{
MessageBox(NULL, "ERROR Loading MAP", "Error", MB_OK);
return 0;
}

fin.read((char*) &LoadingMap, sizeof(FileType));
fin.close();
return 1;
}


it''s just that easy, if anyone wants to use these functions(though i''m sure most people have very complicated 100x faster versions for them selves but hey, whatever works right) feel free, i''m sure you can see how they work. and i love posting code from my game i''m also on some realy good medicine so i''ll shut up now...


-------------------------------------------------
Don''t take life too seriously, you''''ll never get out of it alive. -Bugs Bunny
0

Share this post


Link to post
Share on other sites
i think for windows
CreateFile()
WriteFile()
ReadFile()

is the fastest , but its also just a hunch


{ Stating the obvious never helped any situation !! }
0

Share this post


Link to post
Share on other sites
Ok .. the answer is already posted .. but i want to add a few tidbits.

There are (at least) 5 different I/O methods ... 3 fast, 2 slow. The exact comparisons I don''t know ... but here are the basics .. from what I assume are slowest to fastest .. but the top 3 are very close and you should run tests to find out which is best.

SLOW - formatted io

1. Hands Down Slowest - formatted I/O in C using fprintf type functions.

2. Second Slowest - formatted I/O in C++ using insertion / extraction operators (<< >>)

FAST

3. C++ file stream''s read and write member functions.
4. C''s binary FILE read / write function ... FREAD i think.
5. Win32s binary file read write functions WriteFile() .. etc

the bottom 3 should be considered equivelent unless you have run tests that say otherwise ... usually you just choose the one that most closely matches the rest of you code ... 3 if you use c++ strstreams or manipulators ... 5 if you are using many other Win32 API functions ... and 4 if you are using C standard library stuff.

I personally use 2 and 3 ... pure c++ all the way ... formatted i/o when usefull and not speed critical ... binary i/o when structured and /or performance critical.

good luck.
0

Share this post


Link to post
Share on other sites
Some comments:

1. Asyncronous IO only works on OSes based on NT/2K kernel. So is not supported on Win9x.

2. CreateFile is the fastest... but only if you use the correct flags for your access type, and stick to sensible patterns (FILE_FLAG_SEQUENTIAL_SCAN can help quite a lot if you do access in true sequential order, as can some of the flags).

3. In places where you''re allocating a buffer to read into, doing something with the data and then freeing the buffer - you can actually get even faster still by using Memory Mapped Files... (this is the mechanism Windows uses to handle virtual memory so is very optimal).

In our last game (Pac-Man:Adventures in Time) all data was held in a single monolithic file (.PAC) opened at the start of the game (CreateFile with correct flags). A file mapping object was created for the file, which again was held open throughout the games life. When some data was required from the file, a view was mapped (MapViewOfFile) - this makes the file become part of the process address space, so can be accessed just like real memory - and is buffered and paged into real memory in the same way as virtual memory pages are.

Use CreateFile, CreateFileMapping and MapViewOfFile for the fastest access in Windows...

--
Simon O''''Connor
Creative Asylum Ltd
www.creative-asylum.com
0

Share this post


Link to post
Share on other sites