Shop OBEX P1 Docs P2 Docs Learn Events
Pure Virtual Functions Cause Instant Code Bloat - Page 3 — Parallax Forums

Pure Virtual Functions Cause Instant Code Bloat

13»

Comments

  • SRLMSRLM Posts: 5,045
    edited 2013-11-22 19:50
    Heater. wrote: »
    Seems this is faster than using inheritance but eats more memory.

    CRTP doesn't consume any extra resources, at least in this test:
    #include "libpropeller/serial/serial.h"
    #include "libpropeller/streaminterface/streaminterface.h"
    int main() {
        Serial debug;
        debug.Start(31,30, 115200);
        debug.Put("Hello World\r\n");
        //----------------------------------------
        
        OutputStream<Serial> * si = &debug;
        si->Put("Hello, OutputStream\r\n");
        
        // OR
        
        //debug.Put("Hello, OutputStream\r\n");
        
        //----------------------------------------
        debug.Put((char) 0xFF);
        debug.Put((char) 0x00);
        debug.Put((char) 0);
        
        return 0;
    }
    

    Where I have it output the same either directly or via the CRTP. Both times compiled to 2996 bytes.
  • Heater.Heater. Posts: 21,230
    edited 2013-11-22 20:04
    Roy,

    Sounds like you have been in the trenches with C++. Thanks for the war stories.

    Pretty much all the C++ I have ever written has been for space constrained Linux based embedded systems. It's always had to run on Mac and Windows if only so that developers can work on it with their favorite machines and tools. Insisisting on cross-platform operation also shows up all kinds of bugs and other weirdness in your code.

    Most of the time I don't even like to use any new/delete, having worked on small real time systems for so long I get nervous about the non-deterministic nature of any kind of memory allocation.

    Other than that it's been simple Qt based GUI stuff.

    As such the STL is unfamiliar ground for me and Boost is on another planet.
  • Heater.Heater. Posts: 21,230
    edited 2013-11-22 20:13
    SRLM,

    Templates, as used in CRTP, are wonderful things. Templated class definitions and such can be very long, complicated, ugly and incomprehensible. But after all that they don't actually generate any code.
  • Roy ElthamRoy Eltham Posts: 3,000
    edited 2013-11-22 21:16
    Heater,
    Yeah I have been working on C++ codebases for something like 16+ years. Some of which have been multi-million line monsters with many exe's and dll's sharing code and needing to work on multiple platforms.

    In embedded land I've not really done any C++. Plenty of C and ASM, and of course some Spin/PASM. I'm just starting to use some C++ in a project I'm working on for the Prop (on a custom board).
Sign In or Register to comment.