Using emplace leading to memory corruption

monarch_dodra monarchdodra at gmail.com
Sun Sep 29 03:47:04 PDT 2013


On Sunday, 29 September 2013 at 09:46:04 UTC, Andrej Mitrovic 
wrote:
> On 9/29/13, monarch_dodra <monarchdodra at gmail.com> wrote:
>> Remember though that when emplacing a class over some memory, 
>> you
>> must account for any extra alignment (though that doesn't seem 
>> to
>> be a problem here).
>
> emplace does do a check for misalignment this internally with 
> the
> testEmplaceChunk helper function. It would throw otherwise.

Right, emplace *checks*, which means caller must take it into 
account. This doesn't explain the issue, but it should be kept in 
mind when making the allocation, and building the slice. OP 
clearly just assumed his slice would be aligned.


More information about the Digitalmars-d mailing list