Advertisement

Three kinda newbie questions

Started by August 13, 2000 01:10 AM
22 comments, last by Peon 24 years, 4 months ago
Libraries speed development time. So if you need a quick sort, you don''t have to write the algorithm, you just use library functions. Also you need a library for hardware acceleration and interfacing with the drivers. Library functions are generic and unoptimised. So you may need to write faster functions occasionally. In BASIC there are library functions, and all the libraries are included by default, so for an application that just spits out text there is a lot of wasted space. This is because BASIC is higher level than C and C++. So you can reduce program size by translating them into C/C++

------------------------------
#pragma twice
quote:
but C++ is stricter. You need to #include and then call
strcpy(highscore, name);


C++ and strcpy? gah! What you want is #include (without the .h), and use it like this:

        #include <string>void foo(){	std::string name;	std::string highscore;	name = highscore;}        


There's not much need for char arrays when working with strings, using std::makes things much simpler.

Edited by - Wilka on August 13, 2000 12:47:45 PM
Advertisement
As Peon (appears) to be a newbie, it''s pretty important for him/her to know how to use char arrays. I recommend the use of a string class instead of char arrays, but the char arrays are still here (I''m afraid), and sooner or later you''ll see them, and you might as well learn how to use them now instead of later!
I'm reminded of the day my daughter came in, looked over my shoulder at some Perl 4 code, and said, "What is that, swearing?" - Larry Wall
Thanks all I was just using char arrays because I was reading the lessons from a C++ class that someone sent me, and it used char arrays. I''ll have to look into other methods though.
Peon
There''s no idea of using the STL string class for the simple tasks such as holding a filename or such. It just means extra overhead.

"Paranoia is the belief in a hidden order behind the visible." - Anonymous
quote:
There''s no idea of using the STL string class for the simple tasks such as holding a filename or such. It just means extra overhead.


If your already using std::string in your project, what extra overhead is there for using it to store filenames? Unless I know the string at compile time, I always use std::string.
Advertisement
A string class will be slower than a char array always because of the added level of indirection. If you just use strings for filenames and screen display, a string class adds unneccessary overhead. I''m not being anti-C++, templates saved my project.

------------------------------
#pragma twice
yeah, but you usually only use filenames during loading or saving, which don''t need to be performed at 70fps.
my console code uses char arrays and my garbage collector uses strings.

(my console used to use strings and i only gained 0fps since i was waiting for vsync anyways...guess it just depends on how inefficiently or efficiently you use them).



crazy166
some people think i'm crazy, some people know i am
quote:
A string class will be slower than a char array always because of the added level of indirection


std::string is mostly small functions, and they get expanded inline (unlike strcpy, strcat, etc.). So it''ll probably end up faster than if you coded it using char arrays (and with less bugs).

It also means you don''t need to spend any doing the string routines yourself, so you can work on the important stuff in your project.
...besides, I doubt speed will be an issue in a text RPg
Peon

This topic is closed to new replies.

Advertisement