On Friday, 12 March 2021 at 17:37:43 UTC, David Zhang wrote:
I want to store interfaces as untyped void[], then cast them
back to the interface at a later time. However, it appears to
produce garbage values on get().
Is this even possible, and if so, what is happening here? The
alternative would be a struct { CheckedPtr self; api_fns.... }
e.g.
void register(I)(I i) {
auto mem = new void[](I.sizeof);
memcpy(mem.ptr, cast(void*) i, I.sizeof);
// CheckedPtr includes a hash of fullyQualifiedName
map[i.get_name()] = CheckedPtr!I(mem.ptr);
}
I get(I)() {
// basically cast(I) p
return map[I.get_name()].as!I();
}
Maybe I don't get this right but why you don't just use the
void[] as it is?
void[] mem = [i];
//...
return (cast(T[]) mem)[0];
This is how I exchange variable data between DLLs.