Objective-D, reflective programming, dynamic typing

dsimcha dsimcha at yahoo.com
Sun Apr 5 20:14:48 PDT 2009


== Quote from Andrei Alexandrescu (SeeWebsiteForEmail at erdani.org)'s
> 2. In storing structs larger than a threshold. I know how to do that and
> there's a bugzilla on it, just haven't gotten around to implementing it.

I'm looking at this and thinking about how to implement it and submit it.  One
issue is how to store the information about whether the payload is stored inline
or on the heap.  Obvious solutions like sticking an extra bool in the VariantN
struct wouldn't work because this thing is supposed to be uber-efficient.
Querying the typeinfo every time to compare size information is also a bad idea
for similar reasons.

It seems a VariantN struct consists (in terms of fields) of a ubyte[size] array
and a function pointer for handler.  When stuff is allocated on the heap, I can
store the pointer to it in the ubyte[size], provided that size >= void*.sizeof.
In real world use cases, there aren't too many good reasons to use a Variant with
size smaller than a pointer, so I'm thinking just make the minimum size
void*.sizeof.  The problem, though, is encoding whether the data is on the heap or
inline in an efficient way.  Any clever hacks like storing this information in
some unimportant bits of something else?



More information about the Digitalmars-d mailing list