|
From: Zodiaq <zo...@ac...> - 2003-07-31 10:28:52
|
Hello Neszt and all Dev-C++ users, Thursday, July 31, 2003, 10:52:59 AM, Neszt wrote as follows: NT> Hello! NT> #1: NT> Should I use the sprintf within an opengl application? I'm worrying about NT> the speed. Is sprintf taking a long time? (As I tried it, I can not feel NT> any fall-off) Maybe you could try ostringstream from C++ std namespace?? #include <sstream> static std::ostringstream some_text; //before every next use (after first ) you have to clear it: some_text.str( "" ); //to insert new text use standard stream insertion "<<" some_text << "some text, my fps are: " << fps << " fps"; //to format float and double data types to have only 2 digits after "." //use these: #include <iomanip> some_text << "some text, my fps are: " << std::fixed << std::setprecision( 2 ) << fps << " fps"; //to get standard C's char * string use: some_text.str( ).data( ); C++ STD objects and streams are very fast but remember to use static to only once alocate extra memory needed by ostringstream... if you check it in OpenGL please do tell me result - it is very interesting for me as I never checked this out and I don't really know which one is faster... I know that ostringstream is much more safer as it dynamically allocates needed memory - not like sprintf which writes directly to memory (and here writing beyond buffer is quite often and very dangerous as it leads many times to "random" crashes) Waiting for some results :-) -- regards, Zodiaq |