Thread overview
nogc Array
Jan 26, 2016
Igor
Jan 26, 2016
maik klein
Jan 26, 2016
Igor
Jan 26, 2016
Adam D. Ruppe
Jan 26, 2016
Igor
Jan 26, 2016
Olivier Pisano
Jan 26, 2016
Kapps
Jan 26, 2016
Nemo
Jan 26, 2016
Jonathan M Davis
Jan 26, 2016
ZombineDev
January 26, 2016
Is there a GC-less array that we can use out of the box or do I have to create my own?

January 26, 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
January 26, 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.
January 26, 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:
>> 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

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?

January 26, 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 classes


> I 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!
January 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:
>> 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
>
> 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?

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.
January 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

January 26, 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:
>> then std.algorithm.find!("a.myInt == b")(classes, 3)
>
> Try
>
> std.algorithm.find!("a.myInt == b")(classes[], 3)
>
> notice the [] after classes
>
>
>> I 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!

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?


January 26, 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:
>> 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 classes
>>
>>
>>> I 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!
>
> 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?

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().
January 26, 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: http://dlang.org/phobos/std_experimental_allocator#.makeArray