Jump to content
  • Advertisement

Red Ant

  • Content Count

  • Joined

  • Last visited

Community Reputation

471 Neutral

About Red Ant

  • Rank
    Advanced Member
  1. Red Ant

    C++: Custom memory allocation

    I'm sorry, but if you're going to go to the trouble of writing custom allocators why wouldn't you at least make them STL-compliant so you can actually use them with the various STL containers??
  2. Hi, I have a C++ module consisting of a bunch of functions containing quite complicated floating point math computations that get run over and over again in a tight loop. Profiling has shown that the program spends a substantial amount of CPU time running these floating point computations. Floating point multiplications and std::sin() / cos() / tan(), etc. seem to be a lot more expensive than I thought. We're already compiling with -xO4 (which is the second highest optimization level on our compiler). In the past few days I've been trying to optimize these computations as much as I can. I've actually had some success as some of our simulation tests scenarios have gone down from roughly 60 seconds to about 50 seconds. Not an astronomical improvement but nothing to be sneezed at either. The way I've been going about this is to mainly break up complex computations that reuse the same expression over and over. So instead of evaluating the same expression many times over, I just evaluate it once and then feed the result into the computations that depended on the original expression. The downside to this is that readability of the calculations has suffered badly. Also, it's pretty tenuous work and I have to take great care not to accidentally mess up any of the rather complicated calculations. So I was wondering if there are any fancy mechanisms or tools that can be fed a series of complicated math expressions and that will try to automatically identify and remove any redundant calculations to optimize the computations as much as possible. Does such a thing exist or am I stuck with handcrafted optimizations?
  3. Red Ant

    Java vs C++ research paper

    I'm sorry, but what do you mean by that?
  4. Red Ant

    Segmentation fault on std::sort

    Oops, sorry. Shame on me for not reading the whole thread before posting.
  5. Red Ant

    Segmentation fault on std::sort

    Well, there's your problem. You're invoking the get_f() method on a null pointer. EDIT: This means one of your operands in a call to [color=#ff0000]bool cell_cmp::operator()(const std::shared_ptr<SearchCell>& a, const std::shared_ptr<SearchCell>& b) const is an empty shared_ptr.
  6. What optimization? Where else would it be "allocated" if not on the stack? Foo() creates a temporary. Of course it's on the stack.
  7. Yup, it's simply just UNDEFINED BEHAVIOR. May actually appear to work some of the time, or it may cause your computer to explode.
  8. Red Ant

    Disabling implicit conversions in typedefs?

    Not possible, I'm afraid. To the compiler, typedefs don't really introduce new types. EDIT: You _could_ derive both WorldPoint and ScreenPoint from Point.
  9. That problem won't really go away if you switch to pure C, though, except that you obviously won't be writing any classes. Instead you'll write a set of functions operating on a certain type of data and then change your mind the next day and rewrite them all. There are probably various third-party libraries available that provide somewhat generic data structures such as lists and so on. It's just that in C, "generic" usually means mucking around with void-Pointers and constantly casting to the type of data you're using the structure with.
  10. Red Ant

    What's wrong with OOP?

    Maybe instead of writing an article about why OOP kills baby seals, the guy should have read an article about web page design. Anyway, common sense says that a programmer who rejects OOP on principle is just as silly as one who won't consider using anything but OOP. There are problems that quite obviously benefit from the use of OOP while there are others that just as obviously benefit from the use of other paradigms. One doesn't have to waft through a dozen pages of diatribe to understand that.
  11. Red Ant

    Type not registering?

    What do you mean, "it started the compilation at"? Each translation unit (i.e. each .cpp file) always is compiled separately. What you include in one translation unit has no effects whatsoever on any of the other translation units. So if you have two .cpp's that both use vector2 then they both need to include vector2.h.
  12. Red Ant

    Type not registering?

    Either the code you showed us is not the code you're actually working with or there's ANOTHER vector2.h somewhere in your include paths that the compiler pulls in instead of the one you want. P.S. If you're using Visual Studio, you can configure the compiler to print out the path name of each included file during a compile run. That way you can see exactly what is getting included. (Configuration Properties -> C/C++ -> Advanced -> Show Includes) 2nd P.S. Under Configuration Properties -> C/C++ -> Preprocessor -> Preprocess to a file you can even make the compiler generate a file showing you exactly what code is emitted by the preprocessor. Open that file and see if you can find the definition of your vector2 struct. If you can't then for some reason it's not getting included.
  13. On top of what's been said above, your copy constructor doesn't really "initialize" per se; it assigns. Instead of this UsesA( const UsesA& other ) { mya = other.mya; } what you really want to do is this UsesA( const UsesA& other ) : mya( other.mya ) {} When writing constructors, it's generally advisable to prefer initialization lists over assignment.
  14. Hehe, yup. As soon as you get into embedded systems (where the OS might not protect you from your own stupidity in the way it does on a PC), a bad pointer could very well be the difference between a functioning machine and an accident involving human casualties.
  15. I don't think a static_cast is enough to do the trick. You will need a reinterpret_cast.
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!