Menu

#890 Improve implementation of constructors

open
nobody
icewm-1.3 (100)
5
2012-01-04
2012-01-04
No

Discussion

  • Eduard Bloch

    Eduard Bloch - 2012-01-05

    In theory, you are right.

    In practice... seriously, WTF? Every normal C++ compiler from the last decade should be able to optimize trivial assignment lists as needed.

     
  • Markus Elfring

    Markus Elfring - 2012-01-05

    Would you also like to consider any adjustments for the initialisation of pointer member variables?

    Update candidates:
    - fMotion = new XMotionEvent;
    - fDocked = new YXEmbedClient(this, this, win);
    - cpu = new int *[taskBarCPUSamples];
    - fUpdateTimer = new YTimer(taskBarCPUDelay);
    - clockTimer = new YTimer(1000);
    - ppp_in = new long[taskBarNetSamples];
    - ppp_out = new long[taskBarNetSamples];
    - fUpdateTimer = new YTimer();
    - tray = new SysTray();
    - fClientContainer = new YClientContainer(this, this);
    - fTitleBar = new YFrameTitleBar(this, this);
    - Other constructors: TextView, HTextView, IceSame, AboutDlg, CtrlAltDelete

    How do you think about to reuse the class "std::unique_ptr"?
    http://en.wikipedia.org/wiki/Smart_pointer#C.2B.2B_Smart_Pointers

     
  • Eduard Bloch

    Eduard Bloch - 2012-01-05

    I don't know what Marko thinks, here is my opinion:

    Using C++11 features just for the sake of code beautification is not worth it.

    If you can safe time or enhance code safety (or both) then we might talk about it, but in this case, what's the point? Those member variables are private and only allocated on heap in order to keep the stack size sane, and they are never passed around. The only good reason for auto_ptr (and family) might be the work around exception handling in constructors... but icewm does not use exceptions so that point is void.

     
  • Eduard Bloch

    Eduard Bloch - 2012-01-07

    @elfring: I suggest that you start your problem description with telling what the actual problem is ("here: new throws std::bad_alloc") and not with throwing buzzwords and imprecise RTFM hints at people. No offense implied.

    @Marko: unfortunately, he has a point. std::bad_alloc is thrown by the libstdcxx's implementation of malloc so using -fno-exceptions does not really help. On Debian, I link with libsupc++ but even that one throws std::bad_alloc (for some reason I assumed the opposite).

     
  • Eduard Bloch

    Eduard Bloch - 2012-01-08

    PS: double-thinking about it, I guess the problem can be "solved" by replacing the normal new/delete operators with non-throwing versions, see http://www.informit.com/guides/content.aspx?g=cplusplus&seqNum=40 for example (just the other way round).

     
  • Markus Elfring

    Markus Elfring - 2012-01-08

    If you do not want to support exception handling, you do not need to change the mentioned source code places because the compiler parameter "-fno-exceptions" should have got the effect that your program will be eventually aborted.
    http://gcc.gnu.org/onlinedocs/libstdc++/manual/using_exceptions.html#intro.using.exception.no

    But I hope that you are interested to improve your software a bit more.

     

Log in to post a comment.