Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


cstdio FILE really slow


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 KoldGames   Members   -  Reputation: 222

Like
0Likes
Like

Posted 02 April 2014 - 01:55 PM

Hello everyone!  I started by using ifstream to read my model format but found it to be really slow.  So I switched to cstdio only to find out that ifstream is based on cstdio so it ran at the same speed.  Does anyone know of a better, faster way to read files? It's weird because even C#'s BinaryReader ran faster than cstdio while reading my file. Thanks! :)



Sponsor:

#2 rip-off   Moderators   -  Reputation: 8515

Like
0Likes
Like

Posted 02 April 2014 - 02:46 PM

Can you show us your code?

#3 L. Spiro   Crossbones+   -  Reputation: 13970

Like
9Likes
Like

Posted 02 April 2014 - 03:06 PM

No matter what interface you use to load a file’s contents it will be slow if your approach to loading is naïve, and streams, while serving to abstract away the source of data (be it from a file, a network, user input, etc.), tend promote naïve loading practices.

 

Streams, cstdio, ReadFile, and any other API/interface can be fast as long as you know what to do and what to avoid.

 

DO:

Load data in large chunks at a time.

Make as few calls to the API/interface as possible (in other words, load data in large chunks at a time).

Cache files that will be opened regularly.

 

DO NOT:

Read small amounts of data at a time such as single bytes or single integers unless necessary.  Streams tend to promote this practice so it is likely what you have done and the cause of your performance issues.

Repeatedly open and close files.

 

 

For games, where performance is always critical, the best way to load a file is to map it to memory (CreateFileMapping()) and access it directly rather than going through any API/interface.

 

 

L. Spiro


It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS