Re: binary search

2020-12-06 Thread Виталий Фадеев via Digitalmars-d-learn
On Monday, 7 December 2020 at 06:24:27 UTC, drug wrote: Phobos provides this by SortedRange: https://dlang.org/phobos/std_range.html#.SortedRange Example of usage: https://run.dlang.io/is/WW2bn0 Thanks! :-)

Re: binary search

2020-12-06 Thread drug via Digitalmars-d-learn
Phobos provides this by SortedRange: https://dlang.org/phobos/std_range.html#.SortedRange Example of usage: https://run.dlang.io/is/WW2bn0

Re: how to access record[0] of a csv row? Error: no [] operator overload for type CsvRecord!(int, cast(Malformed)1, string, dchar)

2020-12-06 Thread mw via Digitalmars-d-learn
On Monday, 7 December 2020 at 04:38:07 UTC, Paul Backus wrote: On Monday, 7 December 2020 at 04:03:05 UTC, mw wrote: So my next question: given N, how do I create a Tuple!(double, double, ... n-double) type programmatically? import std.meta: Repeat; alias NDoubles = Tuple!(Repeat!(N,

Re: Request assistance initializing struct instance at global scope

2020-12-06 Thread user1234 via Digitalmars-d-learn
On Monday, 7 December 2020 at 05:28:41 UTC, user1234 wrote: On Monday, 7 December 2020 at 04:13:16 UTC, Andrew Edwards wrote: Given: === extern(C): char*[] hldr; enum I = (1<<0); struct S { char* ft; char** fm; int f; } void main(){} === How do I initialize an

Re: Request assistance initializing struct instance at global scope

2020-12-06 Thread user1234 via Digitalmars-d-learn
On Monday, 7 December 2020 at 04:13:16 UTC, Andrew Edwards wrote: Given: === extern(C): char*[] hldr; enum I = (1<<0); struct S { char* ft; char** fm; int f; } void main(){} === How do I initialize an instance of S at global scope? You cant. At the global scope the

Re: how to access record[0] of a csv row? Error: no [] operator overload for type CsvRecord!(int, cast(Malformed)1, string, dchar)

2020-12-06 Thread Paul Backus via Digitalmars-d-learn
On Monday, 7 December 2020 at 04:03:05 UTC, mw wrote: So my next question: given N, how do I create a Tuple!(double, double, ... n-double) type programmatically? import std.meta: Repeat; alias NDoubles = Tuple!(Repeat!(N, double)); Note that N must be a compile-time constant, since the

Request assistance initializing struct instance at global scope

2020-12-06 Thread Andrew Edwards via Digitalmars-d-learn
Given: === extern(C): char*[] hldr; enum I = (1<<0); struct S { char* ft; char** fm; int f; } void main(){} === How do I initialize an instance of S at global scope? // Not sure how to do this... so try to keep as close to original as possible // Nope, does not work

binary search

2020-12-06 Thread Виталий Фадеев via Digitalmars-d-learn
We have: // sorted values size_t lines = [20, 1755, 1756, 1757, 1798, 1824, 1825, 1839, 1840]; size_t search = 21; Goal: // Fast find index of the '21' in ordered array 'lines' auto found = lines.binarySearch( 20 ); // 0 - index auto low = lines.binarySearchLow(

Re: how to access record[0] of a csv row? Error: no [] operator overload for type CsvRecord!(int, cast(Malformed)1, string, dchar)

2020-12-06 Thread mw via Digitalmars-d-learn
On Monday, 7 December 2020 at 03:51:02 UTC, Paul Backus wrote: On Monday, 7 December 2020 at 02:25:23 UTC, mw wrote: onlineapp.d(8): Error: no [] operator overload for type CsvRecord!(int, cast(Malformed)1, string, dchar) should `r`'s type be integer array? and how do I access each elelment

Re: how to access record[0] of a csv row? Error: no [] operator overload for type CsvRecord!(int, cast(Malformed)1, string, dchar)

2020-12-06 Thread Paul Backus via Digitalmars-d-learn
On Monday, 7 December 2020 at 02:25:23 UTC, mw wrote: onlineapp.d(8): Error: no [] operator overload for type CsvRecord!(int, cast(Malformed)1, string, dchar) should `r`'s type be integer array? and how do I access each elelment of the row? Thanks. The docs [1] say that csvReader returns

how to access record[0] of a csv row? Error: no [] operator overload for type CsvRecord!(int, cast(Malformed)1, string, dchar)

2020-12-06 Thread mw via Digitalmars-d-learn
Hi, I'm trying this code: i.e. print out the 1st element of each row https://run.dlang.io/is/pG921a void main() { import std.csv; import std.stdio: write, writeln, writef, writefln; import std.algorithm.comparison : equal; string text = "76,26,22"; auto records =

Re: converting D's string to use with C API with unicode

2020-12-06 Thread Jack via Digitalmars-d-learn
On Sunday, 6 December 2020 at 05:04:35 UTC, tsbockman wrote: On Sunday, 6 December 2020 at 02:07:10 UTC, Jack wrote: On Saturday, 5 December 2020 at 23:31:31 UTC, tsbockman wrote: On Saturday, 5 December 2020 at 21:55:13 UTC, Jack wrote: [...] `ws.length` is the length in `wchar`s, but

Re: converting D's string to use with C API with unicode

2020-12-06 Thread Jack via Digitalmars-d-learn
On Sunday, 6 December 2020 at 04:41:56 UTC, Виталий Фадеев wrote: On Saturday, 5 December 2020 at 19:51:14 UTC, Jack wrote: So in D I have a struct like this: struct ProcessResult { string[] output; bool ok; } in order to use output from C WINAPI with unicode, I need to

Re: low-latency GC

2020-12-06 Thread Ola Fosheim Grostad via Digitalmars-d-learn
On Sunday, 6 December 2020 at 17:28:52 UTC, Bruce Carneal wrote: D is good for systems level work but that's not all. I use it for projects where, in the past, I'd have split the work between two languages (Python and C/C++). I much prefer working with a single language that spans the

Re: low-latency GC

2020-12-06 Thread Ola Fosheim Grostad via Digitalmars-d-learn
On Sunday, 6 December 2020 at 17:35:19 UTC, IGotD- wrote: Is automatic atomic reference counting a contender for kernels? In kernels you want to reduce the increase/decrease of the counts. Therefore the Rust approach using 'clone' is better unless there is some optimizer that can figure it

Re: low-latency GC

2020-12-06 Thread IGotD- via Digitalmars-d-learn
On Sunday, 6 December 2020 at 15:44:32 UTC, Ola Fosheim Grøstad wrote: It was more a hypothetical, as read barriers are too expensive. But write barriers should be ok, so a single-threaded incremental collector could work well if D takes a principled stance on objects not being 'shared' not

Re: low-latency GC

2020-12-06 Thread Bruce Carneal via Digitalmars-d-learn
On Sunday, 6 December 2020 at 16:42:00 UTC, Ola Fosheim Grostad wrote: On Sunday, 6 December 2020 at 14:44:25 UTC, Paulo Pinto wrote: And while on the subject of low level programming in JVM or .NET. https://www.infoq.com/news/2020/12/net-5-runtime-improvements/ Didnt say anything about low

Re: low-latency GC

2020-12-06 Thread Ola Fosheim Grostad via Digitalmars-d-learn
On Sunday, 6 December 2020 at 14:44:25 UTC, Paulo Pinto wrote: And while on the subject of low level programming in JVM or .NET. https://www.infoq.com/news/2020/12/net-5-runtime-improvements/ Didnt say anything about low level, only simd intrinsics, which isnt really low level? It also

Re: low-latency GC

2020-12-06 Thread Ola Fosheim Grostad via Digitalmars-d-learn
On Sunday, 6 December 2020 at 14:11:41 UTC, Max Haughton wrote: On Sunday, 6 December 2020 at 11:35:17 UTC, Ola Fosheim Grostad wrote: On Sunday, 6 December 2020 at 11:27:39 UTC, Max Haughton wrote: [...] No, unique doesnt need indirection, neither does ARC, we put the ref count at a

Re: low-latency GC

2020-12-06 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Sunday, 6 December 2020 at 14:45:21 UTC, Bruce Carneal wrote: Well, you could in theory avoid putting owning pointers on the stack/globals or require that they are registered as gc roots. Then you don't have to scan the stack. All you need then is write barriers. IIRC 'shared' with teeth?

Re: low-latency GC

2020-12-06 Thread Bruce Carneal via Digitalmars-d-learn
On Sunday, 6 December 2020 at 08:59:49 UTC, Ola Fosheim Grostad wrote: On Sunday, 6 December 2020 at 08:36:49 UTC, Bruce Carneal wrote: Yes, but they don't allow low level programming. Go also freeze to sync threads this has a rather profound impact on code generation. They have spent a lot of

Re: low-latency GC

2020-12-06 Thread Paulo Pinto via Digitalmars-d-learn
On Sunday, 6 December 2020 at 08:12:58 UTC, Ola Fosheim Grostad wrote: On Sunday, 6 December 2020 at 07:45:17 UTC, Bruce Carneal wrote: GCs scan memory, sure. Lots of variations. Not germane. Not a rationale. We need to freeze the threads when collecting stacks/globals. D is employed at

Re: low-latency GC

2020-12-06 Thread Max Haughton via Digitalmars-d-learn
On Sunday, 6 December 2020 at 11:35:17 UTC, Ola Fosheim Grostad wrote: On Sunday, 6 December 2020 at 11:27:39 UTC, Max Haughton wrote: [...] No, unique doesnt need indirection, neither does ARC, we put the ref count at a negative offset. shared_ptr is a fat pointer with the ref count as a

Re: low-latency GC

2020-12-06 Thread Ola Fosheim Grostad via Digitalmars-d-learn
On Sunday, 6 December 2020 at 12:58:44 UTC, IGotD- wrote: I was thinking about how to deal with this in D and the question is if it would be better to be able to control move as default per type basis. This way we can implement Rust style reference counting without intruding too much on the

Re: low-latency GC

2020-12-06 Thread IGotD- via Digitalmars-d-learn
On Sunday, 6 December 2020 at 11:07:50 UTC, Ola Fosheim Grostad wrote: ARC can be done incrementally, we can do it as a library first and use a modified version existing GC for detecting failed borrows at runtime during testing. But all libraries that use owning pointers need ownership to

Re: low-latency GC

2020-12-06 Thread Ola Fosheim Grostad via Digitalmars-d-learn
On Sunday, 6 December 2020 at 11:27:39 UTC, Max Haughton wrote: ARC with a library will have overhead unless the compiler/ABI is changed e.g. unique_ptr in C++ has an indirection. No, unique doesnt need indirection, neither does ARC, we put the ref count at a negative offset. shared_ptr is

Re: low-latency GC

2020-12-06 Thread Max Haughton via Digitalmars-d-learn
On Sunday, 6 December 2020 at 11:07:50 UTC, Ola Fosheim Grostad wrote: On Sunday, 6 December 2020 at 10:44:39 UTC, Max Haughton wrote: On Sunday, 6 December 2020 at 05:29:37 UTC, Ola Fosheim Grostad wrote: It has to be either some kind of heavily customisable small GC (i.e. with our resources

Re: low-latency GC

2020-12-06 Thread Ola Fosheim Grostad via Digitalmars-d-learn
On Sunday, 6 December 2020 at 10:44:39 UTC, Max Haughton wrote: On Sunday, 6 December 2020 at 05:29:37 UTC, Ola Fosheim Grostad wrote: It has to be either some kind of heavily customisable small GC (i.e. with our resources the GC cannot please everyone), or arc. The GC as it is just hurts the

Re: low-latency GC

2020-12-06 Thread Max Haughton via Digitalmars-d-learn
On Sunday, 6 December 2020 at 05:29:37 UTC, Ola Fosheim Grostad wrote: On Sunday, 6 December 2020 at 05:16:26 UTC, Bruce Carneal wrote: How difficult would it be to add a, selectable, low-latency GC to dlang? Is it closer to "we cant get there from here" or "no big deal if you already have

Re: low-latency GC

2020-12-06 Thread Ola Fosheim Grostad via Digitalmars-d-learn
On Sunday, 6 December 2020 at 08:59:49 UTC, Ola Fosheim Grostad wrote: Well, you could in theory avoid putting owning pointers on the stack/globals or require that they are registered as gc roots. Then you don't have to scan the stack. All you need then is write barriers. IIRC Abd read

Re: low-latency GC

2020-12-06 Thread Ola Fosheim Grostad via Digitalmars-d-learn
On Sunday, 6 December 2020 at 08:36:49 UTC, Bruce Carneal wrote: Yes, but they don't allow low level programming. Go also freeze to sync threads this has a rather profound impact on code generation. They have spent a lot of effort on sync instructions in code gen to lower the latency AFAIK.

Re: low-latency GC

2020-12-06 Thread Bruce Carneal via Digitalmars-d-learn
On Sunday, 6 December 2020 at 08:12:58 UTC, Ola Fosheim Grostad wrote: On Sunday, 6 December 2020 at 07:45:17 UTC, Bruce Carneal wrote: GCs scan memory, sure. Lots of variations. Not germane. Not a rationale. We need to freeze the threads when collecting stacks/globals. OK. Low latency

Re: low-latency GC

2020-12-06 Thread Ola Fosheim Grostad via Digitalmars-d-learn
On Sunday, 6 December 2020 at 07:45:17 UTC, Bruce Carneal wrote: GCs scan memory, sure. Lots of variations. Not germane. Not a rationale. We need to freeze the threads when collecting stacks/globals. D is employed at multiple "levels". Whatever level you call it, Go and modern JVMs