Thread overview | ||||||
---|---|---|---|---|---|---|
|
September 02, 2010 [phobos] swap() | ||||
---|---|---|---|---|
| ||||
A few questions about std.algorithm.swap() that came up when I was reading the code to fix Bug 4789: 1. Do we really need to use memcpy() for structs w/o a postblit? I can't see any advantages and it seems like it might be less efficient, since for a struct without a postblit just using plain old assignment should be about as efficient as it gets. 2. memcpy() isn't guaranteed to work for overlapping memory blocks. Shouldn't there be a check in to make sure a and b don't have the same address? |
January 01, 2011 [phobos] swap() | ||||
---|---|---|---|---|
| ||||
Posted in reply to David Simcha | This has been lying in my inbox for a good while. I see now the bug is fixed. Any trailing questions regarding it?
Andrei
On 9/2/10 10:58 PM, David Simcha wrote:
> A few questions about std.algorithm.swap() that came up when I was
> reading the code to fix Bug 4789:
>
> 1. Do we really need to use memcpy() for structs w/o a postblit? I can't see any advantages and it seems like it might be less efficient, since for a struct without a postblit just using plain old assignment should be about as efficient as it gets.
>
> 2. memcpy() isn't guaranteed to work for overlapping memory blocks.
> Shouldn't there be a check in to make sure a and b don't have the same
> address?
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos
|
January 02, 2011 [phobos] swap() | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | Well, bug 4789 is fixed for static arrays but reintroduced for structs
with elaborate assign.
Array copy is not allowed for overlapping memory.
ubyte[T.sizeof] t = void;
auto a = (cast(ubyte*) &lhs)[0 .. T.sizeof];
auto b = (cast(ubyte*) &rhs)[0 .. T.sizeof];
t[] = a[];
a[] = b[]; <-- will raise exception
b[] = t[];
Martin
On Sun, 02 Jan 2011 00:42:44 +0100, Andrei Alexandrescu <andrei at erdani.com> wrote:
> This has been lying in my inbox for a good while. I see now the bug is fixed. Any trailing questions regarding it?
>
> Andrei
>
> On 9/2/10 10:58 PM, David Simcha wrote:
>> A few questions about std.algorithm.swap() that came up when I was
>> reading the code to fix Bug 4789:
>>
>> 1. Do we really need to use memcpy() for structs w/o a postblit? I can't see any advantages and it seems like it might be less efficient, since for a struct without a postblit just using plain old assignment should be about as efficient as it gets.
>>
>> 2. memcpy() isn't guaranteed to work for overlapping memory blocks.
>> Shouldn't there be a check in to make sure a and b don't have the same
>> address?
>> _______________________________________________
>> phobos mailing list
>> phobos at puremagic.com
>> http://lists.puremagic.com/mailman/listinfo/phobos
|
January 11, 2011 [phobos] swap() | ||||
---|---|---|---|---|
| ||||
Posted in reply to Martin Nowak | I'm not sure I understand where the brokenness is. Could you please post to http://d.puremagic.com/issues/show_bug.cgi?id=4789 an example that does break even after David Simcha's fix (http://dsource.org/projects/phobos/changeset/1948)? Andrei On 1/2/11 9:19 AM, Martin Nowak wrote: > Well, bug 4789 is fixed for static arrays but reintroduced for structs > with elaborate assign. > Array copy is not allowed for overlapping memory. > > ubyte[T.sizeof] t = void; > auto a = (cast(ubyte*) &lhs)[0 .. T.sizeof]; > auto b = (cast(ubyte*) &rhs)[0 .. T.sizeof]; > t[] = a[]; > a[] = b[]; <-- will raise exception > b[] = t[]; > > Martin > > On Sun, 02 Jan 2011 00:42:44 +0100, Andrei Alexandrescu <andrei at erdani.com> wrote: > >> This has been lying in my inbox for a good while. I see now the bug is fixed. Any trailing questions regarding it? >> >> Andrei >> >> On 9/2/10 10:58 PM, David Simcha wrote: >>> A few questions about std.algorithm.swap() that came up when I was >>> reading the code to fix Bug 4789: >>> >>> 1. Do we really need to use memcpy() for structs w/o a postblit? I can't see any advantages and it seems like it might be less efficient, since for a struct without a postblit just using plain old assignment should be about as efficient as it gets. >>> >>> 2. memcpy() isn't guaranteed to work for overlapping memory blocks. >>> Shouldn't there be a check in to make sure a and b don't have the same >>> address? >>> _______________________________________________ >>> phobos mailing list >>> phobos at puremagic.com >>> http://lists.puremagic.com/mailman/listinfo/phobos > _______________________________________________ > phobos mailing list > phobos at puremagic.com > http://lists.puremagic.com/mailman/listinfo/phobos |
Copyright © 1999-2021 by the D Language Foundation