[uClinux-dev] C++ code size problem

Michael Caisse mcaisse at allweatherinc.com
Mon Mar 24 14:30:27 EST 2003


Dominique -

I'm happy share what I can. I've attached my EmbeddedDeque class. I'm 
unable to share the other containers. I've only implemented the 
interface portions that I need. I use the class in both ucLinux and 
non-OS targeted applications. The container supports a fixed number of 
elements that is declared as one of the template parameters. As a result 
it may not be relevant for your application, but it may give you an idea.

Best of luck.

michael


Van Rafelghem, Dominique wrote:

> michael,
>
> Thanks for the info.  I guess using printf's will work for now, as for 
> using STL on the ColdFire it probably isn't going to be easy due to 
> the frequent memory allocation and deallocation.
>
> I will look into writing my own STL templates also.  I don't know if 
> you're willing or able to share you're STL classes you have developed, 
> but any hints would be appreciated.
>
> Dominique
>
> -----Original Message-----
> From: Michael Caisse [mailto:mcaisse at allweatherinc.com]
> Sent: Monday, March 24, 2003 8:45 AM
> To: uclinux-dev at uclinux.org
> Subject: Re: [uClinux-dev] C++ code size problem
>
>
> Dominique -
>
> This may not be too helpful, but adding wide character support is going
> to increase your binary size considerably. Using iostreams will also
> greatly increase your binary size. There are many constructs in C++ that
> are quite handy and require little or no memory overhead. The key with
> C++ in an "embedded" application is to know what the footprint and cycle
> impacts are of varying constructs and to weigh them with their coding
> benifits.
>
> I have created a group of STL similar collections such as the deque for
> embedded systems. They are templated classes that don't rely on dynamic
> memory allocation but instead use placement new. As a result they are
> somewhat limited but can be used without an OS and still provide the
> coding ease of STL containers.
>
> If your application doesn't need wide character support, you should
> remove the dependencies for it. For debugging purposes don't use
> iostreams, stick with printf to keep the memory footprint smaller.
>
>
> michael caisse
>
>
>
>
> Van Rafelghem, Dominique wrote:
>
> > Hi,
> >
> > I am currently writing some code to check out uClinux on a ColdFire
> > processor.  The test platform I am using is the Motorola M5272C3 demo
> > board.  I am using the uClinux-dist-20030305.tar.gz kernel and the
> > m68k-elf-tools-20030314.  One change I've made to the uClinux
> > configuration is to allow wide characters as I was getting compilation
> > problems with my C++ code when I didn't have wide characters turned on
> > in the uClibc configuration.
> >
> > I wrote a simple C++ programs that instantiates a class and uses an
> > STL vector container class.  The code size jumps tremendously when I
> > include the STL stuff.  But when I add a cout statement using the
> > iostreams header file the code size of my application jumps from ~ 100
> > kbytes to ~400 kbytes.  This is a huge jump in code size and
> > unfortunately I can't run this on the demo board as it crashes
> > complaining that it doesn't have enough memory.
> >
> > The following is a my build script that I am using to build the
> > application:
> > # script start
> > m68k-elf-g++ -m5307 -DCONFIG_COLDFIRE -Os -g -fomit-frame-pointer
> > -m5307 -DCONFIG_COLDFIRE  -Dlinux -D__linux__ -Dunix -D__uClinux__
> > -DEMBED \
> >
> > 
> -I/home/VanRafelghemD/uClinux-20030305/uClinux-dist/lib/uClibc/include \
> > -I/home/VanRafelghemD/uClinux-20030305/uClinux-dist/lib/libm \
> > -I/home/VanRafelghemD/uClinux-20030305/uClinux-dist/lib/libcrypt_old \
> > -I/home/VanRafelghemD/uClinux-20030305/uClinux-dist -fno-builtin
> > -msep-data \
> > 
> -I/home/VanRafelghemD/uClinux-20030305/uClinux-dist/linux-2.4.x/include    
>
> > -c -o testapp.o testapp.cpp
> >
> > m68k-elf-strip --strip-debug testapp.o
> >
> > m68k-elf-g++ -m5307 -DCONFIG_COLDFIRE -Os -g -fomit-frame-pointer
> > -m5307 -DCONFIG_COLDFIRE  -Dlinux -D__linux__ -Dunix -D__uClinux__
> > -DEMBED \
> >
> > 
> -I/home/VanRafelghemD/uClinux-20030305/uClinux-dist/lib/uClibc/include \
> > -I/home/VanRafelghemD/uClinux-20030305/uClinux-dist/lib/libm \
> > -I/home/VanRafelghemD/uClinux-20030305/uClinux-dist/lib/libcrypt_old \
> > -I/home/VanRafelghemD/uClinux-20030305/uClinux-dist \
> > -fno-builtin -msep-data
> > 
> -I/home/VanRafelghemD/uClinux-20030305/uClinux-dist/linux-2.4.x/include \
> > -mapcs-26 -Wl,-elf2flt -Wl,-move-rodata -nostartfiles
> > 
> /home/VanRafelghemD/uClinux-20030305/uClinux-dist/lib/uClibc/lib/crt0.o \
> >
> > -o testapp testapp.o -lc -lgcc
> > #script end
> >
> > This is the code I am compiling:
> >
> > // start C++ code
> > //#include <iostream>
> > #include <vector>
> > #include <stdio.h>
> >
> > using namespace std;
> >
> >
> > class Test
> > {
> >         public:
> >                 Test(int TestNo);
> >                 int storeTestNo(void);
> >                 ~Test();
> >         private:
> >                 std::vector<int> v;
> >                 int m_TestNo;
> > };
> >
> > Test::Test(int TestNo) : m_TestNo(TestNo)
> > {
> >         printf("Test no %d, constructed\n", m_TestNo);
> >         v.reserve(80);
> > }
> >
> > Test::~Test()
> > {
> >         printf("Test no %d, destroyed\n", m_TestNo);
> > }
> >
> > int Test::storeTestNo(void)
> > {
> >         v.push_back(m_TestNo);
> >         printf("Test no %d stored in v\n", m_TestNo);
> >         return v.size();
> > }
> >
> > int main(void)
> > {
> >         Test * Testp = new Test(1);
> >         int size = Testp->storeTestNo();
> >         printf("vector size is %d\n", size);
> > //      cout << "cool" << endl;
> >         delete Testp;
> > }
> >
> > // end C++ code
> >
> > This code snippet has the cout and iostream header file commented
> > out.  As is this application will be ~100 kbytes which is huge for
> > what it does.  But when you remove the comments from the iostream
> > header and the cout statement the code size jumps to 400 kbytes.  When
> > I compile the same code on my linux box using gcc the code size of the
> > non-cout file is 25 kbytes, with cout the code size is 26 kbytes. 
> > Does anyone have any idea why the m68k-elf-g++ code is so large and is
> > there any way to reduce this code size?  Any help with this would be
> > greatly appreciated.
> >
> > Dominique
> >
>
>
> _______________________________________________
> uClinux-dev mailing list
> uClinux-dev at uclinux.org
> http://mailman.uclinux.org/mailman/listinfo/uclinux-dev
> This message was resent by uclinux-dev at uclinux.org
>

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: EmbeddedDeque.h
URL: <http://mailman.uclinux.org/pipermail/uclinux-dev/attachments/20030324/28ef5384/attachment.h>


More information about the uClinux-dev mailing list