Re: Straight Forward Arrays

2023-10-06 Thread dhs via Digitalmars-d-learn
On Thursday, 5 October 2023 at 16:57:00 UTC, Jesse Phillips wrote: On Wednesday, 4 October 2023 at 10:51:46 UTC, dhs wrote: D and Go slices have advantages but can be confusing. I don't have a solution, but if anyone is interested, the relevant discussions about slice confusion in the Go comm

Re: Straight Forward Arrays

2023-10-05 Thread Jesse Phillips via Digitalmars-d-learn
On Wednesday, 4 October 2023 at 10:51:46 UTC, dhs wrote: D and Go slices have advantages but can be confusing. I don't have a solution, but if anyone is interested, the relevant discussions about slice confusion in the Go community apply to D slices as well. I don't believe slice confusion

Re: Straight Forward Arrays

2023-10-04 Thread dhs via Digitalmars-d-learn
On Monday, 2 October 2023 at 02:56:33 UTC, Steven Schveighoffer wrote: FWIW, there is a cache that makes this decently fast, so it doesn't have to go all the way into the GC to get all the information for every append. But it *most definitely* not going to be as fast as reading a local "cap

Re: Straight Forward Arrays

2023-10-01 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/1/23 1:13 PM, dhs wrote: It may not be a problem in practice. My concern was performance, because each time we add an element to the array, the garbage collector has to map the slice to the allocation it belongs to. FWIW, there is a cache that makes this decently fast, so it doesn't hav

Re: Straight Forward Arrays

2023-10-01 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, October 1, 2023 11:13:43 AM MDT dhs via Digitalmars-d-learn wrote: > On Sunday, 1 October 2023 at 13:27:37 UTC, Adam D Ruppe wrote: > > On Sunday, 1 October 2023 at 09:01:53 UTC, dhs wrote: > >> When D creates a dynamic array, it returns a slice. Functions > >> that add or remove element

Re: Straight Forward Arrays

2023-10-01 Thread dhs via Digitalmars-d-learn
On Sunday, 1 October 2023 at 17:21:32 UTC, Steven Schveighoffer wrote: On 10/1/23 10:34 AM, Steven Schveighoffer wrote: This should give you a reasonable head-start. -Steve It does. Many thanks!

Re: Straight Forward Arrays

2023-10-01 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/1/23 10:34 AM, Steven Schveighoffer wrote: The complexity is from the way d does operator overloading and indexing. It should be pretty straightforward. I’ll see if I can post a simple wrapper. I didn't tackle any attribute or memory safety issues, or many operator overloads, but thi

Re: Straight Forward Arrays

2023-10-01 Thread dhs via Digitalmars-d-learn
On Sunday, 1 October 2023 at 13:27:37 UTC, Adam D Ruppe wrote: On Sunday, 1 October 2023 at 09:01:53 UTC, dhs wrote: When D creates a dynamic array, it returns a slice. Functions that add or remove elements begin by asking the memory manager for the dynamic array that the slice belongs to. Only

Re: Straight Forward Arrays

2023-10-01 Thread Steven Schveighoffer via Digitalmars-d-learn
On Sunday, 1 October 2023 at 13:24:27 UTC, dhs wrote: On Sunday, 1 October 2023 at 13:05:12 UTC, Steven Schveighoffer wrote: On Sunday, 1 October 2023 at 09:01:53 UTC, dhs wrote: [...] Std::vector uses value semantics. D does not have anything like that. It could be done someone just has to

Re: Straight Forward Arrays

2023-10-01 Thread dhs via Digitalmars-d-learn
On Sunday, 1 October 2023 at 13:51:35 UTC, Imperatorn wrote: D can be very readable and maintainable, but since all the advanced features exist, we are tempted to use them, which can cause otherwise normal code to become a bit obfuscated. OK in any case the forum seems to be very helpful. Th

Re: Straight Forward Arrays

2023-10-01 Thread Imperatorn via Digitalmars-d-learn
On Sunday, 1 October 2023 at 13:24:27 UTC, dhs wrote: On Sunday, 1 October 2023 at 13:05:12 UTC, Steven Schveighoffer wrote: On Sunday, 1 October 2023 at 09:01:53 UTC, dhs wrote: Hi, Is there a straight forward Array type in D similar to C++'s vector class? Something along the lines of the tu

Re: Straight Forward Arrays

2023-10-01 Thread Adam D Ruppe via Digitalmars-d-learn
On Sunday, 1 October 2023 at 09:01:53 UTC, dhs wrote: When D creates a dynamic array, it returns a slice. Functions that add or remove elements begin by asking the memory manager for the dynamic array that the slice belongs to. Only then can they go on and add elements. Why is this a problem?

Re: Straight Forward Arrays

2023-10-01 Thread dhs via Digitalmars-d-learn
On Sunday, 1 October 2023 at 13:05:12 UTC, Steven Schveighoffer wrote: On Sunday, 1 October 2023 at 09:01:53 UTC, dhs wrote: Hi, Is there a straight forward Array type in D similar to C++'s vector class? Something along the lines of the tuple: (pointer to elements, length, capacity). [...]

Re: Straight Forward Arrays

2023-10-01 Thread Steven Schveighoffer via Digitalmars-d-learn
On Sunday, 1 October 2023 at 09:01:53 UTC, dhs wrote: Hi, Is there a straight forward Array type in D similar to C++'s vector class? Something along the lines of the tuple: (pointer to elements, length, capacity). [...] Std::vector uses value semantics. D does not have anything like that.

Re: Straight Forward Arrays

2023-10-01 Thread dhs via Digitalmars-d-learn
On Sunday, 1 October 2023 at 11:43:17 UTC, bachmeier wrote: On Sunday, 1 October 2023 at 11:39:11 UTC, bachmeier wrote: On Sunday, 1 October 2023 at 09:01:53 UTC, dhs wrote: Hi, Is there a straight forward Array type in D similar to C++'s vector class? Something along the lines of the tuple:

Re: Straight Forward Arrays

2023-10-01 Thread bachmeier via Digitalmars-d-learn
On Sunday, 1 October 2023 at 11:39:11 UTC, bachmeier wrote: On Sunday, 1 October 2023 at 09:01:53 UTC, dhs wrote: Hi, Is there a straight forward Array type in D similar to C++'s vector class? Something along the lines of the tuple: (pointer to elements, length, capacity). I tried two imple

Re: Straight Forward Arrays

2023-10-01 Thread bachmeier via Digitalmars-d-learn
On Sunday, 1 October 2023 at 09:01:53 UTC, dhs wrote: Hi, Is there a straight forward Array type in D similar to C++'s vector class? Something along the lines of the tuple: (pointer to elements, length, capacity). I tried two implementations: D's dynamic array and std.container.array. Whe

Re: Straight Forward Arrays

2023-10-01 Thread dhs via Digitalmars-d-learn
On Sunday, 1 October 2023 at 09:21:37 UTC, Imperatorn wrote: On Sunday, 1 October 2023 at 09:01:53 UTC, dhs wrote: Hi, Is there a straight forward Array type in D similar to C++'s vector class? Something along the lines of the tuple: (pointer to elements, length, capacity). [...] https://

Re: Straight Forward Arrays

2023-10-01 Thread Imperatorn via Digitalmars-d-learn
On Sunday, 1 October 2023 at 09:01:53 UTC, dhs wrote: Hi, Is there a straight forward Array type in D similar to C++'s vector class? Something along the lines of the tuple: (pointer to elements, length, capacity). [...] https://dlang.org/spec/simd.html https://dlang.org/phobos/core_simd.ht