Newsgroups: comp.lang.c++.moderated
From: wizof...@hotmail.com
Date: 2 Nov 2005 06:41:28 -0500
Local: Wed, Nov 2 2005 6:41 am
Subject: Possible with templates?
Ok, this is really just a "is there anyone who thinks this is a
worthwhile challenge" sort of query! Basically, I'm working on data structure design whereby all the objects Unfortunately, maps are problematic for two simple reasons: size and Now much of the time the properties required are known at compile time. int color = object.property(property_color); Basically, I need this to compile to code that isn't measurably slower int color = object.color; Furthermore, in order to reduce memory requirements, I've worked out I also know that each object has a key property - "type" - that With this in mind I came up with a system of macros that allows me to template <bool get> } I've comfirmed by looking at the disassembly and some performance testing that this does exactly what I want for cases where both the object type and property id are known at compile time, and for cases where one or the other or both are not (in fact, it's damn impressive the sort of optimizations compilers can do in this regard!). The 'both unknown at compile time' scenario pretty much only occurs when serializing, but even this can't afford to be as slow as a std::map lookup. The part I don't like about it is the GETSETPROP# macros, which need to #define SPROP(P, N) case P: assign<get>(p->m##N, value); return; }; \ I accept the casting will be necessary one way or another (or you could return; \ }; cheat and use a union), but this is really just a method of packing as much data as possible into a limited block of space. The obvious question is how much of this can be done with just template If I can scrap the macros entirely I would be very happy, but [ See http://www.gotw.ca/resources/clcm.htm for info about ] You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||