From mboxrd@z Thu Jan 1 00:00:00 1970 From: Todd Hoff To: shiva@well.com Cc: C++ Embedded Subject: Re: static function tables Date: Mon, 29 Jun 1998 19:55:00 -0000 Message-id: <3598531C.99E95CB5@possibility.com> References: <3594A08B.6D84@compuserve.com> <35951205.2F8ACE6@possibility.com> <35982CA0.21E2@compuserve.com> X-SW-Source: 1998/msg00018.html Ken wrote: > The catch in this case is that the objects are static, and this is a > memory-limited embedded system where I don't want to copy a const array > of structures in ROM into equivalent C++ structures in RAM. This is kind > of a general problem in using C++ in a memory-limited environment. I would be inclined to overload the new operator and take the memory out of a static array or some other fixed source. Best of both worlds. In fact, in a memory constrained system i would overload the global new and allocate memory from pools of fixed sized buffers. Works best i think. >There > are cases where it would be nice to initialize static const C++ objects > at compile or link time (on the host) rather than just before main() (on > the target). Some say potatoes... > I've seen a trick lately (I think in Embedded Systems Programming) where > one exposes a C++ class that defines an internal private struct for the > static const data. Something like > > class public_class > { > private: > struct static_data { ... }; > static const static_data data[]; // stored in ROM > }; > > This looks applicable to the situation. This is the pimple pattern or the handle pattern. Works fine. Just better make sure your rom address is correct! ------------------------------------------------------------------ tmh@possibility.com http://www.possibility.com/Tmh Desperate measures require the invention of desperate times. -- Todd Hoff