digitalmars.D.learn - Cameleon: Stricter Alternative Implementation of VariantN
- =?UTF-8?B?Tm9yZGzDtnc=?= (25/25) Sep 21 2015 Because I'm not satisfied with the current state of
- Kagamin (3/10) Sep 22 2015 Make sure your struct is always sizeof(void*)-aligned.
- Per =?UTF-8?B?Tm9yZGzDtnc=?= (3/4) Sep 22 2015 Could that be automatically enforced somehow based on the
- Kagamin (3/3) Sep 22 2015 You can generate a union from allowed types, it will make copies
- =?UTF-8?B?Tm9yZGzDtnc=?= (4/7) Sep 22 2015 I believe there is a trait somewhere that figures out the maximum
- Per =?UTF-8?B?Tm9yZGzDtnc=?= (4/7) Sep 22 2015 How does the GC know if the data block contains a reference
- Per =?UTF-8?B?Tm9yZGzDtnc=?= (2/5) Sep 22 2015 If so when does this memory scanning occurr?
- =?UTF-8?B?Tm9yZGzDtnc=?= (6/8) Oct 03 2015 Moved to
Because I'm not satisfied with the current state of memory-layout-flexibility/pureness/safeness/nogc/nothrow-ness of `VariantN` I've hacked together a lightweight version of `VariantN`, I currently call `Cameleon`. The code is here: https://github.com/nordlow/justd/blob/master/cameleon.d Its currently limited to my specific needs (strings and value-types) through https://github.com/nordlow/justd/blob/master/cameleon.d#L5 https://github.com/nordlow/justd/blob/master/cameleon.d#L35 because it's hard to decrypt the inner `OpID`-workings of `VariantN`. Questions: - Is the logic of opAssign and get ok for string? - How does the inner workings of the GC harmonize with my calls to `memcpy` in `opAssign()` here https://github.com/nordlow/justd/blob/master/cameleon.d#L80 https://github.com/nordlow/justd/blob/master/cameleon.d#L107 and my zeroing of the internal data buffer in `clear()` here https://github.com/nordlow/justd/blob/master/cameleon.d#L143 ? - Do I have to call some GC-logic in order to make the GC aware of the new string-reference in `opAssign`? - Is this logic for `char[]` different from `(immutable char)[]`? - And what do I need to think about if I allow classes as members?
Sep 21 2015
On Monday, 21 September 2015 at 13:42:14 UTC, Nordlöw wrote:Questions: - Is the logic of opAssign and get ok for string? - How does the inner workings of the GC harmonize with my calls to `memcpy` in `opAssign()` here https://github.com/nordlow/justd/blob/master/cameleon.d#L80That line won't compile, so don't be afraid of its behavior.- Do I have to call some GC-logic in order to make the GC aware of the new string-reference in `opAssign`?Make sure your struct is always sizeof(void*)-aligned.
Sep 22 2015
On Tuesday, 22 September 2015 at 09:57:58 UTC, Kagamin wrote:Make sure your struct is always sizeof(void*)-aligned.Could that be automatically enforced somehow based on the contents of AllowedTypes?
Sep 22 2015
You can generate a union from allowed types, it will make copies type safe too, sort of set!(staticIndexOf(T, AllowedTypes))(rhs)... hmm... can it be an overload?
Sep 22 2015
On Tuesday, 22 September 2015 at 12:54:47 UTC, Kagamin wrote:You can generate a union from allowed types, it will make copies type safe too, sort of set!(staticIndexOf(T, AllowedTypes))(rhs)... hmm... can it be an overload?I believe there is a trait somewhere that figures out the maximum alignment needed for a set/union of types. I think Walter spoke about in a DConf lecture some time ago.
Sep 22 2015
On Tuesday, 22 September 2015 at 09:57:58 UTC, Kagamin wrote:How does the GC know if the data block contains a reference (pointer) or value type? Does it try to follow that pointer either way!?- Do I have to call some GC-logic in order to make the GC aware of the new string-reference in `opAssign`?Make sure your struct is always sizeof(void*)-aligned.
Sep 22 2015
On Tuesday, 22 September 2015 at 12:47:31 UTC, Per Nordlöw wrote:How does the GC know if the data block contains a reference (pointer) or value type? Does it try to follow that pointer either way!?If so when does this memory scanning occurr?
Sep 22 2015
On Monday, 21 September 2015 at 13:42:14 UTC, Nordlöw wrote:The code is here: https://github.com/nordlow/justd/blob/master/cameleon.dMoved to https://github.com/nordlow/justd/blob/master/vary.d Templates are no called: - FastVariant - PackedVariant
Oct 03 2015