Re: Using tasks without GC?

2020-01-05 Thread Chris Katko via Digitalmars-d-learn
Thanks everyone, looks like i'll have to benchmark myself (which 
is fine) but I'm always afraid because I know "proper 
benchmarking is hard. (TM)"


Feel free to throw any other side advice in. I'm looking to get a 
broad perspective on this.


Straight up shutting off the garbage collector in exchange for 
memory is an interesting concept. But I wonder how quickly it 
will get eaten up. ALSO, if I do shut it off, when i turn it on 
is it going to take much longer? Does the GC take linear / 
quadratically more time based on the N of "items need to be 
freed"?


The thing is, I'm looking to parallelize a dedicated server for 
running MASSIVE numbers of objects (1's or 10's) at high 
tick rate. Worse, for my particular "game mode", the "rounds" can 
last hours. So while a slow crawl of RAM is okay, it won't be 
okay if it hits 30 GB in an hour. So that's going to be another 
"it works IF it works [in our particular game/application]" as 
opposed to "this definitely will/won't work". That's more 
"benchmarking and see" scenarios, which I'm trying to avoid as 
much as possible. You normally don't want to willfully START a 
project with a design where the only way to know if it works... 
is to bench.


There's also an option of periodically firing off (without ending 
the game) say, once every hour and tell everyone to just "live 
with it" because it's (I HOPE!) not going to be a 15/30/60 second 
delay. In my particular application, that still wouldn't be that 
disruptive. (Unless turning GC off hits max ram every couple 
minutes. Then again nobody is going to be okay with that.)


On Saturday, 4 January 2020 at 11:30:53 UTC, dwdv wrote:

Creates a Task on the GC heap that calls an alias.


If possible, there's also scopedTask, which allocates on the 
stack: https://dlang.org/phobos/std_parallelism.html#.scopedTask


So my question is: Has anyone done any analysis over how 
"dangerous" it is to use GC'd tasks for _small_ tasks (in 
terms of milliseconds)?


Nothing major, but 
https://github.com/mratsim/weave/tree/master/benchmarks/fibonacci puts quite a bit of pressure on various implementations. You might want to profile ./pfib 40:


import std;

ulong fib(uint n) {
if (n < 2) return n;

auto x = scopedTask!fib(n-1); // vs. Task!fib(n-1);
taskPool.put(x);
auto y = fib(n-2);
return x.yieldForce + y; // {yield,spin,work}Force
}

void main(string[] args) {
enforce(args.length == 2, "Usage: fib number requested>");

auto n = args[1].to!uint;
// defaultPoolThreads(totalCPUs);
writefln!"fib(%d) = %d"(n, fib(n));
}

At least D isn't locking up beyond 12 tasks; looking at you, 
stdlib-nim. :)





Re: Unfold string array

2020-01-05 Thread Temtaime via Digitalmars-d-learn

On Sunday, 5 January 2020 at 22:39:37 UTC, Teo wrote:

On Sunday, 5 January 2020 at 13:37:58 UTC, JN wrote:

[...]


Thanks for the input.
I just realized that I was not precise enough in my 
description. Apologies for that.

My intention is to use std.algorithm, if possible.

I read the documentation and tried using many functions like 
"joiner", "each", "fold", "group", "filter", etc. from 
std.algorithm.iteration.


In my opinion, I need to construct a predicate like
(a, b) => if b.startsWith() {join(a, b, " ")}
Unfortunately, I cannot figure out which combination of 
functions will give me the desired result.


Of course, if I am unable to find an elegant way to do it, I am 
going to iterate over the array in a way similar to what you 
suggested.


https://ideone.com/tvpreP


Re: Unfold string array

2020-01-05 Thread Teo via Digitalmars-d-learn

On Sunday, 5 January 2020 at 13:37:58 UTC, JN wrote:
It's kind of a naive implementation, there probably is room for 
improvement but should work for start.


Thanks for the input.
I just realized that I was not precise enough in my description. 
Apologies for that.

My intention is to use std.algorithm, if possible.

I read the documentation and tried using many functions like 
"joiner", "each", "fold", "group", "filter", etc. from 
std.algorithm.iteration.


In my opinion, I need to construct a predicate like
(a, b) => if b.startsWith() {join(a, b, " ")}
Unfortunately, I cannot figure out which combination of functions 
will give me the desired result.


Of course, if I am unable to find an elegant way to do it, I am 
going to iterate over the array in a way similar to what you 
suggested.


Re: How load icon from resource using LoadImage?

2020-01-05 Thread Marcone via Digitalmars-d-learn

On Sunday, 5 January 2020 at 15:13:17 UTC, Rumbu wrote:

On Sunday, 5 January 2020 at 13:33:35 UTC, Marcone wrote:
I am using this code to load icon from local directory, but I 
want to load icon from resource.res file:


wndclass.hIcon  = LoadImage( NULL, "icon.ico", IMAGE_ICON, 0, 
0, LR_LOADFROMFILE| LR_SHARED | LR_LOADTRANSPARENT);


You cannot load icons from res files.

If you link your res file to the executable, you can load the 
icon using:


LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(youriconid));


The function LoadImage from above loads an icon from the file 
named icon.ico, not from a res file.


Very good! working using: LoadIcon(hInstance, 
MAKEINTRESOURCE(youriconid)); becouse GetModuleHandle(NULL) is 
undefined here.


Re: How load icon from resource using LoadImage?

2020-01-05 Thread Rumbu via Digitalmars-d-learn

On Sunday, 5 January 2020 at 13:33:35 UTC, Marcone wrote:
I am using this code to load icon from local directory, but I 
want to load icon from resource.res file:


wndclass.hIcon  = LoadImage( NULL, "icon.ico", IMAGE_ICON, 0, 
0, LR_LOADFROMFILE| LR_SHARED | LR_LOADTRANSPARENT);


You cannot load icons from res files.

If you link your res file to the executable, you can load the 
icon using:


LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(youriconid));


The function LoadImage from above loads an icon from the file 
named icon.ico, not from a res file.


Re: How load icon from resource using LoadImage?

2020-01-05 Thread JN via Digitalmars-d-learn

On Sunday, 5 January 2020 at 13:33:35 UTC, Marcone wrote:
I am using this code to load icon from local directory, but I 
want to load icon from resource.res file:


wndclass.hIcon  = LoadImage( NULL, "icon.ico", IMAGE_ICON, 0, 
0, LR_LOADFROMFILE| LR_SHARED | LR_LOADTRANSPARENT);


https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-loadimagea

According to the docs, the first argument is NULL only for 
standalone images, otherwise you have to provide a valid 
HINSTANCE.


By the way, have you managed to add the res file into the binary? 
My understanding is that the res file should be added into the 
exe file by the rc command before it can be used.


Re: Unfold string array

2020-01-05 Thread JN via Digitalmars-d-learn

On Sunday, 5 January 2020 at 08:21:54 UTC, Teo wrote:

All advises are welcome
Thank you!


For some reason I can't get run.dlang.io to shorten a link... 
hmm... I'll use ideone.


https://ideone.com/EjbhIs

It's kind of a naive implementation, there probably is room for 
improvement but should work for start.


How load icon from resource using LoadImage?

2020-01-05 Thread Marcone via Digitalmars-d-learn
I am using this code to load icon from local directory, but I 
want to load icon from resource.res file:


wndclass.hIcon  = LoadImage( NULL, "icon.ico", IMAGE_ICON, 0, 0, 
LR_LOADFROMFILE| LR_SHARED | LR_LOADTRANSPARENT);


Unfold string array

2020-01-05 Thread Teo via Digitalmars-d-learn
I couldn't find by searching this forum the way to do that, so I 
thought it is better to ask and learn.


The data I am trying to unfold is in the form of string array 
read from a file line by line, like this:


string[] lines =
[
"key1: valueA",
"key2: valueB",
"key3: valueC",
"\tvalueD",
"valueE",
"key4: valueF",
]

where  represents some white space character(s). It 
could be TAB or SPACE, etc.


Now, I want to find a way to concatenate valueD to the previous 
element which begins with key3 and afterwards concatenate valueE 
also to the concatenated string for key3.


The rule is that long strings are folded when written to the file 
and folded lines always begin with a white space.


Finally I am going to use assocArray to construct an associative 
array.


All advises are welcome
Thank you!