delegate !is null
Saaa
empty at needmail.com
Tue Sep 8 13:39:00 PDT 2009
"Steven Schveighoffer" <schveiguy at yahoo.com> wrote in message
news:op.uzyfzuvueav7ka at localhost.localdomain...
> On Tue, 08 Sep 2009 16:15:49 -0400, Saaa <empty at needmail.com> wrote:
>
>
>>>
>>> // dg is now a "instanceless" delegate to C.method.
>>>
>>> dg.ptr = new C;
>> So, nothing special under the hood, this would also work?
>> C c= new C;
>> dg.ptr = c;
>
> Yes, same thing.
>
>>> I also don't know how well it will work on interfaces.
>> Very nice :)
>> Might be useful, thanks.
>
> Just be cautious. You can get into undefined territory real easily,
> because dg.ptr is a void * (i.e. goodbye type system, I'm on my own!)
Ok, noted.
>
>>>
>>>> Kind of related:
>>>> If you delete an object and later create a new object, what are the
>>>> chances
>>>> they are located on the
>>>> same place (deleted.ptr is new.ptr) ?
>>>> Does the garbage collector try to reuse locations or is it the opposite
>>>> (or
>>>> random) ?
>>>
>>> The chances are non-zero :)
>> Are you quite sure there?
>
> very quite.
>
>> I'm only asking a single 'new'.
>> I mean, there could be some heuristic which would prevent the a new
>> object
>> to take the place of the latest deleted one.
>
> There isn't. Memory freed by the GC is able to be used in another
> allocation. If this didn't happen, then it wouldn't take long to use up
> all the memory in the system.
I didn't say a second new couldn't take the place of the delete ;)
> I'm sure if you threw random shit at the GC long enough, it would do this
> :)
>
> -Steve
More information about the Digitalmars-d-learn
mailing list