GC and void[N] in struct
vit
vit at vit.vit
Mon Aug 6 18:59:05 UTC 2018
On Monday, 6 August 2018 at 18:28:11 UTC, Steven Schveighoffer
wrote:
> On 8/6/18 2:22 PM, vit wrote:
>> Hello,
>> I have this struct:
>>
>> struct S{
>> uint kind;
>> void[N] data_;
>
> define "N"
>
>>
>> }
>>
>> Instances of struct S are allocated by standard GC new and
>> S.data_ can contain pointers/ranges to GC allocated data.
>> If is GC disabled then program run fine. But when is GC
>> enabled then it fail randomly.
>
> how does it fail?
>
> -Steve
private auto sizeOf(T)(){return T.sizeof;}
struct ExprImpl(Ts...){
enum N = max(staticMap!(sizeOf, Ts));
invariant(kind_ != 0);
uint kind_ = 0;
void[N] data_;
this(T)(auto ref T x){/+emplace T to data_ and change kind_
to something != 0+/}
}
Ts == structs
data change without triggering invariant after allocation in
other part of program.
More information about the Digitalmars-d-learn
mailing list