compiler support added for precise GC

Jacob Carlborg doob at me.com
Tue Apr 17 01:53:50 PDT 2012


On 2012-04-17 10:13, Walter Bright wrote:
> On 4/17/2012 1:10 AM, Walter Bright wrote:
>> How would you know if they are or aren't, when dynamically loading stuff?

I'm not entirely sure what you mean by "dynamically loading stuff". The 
only types you can create dynamically are objects:

auto b = Object.factory("Bar");

D has a limited set of types and a couple of user definable types, like 
classes, structs and so on. So in my serialization library it's 
basically hard coded what's serializable or not. All primitive types, 
int, char, string and so on are serializable. All classes and structs 
are serializable as well.

It essentially works like this. You always need to start with a static 
type, like this:

struct Foo { ... }

auto a = deserialize!(Foo)(data);

 From that I can figure out most of the things via compile time 
reflection. What's not possible is when the runtime type is different 
from the static type:

class Base { ... }
class Sub : Base { ... }

Base b = new Sub;

In the above code, when inspecting "b" using compile time reflection all 
information about "Sub" is gone. It's just a regular "Base".

> Essentially, I'm concerned with a vast amount of data being generated
> for every type and inserted into the executables (which are already
> large).

Most of the data is already available in the symbol table anyway. 
Instance methods, static methods and static variables. What's missing is 
basically instance variables and an easy way to access them.

> Even worse, I'm concerned that such a feature will not "just
> work" when one wants to serialize a class that wasn't designed to be
> serialized, and it'll come off as a crappy half-assed buggy misfeature.

Sure that can always happen. But as long as the data is there it's up to 
the serialization library how to use it. When serializing third party 
types not explicitly made for serializing it would be up to the user to 
know what he/she's doing. I mean, this is a system programming language 
just as you can cast away shared an similar.

Feel free to use my serialization library and see what it can handle:

https://github.com/jacob-carlborg/orange

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list