Berkeley CSUA MOTD:Entry 10248
Berkeley CSUA MOTD
 
WIKI | FAQ | Tech FAQ
http://csua.com/feed/
2025/05/29 [General] UID:1000 Activity:popular
5/29    

2003/9/18-19 [Computer/SW/Languages/Java, Computer/SW/Languages/C_Cplusplus] UID:10248 Activity:low
9/18    I have an embedded C++ application that passes around a lot of
        68-byte structs-- the struct is a wrapper around a binary message,
        and just about every function call includes one of them (usually
        passed by copy).  Today I changed the struct into a class which
        contains an empty Constructor/Destructor, and Configure() method
        which initializes every field.  Basically nothing else was changed:
        the 68-byte struct became a 72-byte object.  No inheritance, no
        virtual functions, everything is allocated on the stack.  My test
        suite is taking 300% longer to run, even with -O3.  Any ideas
        about what might be causing this?  I'm going to look into gprof,
        but if there are any hints and tips I'd like to hear them.  Thanks.
        \_ WAG: From your description, I gather you changed the definition
           from: struct Foo { ... }; to: class Foo { ... };
           Try changing "class" back to "struct" and see if that changes
           anything.
           \_ It does-- it cuts the running time by 2/3.  I've got 2
              parallel (except for the class stuff) directories and I'm
              running the tests side by side.
              \_ Well, are you passing these structs by value?  Are you
                 constructing and deconstructing tons and tons of classes
                 now?  Calling all those empty constructors and deconstructors
                 can get quite expensive.  Also do you have RTTI turned on?
                 That could explain the extra bytes,
                 \_ I don't have RTTI on explicitly (how would I check?),
                    and I'm not using any template stuff.  The compiler is
                    gcc 3.2.  Is there a way to optimize the (de|con)structor
                    calls to nothing?  I had figured that -O2 would take
                    care of that for me.  Also, I think that extra 4 bytes
                    is just a pointer to the dispatch table, which is
                    completely expected. --op
                    \_ If you have no virtual functions you don't have a
                       dispatch table, and you shouldn't have a pointer.
                       Trust me when your basic math objects are classes
                       and you have umpty millions of them, doubling the
                       size for a dispatch pointer would be really annoying.
                       \_ Aaah!  You're totally right.  Out of habit I had
                          put "virtual ~Foo() { };".  I removed the virtual
                          and the code is now about 5-10% *faster* than the
                          struct version.  Thank you thank you thank you.
              \_ Two more suggestions: Did you define Configure() in the
                 header file? If so, move it to the implementation file
                 and see if that makes a difference. Also, try compiling
                 with -Os, which optimizes for size (at least on my
                 gcc).          - struct guy
                 \_ Configure is defined in the .cc file; I'll give -Os
                    a shot now.
                    \_ Try swapping the the definition of the ctor/dtor
                       and Configure from .cc to .h or vice-versa.
        \_ Why did you change working code in the first place?  That's where
           your real problem is.
           \_ Obviously so he could put C/C++ on his resume!
2025/05/29 [General] UID:1000 Activity:popular
5/29    

You may also be interested in these entries...
2013/5/1-18 [Computer/SW/Languages/Java, Computer/Theory] UID:54669 Activity:nil
5/1     What's the difference between CS and Computer Engineering?
        http://holykaw.alltop.com/top-ten-paying-degrees-for-college-graduates
        \_ One is science and the other is engineering.
        \_ From http://en.wikiquote.org/wiki/Computer_science
           'A folkloric quotation ... states that "computer science is no more
           about computers than astronomy is about telescopes."  The design
	...
2012/12/4-18 [Computer/SW/Languages/Java] UID:54544 Activity:nil
12/4    Holy cow, everyone around me in Silicon Valley is way beyond
        middle class according to Chinni's definition:
        http://en.wikipedia.org/wiki/American_middle_class
        \_ Let's set our goals higher:
           http://en.wikipedia.org/wiki/Upper_middle_class_in_the_United_States
           \_ How about this one?
	...
2012/10/29-12/4 [Science/Disaster, Computer/SW/Languages/Java, Politics/Domestic/President/Bush] UID:54516 Activity:nil
10/29   Go Away Sandy.
        \_ Sorry, Coursera is performing preventive maintenance for this
           class site ahead of Hurricane Sandy. Please check back in 15 minutes.
           class site ahead of Hurricane Sandy. Please check back in 15
           minutes.
        \_ Bitch.
	...
2012/1/18-3/3 [Computer/SW/Languages/Java, Finance/Investment] UID:54290 Activity:nil
1/18    I own a bunch of NFLX stocks bought at several different periods
        (from high $200 all the way down to $80). I dumped a few and
        still have a few. Why the hell is Reid Hastings still making
        $500,000/year? How do I join the pending NFLX Class Action
        Lawsuit?
        \_ Why would you buy stock in a company run by a narcissistic
	...
2012/7/19-11/7 [Computer/SW/Languages/C_Cplusplus] UID:54439 Activity:nil
7/19    In C or C++, how do I write the code of a function with variable
        number of parameters in order to pass the variable parameters to
        another function that also has variable number of parameters?  Thanks.
        \_ The usual way (works on gcc 3.0+, Visual Studio 2005+):
               #define foo(fmt, ...) printf(fmt, ##__VA_ARGS__)
           The cool new way (works on gcc 4.3+):
	...
2004/10/29-30 [Computer/SW/Languages/C_Cplusplus] UID:34449 Activity:very high
10/29   C++ is so freaking BROKEN.  Augh!
        \_ Just use C.
           \_ Would if I could.
        \_ No, you are.  C++ works just fine, and far better than C for many
           purposes.
           \_ C vs. C++.  FIGHT!!!
	...
2004/4/13-14 [Computer/SW/Languages/C_Cplusplus] UID:13175 Activity:high
4/13    How much C++/C knowledge do recent Berkeley CS/EECS grad have?
        \_ Class CSGrad inherits FromDaddy and does not implement C++Knowledge
           very well.
           \_ funny.  just the rich and poor as always.  the middle class can't
              afford education.
        \_ They know how to deal with pointers and addresses, malloc and free.
	...
2004/3/30-31 [Computer/SW/Languages/Perl] UID:12925 Activity:kinda low
3/17    In Perl, how do I make variables have static types and type check
        for valid parameter/actuals? I realize that variables are untyped
        in Perl ($var can be 0.001 or "hello") but I'd like to have more
        strict checking so that errors would be caught ahead of run-time,
        Thanks,                                                 -java guy
        \_ use java.  Seriously.  You don't use perl if you want strong
	...
2002/11/5 [Computer/SW/Languages/C_Cplusplus] UID:26409 Activity:high
11/4    I'm having a problem formatting inline elements in xsl-- I have to
        handle the situation where
        <school>I graduated from
          <link href="<DEAD>www.berkeley.edu"<DEAD>Cal</link> in 1998.
        </school>
        My current template is like this:
	...
2000/11/21 [Computer/SW/Languages/C_Cplusplus, Computer/SW/Languages/Java] UID:19871 Activity:very high
11/21   All java class inherites from class *Object*, if I have three classes
        A, B, and C all have one same method showErr().  If I want to have a
        function that can call showErr() depending on the object that I passed
        in, eg.
                public void handleErr(Object o) {
                        o.showErr();
	...