View mode: basic / threaded / horizontal-split · Log in · Help
June 21, 2011
Re: what to do with postblit on the heap?
(resending)

On 6/21/11 11:13 AM, so wrote:
> On Tue, 21 Jun 2011 18:18:26 +0300, Michel Fortin
> <michel.fortin@michelf.com> wrote:
>
>> Actually, no copy is needed. Move takes the argument by ref so it can
>> obliterates it. Obliteration consists of replacing its bytes with
>> those in S.init. That way if you have a smart pointer, it gets
>> returned without having to update the reference count (since the
>> source's content has been destroyed). It was effectively be moved, not
>> copied.
>
> T move(ref T a) {
> T b;
> move(a, b);
> return b;
> }
>
> T a;
> whatever = move(a);
>
> If T is a struct, i don't see how a copy is not needed looking at the
> current state of move.

The rule that move and TDPL rely on but is not fully implemented is that 
returning a nonstatic local value never does a postblit nor a destructor 
- it just copies the bits.

Andrei
June 21, 2011
Re: what to do with postblit on the heap?
On Jun 21, 2011, at 11:26 AM, Andrei Alexandrescu wrote:
> 
> The rule that move and TDPL rely on but is not fully implemented is that returning a nonstatic local value never does a postblit nor a destructor - it just copies the bits.

So it's effectively illegal to have a struct containing a pointer that references itself, correct?
June 21, 2011
Re: what to do with postblit on the heap?
On 6/21/11 4:24 PM, Sean Kelly wrote:
> On Jun 21, 2011, at 11:26 AM, Andrei Alexandrescu wrote:
>>
>> The rule that move and TDPL rely on but is not fully implemented is that returning a nonstatic local value never does a postblit nor a destructor - it just copies the bits.
>
> So it's effectively illegal to have a struct containing a pointer that references itself, correct?

Illegal. All D structs must be transparently relocatable without 
breaking their invariant.

Andrei
Next ›   Last »
1 2 3
Top | Discussion index | About this forum | D home