Quote:
Originally posted by KevinHall
However, if your application is very CPU intensive, there are sometimes arrays are better. For example:
(1) A matrix class. Using a pointer with new to define a (protected) array is usually more efficient than defining a vector of vectors.
(2) In an FFT system analysis program I have been dealing with. I have to aquire and analyze real-time about 1MB/sec of data with even slow P1 and P2 systems. Using arrays instead of vectors here helps optimize the performance.
Hmm.. I have yet to see an actual case where arrays are more optimized than properly used vectors (of course, don't push_back everything when the size is statically known -- as they must be for arrays). I have had to do a whole lot of strange and intensive manipulations on data structures, many of which have a backbone that could be represented as a statically sized array or vector, and I have done at several times the profiling to see what would be quicker. Almost always I got the same speed (there was a problem once with the Visual C++ compiler not removing one added layer of indirection on a very very tight loop -- two machine instructions -- but CodeWarrior is always my optimizer of choice and I think I heard -- but haven't checked the disassembly -- that the newer .NET c++ compiler does static indirection elimination optimization properly).
Quote:
Also posted by KevinHall
I know that token pasting is part of the preprocessor, however I have seen it used much, much more in C to accomplish things like writing "template"-macros. I have rarely seen token pasting in C++ b/c of the ability of C++ to handle templates, namespaces, etc.... Of coarse there are situations where token pasting is useful for C++.
I use token pasting all the time since I do a lot of API interception and have simple rules for naming my interception functions. I use them to build up the vectors of function pointers used in the interception. I
Quote:
Originally posted by Luis G
btw, i have found some bugs in compilres, a while ago the old BC 3.1 throwed me some bugs into my program, basically, a variable would change its value right after the constructor, even thou it was specified in the constructor to set it to 0, i debug it step by step with a watch, and just after the constructor ended it would change the value back to -1. i didn't like the solution i had to use, which was declaring the variable as "unsigned int", weird huh?
[...]
gcc doesn't like function calls in an if statement (specifically semaphore creation), i had to call semget before the if statement and save its returned value into a variable to get the program working fine, unbelievable, but it took me almost 4 hours of madness to discover that it wasn't my code the one that was introducing unexpected behaviour.
Actually the BC and gcc "bugs" sound like common programming errors from the description. The BC error sounds like the common problem of mistaken scope and passing stack values, and is common in ctors. The gcc error sounds like scoping and variable lifetime problems. Both of these compilers are quite commonly used by professionals, and although they do have known problems which they list on their respective sites, none of them are as basic to the language as what is suggested. If you however feel you have found some bugs, post them in a new thread and have them publicly evaluated. They are not, however, by any means reasons to not use the language properly except as workarounds are needed, but I understand that was not your point.