C++ pure virtual base class memory consumption
Sebastian Huber
sebastian.huber@embedded-brains.de
Thu Aug 23 09:45:00 GMT 2012
On 08/20/2012 08:52 PM, fueb wrote:
>
> Hi out there, I hope someone can give me a hint on a problem building a c++
> static library using newlib and lpcxpresso. Everything works fine, but I
> have a size-problem.
>
> I have got a class that has pure virtual methods. Another class derives this
> base class and implements the function:
>
> Code:
>
> class A {
> public:
> virtual void method() = 0;
> }
> class B : public A {
> virtual void method() { // do something }
> }
>
> Using the above code links appr. 60kB more code from newlib into the
> application than if I use the following code, where the base class method is
> already implemented but overwritten in the derived class:
Are you sure this code is from Newlib and not GCC?
>
> Code:
>
> class A {
> public:
> virtual void method() {} // <-- the only change
> }
> class B : public A {
> virtual void method() { // do something }
> }
>
> I know that gcc for other small devices is capable to build this with
> smaller code, probably with a commandline switch, but I do not know how.
>
> Does someone have a hint on how I could prevent the compiler to
> auto-implement that much functions used for the pure virtual class?
>
I suppose this is due to the abort handler with pretty printing pulled in by a
pure virtual function. You should look at the map file of the linker. See also
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43852
--
Sebastian Huber, embedded brains GmbH
Address : Obere Lagerstr. 30, D-82178 Puchheim, Germany
Phone : +49 89 18 90 80 79-6
Fax : +49 89 18 90 80 79-9
E-Mail : sebastian.huber@embedded-brains.de
PGP : Public key available on request.
Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.
More information about the Newlib
mailing list