digitalmars.D.learn - std.container.array.Array is not nogc?
- drug007 (20/20) Jan 15 2017 Is there a way to use Array in @nogc code:
- Jack Stouffer (8/28) Jan 15 2017 No you're not.
- drug007 (2/9) Jan 15 2017 Thanks for answer. Looking forward for your PR.
- Jack Stouffer (2/3) Jan 15 2017 https://github.com/dlang/phobos/pull/5036
Is there a way to use Array in nogc code: ``` import std.container.array : Array; nogc: void main(string[ ] args) { Array!int ai; ai ~= 1; assert(ai[0] == 1); } ``` fails: ``` main.d(8): Error: nogc function 'D main' cannot call non- nogc function 'std.container.array.Array!int.Array.opOpAssign!("~", int).opOpAssign' main.d(9): Error: nogc function 'D main' cannot call non- nogc function 'std.container.array.Array!int.Array.opIndex' ``` am I doing something wrong?
Jan 15 2017
On Sunday, 15 January 2017 at 11:47:06 UTC, drug007 wrote:Is there a way to use Array in nogc code: ``` import std.container.array : Array; nogc: void main(string[ ] args) { Array!int ai; ai ~= 1; assert(ai[0] == 1); } ``` fails: ``` main.d(8): Error: nogc function 'D main' cannot call non- nogc function 'std.container.array.Array!int.Array.opOpAssign!("~", int).opOpAssign' main.d(9): Error: nogc function 'D main' cannot call non- nogc function 'std.container.array.Array!int.Array.opIndex' ``` am I doing something wrong?No you're not. Array was designed before the nogc attribute was created, so it wasn't coded with it's requirements in mind. Looking at the code, Array allocates GC memory for exception throwing in some cases. These can and should be changed to asserts. I am writing a PR now to fix this. There doesn't seem to be too many cases to fix.
Jan 15 2017
On 15.01.2017 15:49, Jack Stouffer wrote:No you're not. Array was designed before the nogc attribute was created, so it wasn't coded with it's requirements in mind. Looking at the code, Array allocates GC memory for exception throwing in some cases. These can and should be changed to asserts. I am writing a PR now to fix this. There doesn't seem to be too many cases to fix.Thanks for answer. Looking forward for your PR.
Jan 15 2017
On Sunday, 15 January 2017 at 13:08:52 UTC, drug007 wrote:Thanks for answer. Looking forward for your PR.https://github.com/dlang/phobos/pull/5036
Jan 15 2017