This is the mail archive of the
c++-embedded@sourceware.cygnus.com
mailing list .
Re: static function tables
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