Re: Idiomatic way of writing nested loops?

2017-07-17 Thread Anton Fediushin via Digitalmars-d-learn
On Monday, 17 July 2017 at 11:32:45 UTC, Sebastiaan Koppe wrote: On Monday, 17 July 2017 at 11:07:35 UTC, Anton Fediushin wrote: Hello! What is the best way of rewriting this code in idiomatic D manner? https://dlang.org/phobos/std_algorithm_setops.html#.cartesianProduct Thank you! I knew

Idiomatic way of writing nested loops?

2017-07-17 Thread Anton Fediushin via Digitalmars-d-learn
Hello! What is the best way of rewriting this code in idiomatic D manner? -- foreach(a; ["foo", "bar"]) { foreach(b; ["baz", "foz", "bof"]) { foreach(c; ["FOO", "BAR"]) { // Some operations on a, b and c } } } -- Every array has at least 1 element, and adding/removing

Re: std.container.array of struct inside a struct fails

2017-07-14 Thread Anton Fediushin via Digitalmars-d-learn
On Friday, 14 July 2017 at 16:42:59 UTC, drug wrote: It's because Array(T) is a value type and needs type size to define itself, so you have expected forward reference. But T[] is reference type and its size is known in advance - it doesn't depend on type, it's always pointer.sizeof +

std.container.array of struct inside a struct fails

2017-07-14 Thread Anton Fediushin via Digitalmars-d-learn
This code: - import std.container.array; struct Test { Array!Test t; } - Fails with an error: - /usr/include/dlang/dmd/std/traits.d(2404): Error: struct arrayissue.Test no size because of forward reference /usr/include/dlang/dmd/std/traits.d(3462): Error: template instance

Re: sorting a string

2017-07-14 Thread Anton Fediushin via Digitalmars-d-learn
On Friday, 14 July 2017 at 17:23:41 UTC, Steven Schveighoffer wrote: Don't do this, because it's not what you think. It's not actually calling std.algorithm.sort, but the builtin array sort property. This will be going away soon. This sucks. I know, that `.sort` will be removed, but I thought

Re: sorting a string

2017-07-14 Thread Anton Fediushin via Digitalmars-d-learn
On Friday, 14 July 2017 at 15:56:49 UTC, Namal wrote: Thx Steve! By sorting string I mean a function or series of functions that sorts a string by ASCII code, "cabA" to "Aabc" for instance. import std.algorithm : sort; import std.stdio : writeln; "cabA".dup.sort.writeln; `dup` is used,

Re: Idiomatic way of writing nested loops?

2017-07-18 Thread Anton Fediushin via Digitalmars-d-learn
On Tuesday, 18 July 2017 at 03:36:04 UTC, Nicholas Wilson wrote: With regards to parallel, only use it on the outermost loop. Assuming you have more items in the outermost loop than you do threads parallelising more than one loop won't net you any speed. Thank you! Yes, `parallel` runs only

Re: Questions about dmd source

2017-07-30 Thread Anton Fediushin via Digitalmars-d-learn
On Sunday, 30 July 2017 at 06:18:16 UTC, Francis Nixon wrote: I have two completely unrelated questions about the dmd source code. 2. I've noticed there are some rather long methods in the dmd source, involving more than one goto; parse.d is particularly bad. Is there a reason for this/is it

Re: Array Printing

2017-09-12 Thread Anton Fediushin via Digitalmars-d-learn
On Tuesday, 12 September 2017 at 06:29:53 UTC, Vino.B wrote: Hi All, Request your help in printing the below array output as per the below required output Array Output: ["C:\\Temp\\TEST2\\BACKUP\\dir1", "34", "C:\\Temp\\TEST2\\BACKUP\\dir2", "36", "C:\\Temp\\TEST3\\BACKUP\\dir1", "69"]

Re: Array Printing

2017-09-12 Thread Anton Fediushin via Digitalmars-d-learn
On Tuesday, 12 September 2017 at 13:15:01 UTC, Vino.B wrote: Hi, Sorry, it didn't work, the genrated out is as below Oops, sorry. It should look like this: writefln("%-(%s\n%)", array);

Re: Dub documentation with an initial ddoc file

2017-09-04 Thread Anton Fediushin via Digitalmars-d-learn
On Sunday, 3 September 2017 at 23:14:15 UTC, Conor O'Brien wrote: I've been trying to figure out how to generate documentation for my project using dub. I have found this link[1] which told me how I could use dub to generate docs: dub build --build=docs However, I wish to have a set of

Re: High memory usage in vibe.d application

2018-06-30 Thread Anton Fediushin via Digitalmars-d-learn
On Saturday, 30 June 2018 at 22:06:50 UTC, Jacob Shtokolov wrote: On Friday, 29 June 2018 at 17:40:07 UTC, Anton Fediushin wrote: So, long story short: - Usage of Mallocator instead of theAllocator made it a little bit better - VibeManualMemoryManagement had no (or little) effect - Manually

Re: High memory usage in vibe.d application

2018-07-01 Thread Anton Fediushin via Digitalmars-d-learn
On Sunday, 1 July 2018 at 12:32:25 UTC, Jacob Shtokolov wrote: On Sunday, 1 July 2018 at 05:20:17 UTC, Anton Fediushin wrote: Now I tried it and indeed, it's vibe.d's fault. I'm not quite sure what causes it and if this problem is known, I'll look into that later and open an issue if it

Re: High memory usage in vibe.d application

2018-06-29 Thread Anton Fediushin via Digitalmars-d-learn
On Friday, 29 June 2018 at 16:19:39 UTC, 12345swordy wrote: On Friday, 29 June 2018 at 16:07:00 UTC, Anton Fediushin wrote: Now I finally understand why GC is not a great thing. I was writing apps utilizing GC for a long time and never had problems with it, but when it came down to this simple

Re: High memory usage in vibe.d application

2018-06-29 Thread Anton Fediushin via Digitalmars-d-learn
On Friday, 29 June 2018 at 16:49:41 UTC, Bauss wrote: On Friday, 29 June 2018 at 16:07:00 UTC, Anton Fediushin wrote: On Friday, 29 June 2018 at 11:11:57 UTC, rikki cattermole wrote: On 29/06/2018 11:09 PM, Anton Fediushin wrote: It is GC's fault for sure, I built my program with profile-gc

Re: High memory usage in vibe.d application

2018-06-30 Thread Anton Fediushin via Digitalmars-d-learn
On Saturday, 30 June 2018 at 05:00:35 UTC, rikki cattermole wrote: On 30/06/2018 4:49 AM, Bauss wrote: I wouldn't really blame the GC. There is a higher chance you're just not using it how it's meant to be, especially since it looks like you're mixing manual memory management with GC memory.

Re: High memory usage in vibe.d application

2018-07-01 Thread Anton Fediushin via Digitalmars-d-learn
On Sunday, 1 July 2018 at 20:15:02 UTC, crimaniak wrote: On Sunday, 1 July 2018 at 13:44:23 UTC, Anton Fediushin wrote: I reduced the test case to _one_ line: ``` 1.seconds.setTimer(() => "http://google.com".requestHTTP((scope req) {}, (scope res) {res.disconnect;}), true); ``` What

High memory usage in vibe.d application

2018-06-29 Thread Anton Fediushin via Digitalmars-d-learn
Hello, I'm looking for an advice on what I am doing wrong. I have a vibe.d-based program, which connects to an audio stream and gets name of the song currently playing. For that, I wrote the following code: ``` @safe string nowPlaying(string url) { import vibe.core.stream;

Re: High memory usage in vibe.d application

2018-06-29 Thread Anton Fediushin via Digitalmars-d-learn
Almost forgot, there are two timers which call this function for two different streams. Value of `metaint` is 16000, which means that only 16KB of memory are allocated for the `buffer`, then it reads another byte which contains length of the metadata / 16 and then it reads the metadata which

Re: High memory usage in vibe.d application

2018-06-29 Thread Anton Fediushin via Digitalmars-d-learn
On Friday, 29 June 2018 at 14:10:26 UTC, Daniel Kozak wrote: Have you try use VibeManualMemoryManagement https://github.com/TechEmpower/FrameworkBenchmarks/blob/3b24d0a21463edc536b30e2cea647fd425915401/frameworks/D/vibed/dub.json#L22 I'll try, not quite sure it'll help much.

Re: High memory usage in vibe.d application

2018-06-29 Thread Anton Fediushin via Digitalmars-d-learn
On Friday, 29 June 2018 at 11:11:57 UTC, rikki cattermole wrote: On 29/06/2018 11:09 PM, Anton Fediushin wrote: It is GC's fault for sure, I built my program with profile-gc and it allocated a lot there. Question is, why doesn't it free this memory? Probably doesn't know that it should

Re: High memory usage in vibe.d application

2018-06-29 Thread Anton Fediushin via Digitalmars-d-learn
On Friday, 29 June 2018 at 10:21:24 UTC, Radu wrote: On Friday, 29 June 2018 at 09:44:27 UTC, Anton Fediushin wrote: Almost forgot, there are two timers which call this function for two different streams. Value of `metaint` is 16000, which means that only 16KB of memory are allocated for the

Re: High memory usage in vibe.d application

2018-06-29 Thread Anton Fediushin via Digitalmars-d-learn
On Friday, 29 June 2018 at 11:01:41 UTC, Anton Fediushin wrote: On Friday, 29 June 2018 at 10:21:24 UTC, Radu wrote: On Friday, 29 June 2018 at 09:44:27 UTC, Anton Fediushin wrote: Almost forgot, there are two timers which call this function for two different streams. Value of `metaint` is

Re: High memory usage in vibe.d application

2018-06-29 Thread Anton Fediushin via Digitalmars-d-learn
On Friday, 29 June 2018 at 10:31:14 UTC, bauss wrote: On Friday, 29 June 2018 at 10:21:24 UTC, Radu wrote: On Friday, 29 June 2018 at 09:44:27 UTC, Anton Fediushin wrote: Almost forgot, there are two timers which call this function for two different streams. Value of `metaint` is 16000,

Re: High memory usage in vibe.d application

2018-06-29 Thread Anton Fediushin via Digitalmars-d-learn
On Friday, 29 June 2018 at 11:42:18 UTC, bauss wrote: On Friday, 29 June 2018 at 11:24:14 UTC, Anton Fediushin wrote: On Friday, 29 June 2018 at 11:01:41 UTC, Anton Fediushin wrote: On Friday, 29 June 2018 at 10:21:24 UTC, Radu wrote: On Friday, 29 June 2018 at 09:44:27 UTC, Anton Fediushin

Subtyping of an enum

2019-04-15 Thread Anton Fediushin via Digitalmars-d-learn
Hello! I am currently trying to add a custom `toString` method to an enum so that: 1. Enum members would still have numeric values and can be easily compared (things like `enum a { foo = "FOO", bar = "BAR”}` won't do, I want `a.foo < a.bar)`) 2. More custom methods can be implemented in the

Re: Subtyping of an enum

2019-04-15 Thread Anton Fediushin via Digitalmars-d-learn
On Monday, 15 April 2019 at 10:00:36 UTC, Alex wrote: On Monday, 15 April 2019 at 08:39:24 UTC, Anton Fediushin wrote: [snip] Otherwise, you could alwas define fun as ´´´ void fun(Enum.internal e) {} ´´´ but I assume, you want to avoid especially this. In favor of my first proposition,

Re: Subtyping of an enum

2019-04-15 Thread Anton Fediushin via Digitalmars-d-learn
On Monday, 15 April 2019 at 10:06:30 UTC, XavierAP wrote: On Monday, 15 April 2019 at 08:39:24 UTC, Anton Fediushin wrote: Hello! I am currently trying to add a custom `toString` method Several remarks... First of all, strings can be compared (alphabetically) as well as integers, e.g.

Re: Subtyping of an enum

2019-04-15 Thread Anton Fediushin via Digitalmars-d-learn
On Monday, 15 April 2019 at 12:25:38 UTC, XavierAP wrote: On Monday, 15 April 2019 at 10:34:42 UTC, Anton Fediushin wrote: On Monday, 15 April 2019 at 10:06:30 UTC, XavierAP wrote: [snip] Isn't this how subtyping works for integers and other types? For example, you have subtyped an integer

Re: Subtyping of an enum

2019-04-15 Thread Anton Fediushin via Digitalmars-d-learn
On Monday, 15 April 2019 at 10:45:26 UTC, Alex wrote: On Monday, 15 April 2019 at 10:15:50 UTC, Anton Fediushin wrote: On Monday, 15 April 2019 at 10:00:36 UTC, Alex wrote: [snip] This would: ´´´ struct Enum { private { enum internal { foo, bar } internal m_enum;

Re: Subtyping of an enum

2019-04-15 Thread Anton Fediushin via Digitalmars-d-learn
On Monday, 15 April 2019 at 14:11:05 UTC, diniz wrote: Le 15/04/2019 à 10:39, Anton Fediushin via Digitalmars-d-learn a écrit : [snip] I don't understand why you just don't call fun with an Enum (struct) param, since that is how fun is defined. This works by me (see call in main): struct

Re: Subtyping of an enum

2019-04-15 Thread Anton Fediushin via Digitalmars-d-learn
On Monday, 15 April 2019 at 14:20:57 UTC, Alex wrote: On Monday, 15 April 2019 at 08:39:24 UTC, Anton Fediushin wrote: Hello! I am currently trying to add a custom `toString` method to an enum so that: 1. Enum members would still have numeric values and can be easily compared (things like