digitalmars.D.learn - nogc Array
- Igor (2/2) Jan 25 2016 Is there a GC-less array that we can use out of the box or do I
- maik klein (2/4) Jan 25 2016 https://dlang.org/phobos/std_container_array.html
- Igor (10/14) Jan 25 2016 How do we use std.algorithm with it? I could like to use find but
- Adam D. Ruppe (11/14) Jan 25 2016 Try
- Igor (17/32) Jan 25 2016 Ok, does the [] do any conversion or any thing I don't want or
- Olivier Pisano (7/48) Jan 26 2016 The [] operator returns a Range object iterating over the Array
- Kapps (4/20) Jan 25 2016 First, should be std.container.array.Array!MyClass. However I
- Nemo (2/4) Jan 25 2016 There's one in emsi containers.
- Jonathan M Davis via Digitalmars-d-learn (7/9) Jan 25 2016 If what you want is a dynamic array (as opposed std.container.Array), th...
- ZombineDev (5/7) Jan 26 2016 If you want containers, use:
Is there a GC-less array that we can use out of the box or do I have to create my own?
Jan 25 2016
On Tuesday, 26 January 2016 at 03:03:40 UTC, Igor wrote:Is there a GC-less array that we can use out of the box or do I have to create my own?https://dlang.org/phobos/std_container_array.html
Jan 25 2016
On Tuesday, 26 January 2016 at 03:06:40 UTC, maik klein wrote:On Tuesday, 26 January 2016 at 03:03:40 UTC, Igor wrote:How do we use std.algorithm with it? I could like to use find but I have no luck. I have std.container.array!MyClass classes; then std.algorithm.find!("a.myInt == b")(classes, 3) I was hoping this would find the first object in classes who has myInt == 3 but I just get many errors about not being able to find the right definition. I guess std.container.array isn't a range? Or am I using it wrong?Is there a GC-less array that we can use out of the box or do I have to create my own?https://dlang.org/phobos/std_container_array.html
Jan 25 2016
On Tuesday, 26 January 2016 at 04:31:07 UTC, Igor wrote:then std.algorithm.find!("a.myInt == b")(classes, 3)Try std.algorithm.find!("a.myInt == b")(classes[], 3) notice the [] after classesI guess std.container.array isn't a range? Or am I using it wrong?Containers aren't really ranges, they instead *offer* ranges that iterate over them. Built in arrays are a bit special in that they do this implicitly so the line is more blurred there, but it is a general rule that you need to get a range out of a container. Otherwise, consider that iterating over it with popFront would result in the container being automatically emptied and not reusable!
Jan 25 2016
On Tuesday, 26 January 2016 at 04:38:13 UTC, Adam D. Ruppe wrote:On Tuesday, 26 January 2016 at 04:31:07 UTC, Igor wrote:Ok, does the [] do any conversion or any thing I don't want or does it just make the template know we are working over an array? Are there any performance issues? I am already using a for loop to find the type, it's 6 lines of code. I was hoping to get that down to one or 2 and make it a bit easier to understand. App app = null; for(int i = 0; i < Apps.length(); i++) if ((Apps[i] !is null) && (Apps[i].hWnd == hWnd)) { app = Apps[i]; break; } versus find!("a.hWnd == b")(Apps[], hWnd); Does [] take time to convert to a built in a array or range or whatever or will it be just as fast as the above code?then std.algorithm.find!("a.myInt == b")(classes, 3)Try std.algorithm.find!("a.myInt == b")(classes[], 3) notice the [] after classesI guess std.container.array isn't a range? Or am I using it wrong?Containers aren't really ranges, they instead *offer* ranges that iterate over them. Built in arrays are a bit special in that they do this implicitly so the line is more blurred there, but it is a general rule that you need to get a range out of a container. Otherwise, consider that iterating over it with popFront would result in the container being automatically emptied and not reusable!
Jan 25 2016
On Tuesday, 26 January 2016 at 05:53:29 UTC, Igor wrote:On Tuesday, 26 January 2016 at 04:38:13 UTC, Adam D. Ruppe wrote:The [] operator returns a Range object iterating over the Array elements, similarly to what the begin()/end() cbegin()/cend() function pairs do in C++. The range object does not copy the array element, only contains a slice to them. So your question ends up in comparing hand-written loops over std::find_if().On Tuesday, 26 January 2016 at 04:31:07 UTC, Igor wrote:Ok, does the [] do any conversion or any thing I don't want or does it just make the template know we are working over an array? Are there any performance issues? I am already using a for loop to find the type, it's 6 lines of code. I was hoping to get that down to one or 2 and make it a bit easier to understand. App app = null; for(int i = 0; i < Apps.length(); i++) if ((Apps[i] !is null) && (Apps[i].hWnd == hWnd)) { app = Apps[i]; break; } versus find!("a.hWnd == b")(Apps[], hWnd); Does [] take time to convert to a built in a array or range or whatever or will it be just as fast as the above code?then std.algorithm.find!("a.myInt == b")(classes, 3)Try std.algorithm.find!("a.myInt == b")(classes[], 3) notice the [] after classesI guess std.container.array isn't a range? Or am I using it wrong?Containers aren't really ranges, they instead *offer* ranges that iterate over them. Built in arrays are a bit special in that they do this implicitly so the line is more blurred there, but it is a general rule that you need to get a range out of a container. Otherwise, consider that iterating over it with popFront would result in the container being automatically emptied and not reusable!
Jan 26 2016
On Tuesday, 26 January 2016 at 04:31:07 UTC, Igor wrote:On Tuesday, 26 January 2016 at 03:06:40 UTC, maik klein wrote:First, should be std.container.array.Array!MyClass. However I don't think(?) that the Array struct is a range itself, you might have to use classes[] instead to get a slice of the array.On Tuesday, 26 January 2016 at 03:03:40 UTC, Igor wrote:How do we use std.algorithm with it? I could like to use find but I have no luck. I have std.container.array!MyClass classes; then std.algorithm.find!("a.myInt == b")(classes, 3) I was hoping this would find the first object in classes who has myInt == 3 but I just get many errors about not being able to find the right definition. I guess std.container.array isn't a range? Or am I using it wrong?Is there a GC-less array that we can use out of the box or do I have to create my own?https://dlang.org/phobos/std_container_array.html
Jan 25 2016
On Tuesday, 26 January 2016 at 03:03:40 UTC, Igor wrote:Is there a GC-less array that we can use out of the box or do I have to create my own?There's one in emsi containers.
Jan 25 2016
On Tuesday, January 26, 2016 03:03:40 Igor via Digitalmars-d-learn wrote:Is there a GC-less array that we can use out of the box or do I have to create my own?If what you want is a dynamic array (as opposed std.container.Array), then you can simply malloc the memory and then slice it to get a dynamic array. It's just that it's then up to you to manage the memory properly, and if you attempt to append or concatenate, it'll result in the GC allocating a new array. - Jonathan M Davis
Jan 25 2016
On Tuesday, 26 January 2016 at 03:03:40 UTC, Igor wrote:Is there a GC-less array that we can use out of the box or do I have to create my own?If you want containers, use: http://code.dlang.org/packages/emsi_containers If you just need an array, use:
Jan 26 2016