This, as well as many other patterns like these exist in the
C-programming world. In order for a compiler to reason about it requires
it to know about regions as well as sizes and assumptions based on the
data within memory areas.
In your case, you must simply assume that FileSystem::Open() properly
constructs an object in the destination region (check while compiling
Open()), and that the memory area given to it is less than Open()'s
requirements (on usage).
Another example, that is similar but shows what can be done in C,
reusing existing data (both static and heap allocated objects) as
something completely different, simply because it is "known" that those
objects are dead. A simple example would be something like this:
struct UninitializedObject
{
bool isInitialized;
int uniqueId;
int anotherObjectId;
int payload;
};
struct ActualObject
{
bool isInitialized;
OtherObject *other;
float neatValue;
};
And after loading the unitialized object, you do:
ActualObject *InitializeObject(UninitializedObject *o)
{
assert(!o->isInitialized);
int uId = o->uniqueId;
int oId = o->anotherObjectId;
int d = o->someInitializationData;
int p = o->payload;
ActualObject *n = (ActualObject *)o;
// Fill n with valid values.
Factory::RegisterObject(uId, n);
n->other = Factory::LookupObject(oId);
n->neatValue = SomeFunction(n, n->other);
n->isInitialized = true;
return n;
}
This pattern is useful for tight memory architectures, and is "safe" as
long as
1. isInitialized is guaranteed to be false for all UninitializedObject's.
2. sizeof(ActualObject) <= sizeof(UninitializedObject).
3. No reference to ActualObject is used without checking or "knowing"
that isInitialized is true.
I am not aware of any system that allows these kinds of reuse.
PKE
_______________________________________________
bitc-dev mailing list
[email protected]
http://www.coyotos.org/mailman/listinfo/bitc-dev