Re: Unittests pass, and then an invalid memory operation happens after?

2024-03-28 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Mar 28, 2024 at 11:49:19PM +, Liam McGillivray via Digitalmars-d-learn wrote: > On Thursday, 28 March 2024 at 04:46:27 UTC, H. S. Teoh wrote: > > The whole point of a GC is that you leave everything up to it to > > clean up. If you want to manage your own memory, don't use the GC. > >

Re: Why is this code slow?

2024-03-28 Thread Salih Dincer via Digitalmars-d-learn
On Friday, 29 March 2024 at 00:04:14 UTC, Serg Gini wrote: On Thursday, 28 March 2024 at 23:15:26 UTC, Salih Dincer wrote: There is no such thing as parallel programming in D anyway. At least it has modules, but I didn't see it being works. Whenever I use toys built in foreach() it always ends

Re: Setting up a final switch from a list

2024-03-28 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, March 28, 2024 4:21:03 PM MDT Salih Dincer via Digitalmars-d- learn wrote: > How can we add all members of an enum type to a list without > duplicating code? As the documentation for EnumMembers explains, you can use std.meta.NoDuplicates to strip out duplicates if you want to do some

Re: Why is this code slow?

2024-03-28 Thread Serg Gini via Digitalmars-d-learn
On Thursday, 28 March 2024 at 23:15:26 UTC, Salih Dincer wrote: There is no such thing as parallel programming in D anyway. At least it has modules, but I didn't see it being works. Whenever I use toys built in foreach() it always ends in disappointment I think it just works :) Which issues di

Re: Unittests pass, and then an invalid memory operation happens after?

2024-03-28 Thread Liam McGillivray via Digitalmars-d-learn
On Thursday, 28 March 2024 at 04:46:27 UTC, H. S. Teoh wrote: The whole point of a GC is that you leave everything up to it to clean up. If you want to manage your own memory, don't use the GC. D does not force you to use it; you can import core.stdc.stdlib and use malloc/free to your heart's

Re: Two chunks but No allocation

2024-03-28 Thread Salih Dincer via Digitalmars-d-learn
On Thursday, 28 March 2024 at 23:08:54 UTC, rkompass wrote: You can drop and take from the folded values range. I got `[1, 0.67, 0.625, 0.619048, 0.618182, 0.618056, 0.618037, 0.618034, 0.618034, 0.618034]` from the above code. Thank you so much... I solved the problem: r.back doesn't wo

Re: range.chunks(2) error

2024-03-28 Thread Salih Dincer via Digitalmars-d-learn
On Thursday, 28 March 2024 at 17:50:17 UTC, Salih Dincer wrote: Hi, When I use the chunks() template with iota(), for instance, with chunks(2), I can access both r.front and r.back. However, in a range of my own type (named iras in the code below), only r.front is working. I think the error g

Re: Why is this code slow?

2024-03-28 Thread Salih Dincer via Digitalmars-d-learn
On Thursday, 28 March 2024 at 20:18:10 UTC, rkompass wrote: I didn't know that OpenMP programming could be that easy. Binary size is 16K, same order of magnitude, although somewhat less. D advantage is gone here, I would say. There is no such thing as parallel programming in D anyway. At lea

Re: Two chunks but No allocation

2024-03-28 Thread rkompass via Digitalmars-d-learn
On Thursday, 28 March 2024 at 03:54:05 UTC, Salih Dincer wrote: On Wednesday, 27 March 2024 at 20:50:05 UTC, rkompass wrote: This works: I decided to give the full code. Maybe then it will be better understood what I mean. I actually pointed out the indirect solution above but it's a bit ugl

Re: Difference between chunks(stdin, 1) and stdin.rawRead?

2024-03-28 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Mar 28, 2024 at 10:10:43PM +, jms via Digitalmars-d-learn wrote: > On Thursday, 28 March 2024 at 02:30:11 UTC, jms wrote: [...] > I think I figured it out and the difference is probably in the mode. > This documentation > https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference

Re: Setting up a final switch from a list

2024-03-28 Thread Salih Dincer via Digitalmars-d-learn
On Thursday, 10 August 2023 at 08:33:13 UTC, Christian Köstlin wrote: I think one part of the original question (now fanished in the nntp backup) was how to get all enum members into a list without duplicating code. ```d import std.traits : EnumMembers; import std.stdio : writeln; import std.

Re: Difference between chunks(stdin, 1) and stdin.rawRead?

2024-03-28 Thread jms via Digitalmars-d-learn
On Thursday, 28 March 2024 at 02:30:11 UTC, jms wrote: Why in the below silly program am I reading both the \r and \n characters when using rawRead in block a, but when looping by 1 byte chunks in block b only appear to be reading the \n characters? I'm on Windows 11 using DMD64 D Compiler v2

Re: Why is this code slow?

2024-03-28 Thread Sergey via Digitalmars-d-learn
On Thursday, 28 March 2024 at 20:18:10 UTC, rkompass wrote: D advantage is gone here, I would say. It's hard to compare actually. Std.parallelism has a bit different mechanics, and I think easier to use. The syntax is nicer. OpenMP is an well-known and highly adopted tool, which is also qui

Re: Why is this code slow?

2024-03-28 Thread rkompass via Digitalmars-d-learn
On Thursday, 28 March 2024 at 14:07:43 UTC, Salih Dincer wrote: On Thursday, 28 March 2024 at 11:50:38 UTC, rkompass wrote: Turning back to this: Are there similarly simple libraries for C, that allow for parallel computation? You can achieve parallelism in C using libraries such as OpenMP

range.chunks(2) error

2024-03-28 Thread Salih Dincer via Digitalmars-d-learn
Hi, When I use the chunks() template with iota(), for instance, with chunks(2), I can access both r.front and r.back. However, in a range of my own type (named iras in the code below), only r.front is working. I think the error given by r.back is not a bug related to chunks, is it? ```d imp

Re: Opinions on iterating a struct to absorb the decoding of a CSV?

2024-03-28 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Mar 28, 2024 at 05:23:39PM +, Andy Valencia via Digitalmars-d-learn wrote: [...] > auto t = T(); > foreach (i, ref val; t.tupleof) { > static if (is(typeof(val) == int)) { > val = this.get_int(); > } else { > val = this.get_str(); >

Opinions on iterating a struct to absorb the decoding of a CSV?

2024-03-28 Thread Andy Valencia via Digitalmars-d-learn
I wanted a lightweight and simpler CSV decoder. I won't post the whole thing, but basically you instantiate one as: struct Whatever { ... } ... f = File("path.csv", "r"); auto c = CSVreader!Whatever(f); foreach (rec; c) { ... CSVreader is, of course, templated: struct CSVreader

Re: Why is this code slow?

2024-03-28 Thread Salih Dincer via Digitalmars-d-learn
On Thursday, 28 March 2024 at 11:50:38 UTC, rkompass wrote: Turning back to this: Are there similarly simple libraries for C, that allow for parallel computation? You can achieve parallelism in C using libraries such as OpenMP, which provides a set of compiler directives and runtime library

Re: Why is this code slow?

2024-03-28 Thread rkompass via Digitalmars-d-learn
On Thursday, 28 March 2024 at 01:09:34 UTC, Salih Dincer wrote: Good thing you're digressing; I am 45 years old and I still cannot say that I am finished as a student! For me this is version 4 and it looks like we don't need a 3rd variable other than the function parameter and return value: