RE: [Algorithms] fundamentally better containers
Brought to you by:
vexxed72
From: Gribb, G. <gg...@ra...> - 2001-07-31 17:08:29
|
> Hey Gil, how do you do this? Do you just use a map<> or did > you write a bunch of your own container code? It seems like > making a fixed-size allocator that will work with vector is > pretty easy, but working with map<> and its whole rebind > mechanism seems pretty scary. Well, I certainly wouldn't want to write smap<> from scratch, so I wrote an allocator to do it. The rebind mechanism and allocators in general in stl apparently never designed for static allocation, which is unfortunate. With some hacky, stl implementation-specific code you can do it. But you need to know how the stl implementation works. If I were to do it again, I would probably just use a #define MAP_NODE_EXTRA, which is enough additional storage for a map node beyond the key and value size. Backedup up with asserts of course. This is even more hacky, but simpler. I needed these bad enough that good style wasn't going to get in the way. And once they are tested, and with appropriate asserts, they are safe and work very well. -Gil > > At 09:01 AM 7/31/2001 -0500, Gil wrote: > >My psx2 engine has no dynamic memory allocation at all. It uses STL > >extensively, but with static allocators, so for example: > > > >void foo() > >{ > > smap<float,CCollisionRecord,32> Collisions; > > .... > >} > > ---------------------------------------------------- > Charles Bloom cb...@cb... www.cbloom.com > > > _______________________________________________ > GDAlgorithms-list mailing list > GDA...@li... > http://lists.sourceforge.net/lists/listinfo/gdalgorithms-list > |