| |
 | Posted by Nicolas Silva in reply to Steven Schveighoffer | Permalink Reply |
|
Nicolas Silva 
| Ok thanks!
You said "the current GC", do you mean that this behavior might change in the future?
> Well, first of all, what is T? If T is a class, you would not cast void * to T*, you almost never use T* since T is already a reference. You could cast void * to T.
I am making a sort of visual scripting system with nodes connected
through inputs and outputs. Nodes perform some processing and receive
data in an abstract form because the surrounding system doesn't know
about the types. So I'm hesitating between passing Object references
and void* pointers. I don't want to limit the parameters to classes so
I could use a Wrapper!T that would contain a pointer to the struct
whenever I need a struct. I am not yet sure whether I want to pass a
reference to a class and let the cast(T) do the type safe checking or
if I want to pass the data along with some hand made runtime type
information and ensure type safety by hand (that's what I did in the
C++ version of the lib)
anyway T might be a class or a struct and I might just access the
struct case with a proxy class I am not sure yet.
I guess passing data in a generic form from a system to another is a common problem and if you guys already had an experience in dealing with this in D and/or are aware of an elegant way to do it i'd be interested to know about it.
Best,
Nicolas Silva
On Thu, Jan 26, 2012 at 4:38 PM, Steven Schveighoffer <schveiguy@yahoo.com> wrote:
>
> On Wed, 25 Jan 2012 19:11:36 -0500, Nicolas Silva <nical.silva@gmail.com> wrote:
>
>> Hi,
>>
>> I need to be sure: would the GC collect an object that is still reachable through a void* pointer ?
>
>
> No. The current GC does not know anything about type information. It blindly assumes if a pointer points to some block of data, that block of data is still in use.
>
>
>> Also, is there a big difference between casting from Object to T and casting from void* to T* ?
>
>
> Well, first of all, what is T? If T is a class, you would not cast void * to T*, you almost never use T* since T is already a reference. You could cast void * to T.
>
> Casting Object to T if T is a class is going to be a dynamic cast, returning null if the object in question is not actually a T. If you know it is a T, then doing a cast to void * first, then to T will circumvent the dynamic cast.
>
>
>> I mean in term of speed. It looks like could be the same difference as between C++'s dynamic_cast and static_cast but i'd like to be sure as well.
>
>
> Exactly.
>
> -Steve
|