• Advertisement

Red Ant

  • Content count

  • Joined

  • Last visited

Community Reputation

471 Neutral

About Red Ant

  • Rank
    Advanced Member
  1. 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. Java vs C++ research paper

    [quote name='Ripiz' timestamp='1335692202' post='4935784'] C++ compiler tends to destroy loop as everything is constant (volatile fixes that) [/quote] I'm sorry, but what do you mean by that?
  4. Segmentation fault on std::sort

    Oops, sorry. Shame on me for not reading the whole thread before posting. [img]http://public.gamedev.net//public/style_emoticons/default/sleep.png[/img]
  5. Segmentation fault on std::sort

    [quote name='AlanSmithee' timestamp='1335129380' post='4933871'] And the debug call stack: #0 00424842 SearchCell::get_f([color=#ff0000]this=0x0[/color]) (C:/Projects/Individuellt Mjukvaruutvecklingsprojekt/Game/DungeonsOfZiro/files/SearchCell.h:33) [/quote] 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[/color] is an empty shared_ptr.
  6. [quote name='Ripiz' timestamp='1335301295' post='4934543'] Possibly it's an optimization causing object to be allocated on the local stack [...] [/quote] 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. 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. [quote name='smile55' timestamp='1333006533' post='4926250'] Many times I define a class and soon I will feel the design is bad, making the problem more complex. Sometimes I define a lot interfaces today and change all my minds tomorrow and re-write them all.[/quote] 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. [quote name='smile55' timestamp='1333006533' post='4926250'] So I want to know how does professional C programmer write their daily codes? For example, when a linked list is used to organize some data, will you directly operate the pointer to next node in the application's algorithm, or will make an abstraction to hide the details of linked list? [/quote] 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. What's wrong with OOP?

    [quote name='Rickert' timestamp='1331894194' post='4922545']Among those are Paul Graham's and he series of articles on this site: [url="http://www.geocities.com/tablizer/oopbad.htm"]http://www.geocities...izer/oopbad.htm[/url] (I haven't read all, since I don't have much time). [/quote] 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. Type not registering?

    [quote name='Nyxenon' timestamp='1331852665' post='4922419'] Apparently the compiler was starting the compilation at "vector3.cpp" [...] [/quote] 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. 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 [b]Configuration Properties -> C/C++ -> Preprocessor -> Preprocess to a file[/b] 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 [code] UsesA( const UsesA& other ) { mya = other.mya; } [/code] what you really want to do is this [code] UsesA( const UsesA& other ) : mya( other.mya ) {} [/code] When writing constructors, it's generally advisable to prefer initialization lists over assignment.
  14. [quote name='Nypyren' timestamp='1331691834' post='4921854'] At some point, your bad pointer may eventually be the cause of anything and everything the physical hardware is capable of (and anyone you're networked with.) The worst that could happen? Your program causes the LHC to create an transdimensional rift which annihilates the universe. [size=3][i]Don't cross the std::streams![/i][/size] [/quote] 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