Boost logo

Boost Users :

From: Arno Schödl (aschoedl_at_[hidden])
Date: 2006-02-12 12:58:51


Hello,

here is my problem: I have a complex data type, like a std::vector< std::string > and need some global constant values of this type. The type is also used non-constant throughout the program, so I do not want to use dumb types, but rather STL containers.

In an ideal world, initialization of these constants would not happen at runtime, but at compile time, essentially generating a
constant memory image of this type via meta-programming. The exact memory layout is compiler-dependent, of course, but the difficult, but portable part would be the programmer's interface, in particular for nested types and user-defined ones.

Why do I want this? Start-up time is a big problem for larger apps, and CRT init code filling std::vectors with stuff causes lots of page faults slowing down the start. This is particularly annoying if the constant never happens to be used in that particular run. And of course it is inelegant to keep data around twice, once in dumb constant arrays, and once on the heap after the containers have been filled from these arrays.

Why can't I use POD arrays for constant data instead of STL containers? Because the same data type is often used both const (for default values, to list possible choices in menus, etc.) and non-const (for user-defined values). Unifying the access would be awfully convenient.

I have implemented this approach with the boost preprocessor library for MSVC 8 std::vector< integral type >, which works, but is nowhere general enough. Has anyone else made attempts in this direction?

Arno


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net