Re: Associative Array potential performance pitfall?

2020-03-13 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Mar 13, 2020 at 03:40:11AM +, Adnan via Digitalmars-d-learn wrote: > In my machine the following D code compiled with release flag and LDC > performs over 230ms while the similar Go code performs under 120ms. > > string smallestRepr(const string arg) { > import std.format : forma

Re: Associative Array potential performance pitfall?

2020-03-13 Thread dayllenger via Digitalmars-d-learn
On Friday, 13 March 2020 at 03:40:11 UTC, Adnan wrote: Where am I losing performance? It is nonsensical to say without measuring. Humans are notoriously bad at predicting performance issues. Wrap all your hardworking code into a loop with like 100 iterations, compile and run: $ perf record

Re: How can I append PATH to environment["PATH"] in runtime?

2020-03-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/13/20 2:08 AM, Marcone wrote: environment["PATH"] ~= r";D:\folder\"; // Error Did you try the long way? environment["PATH"] = environment["PATH"] ~ r";D:\folder\"; It would be nice to have environment support opIndexOpAssign for concatenation. -Steve

Re: Associative Array potential performance pitfall?

2020-03-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/13/20 5:24 AM, H. S. Teoh wrote: Note that `arg ~ arg` may allocate, but it also may not if the current buffer for `arg` is big enough to accomodate both. That always allocates. Only appending may avoid allocation: arg ~= arg; But, I would instead use ranges if possible to avoid all allo

Re: Associative Array potential performance pitfall?

2020-03-13 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Mar 13, 2020 at 09:30:16AM -0400, Steven Schveighoffer via Digitalmars-d-learn wrote: > On 3/13/20 5:24 AM, H. S. Teoh wrote: > > Note that `arg ~ arg` may allocate, but it also may not if the > > current buffer for `arg` is big enough to accomodate both. > > That always allocates. Only a

Is it possible to dynamically load a @safe function from a shared library ?

2020-03-13 Thread wjoe via Digitalmars-d-learn
I've got a plug-in which is a shared library. Like this module plugin; @safe int VersionOfAPI() { return 1; } this is builds to plugin.so in main.d I'm loading the plugin and bind the those functions like so: module app; @safe: alias apiverfn = int function(); apiverfn apiVersion; void

Re: Is it possible to dynamically load a @safe function from a shared library ?

2020-03-13 Thread Mike Parker via Digitalmars-d-learn
On Friday, 13 March 2020 at 15:16:06 UTC, wjoe wrote: bindSymbol(&apiVersion, "VersionOfAPI"); } Is it possible to convince the compiler to look the other way while binding @safe functions from the plugin ? It probably has nothing to do with @safe, but is because of the void**. bin

Re: Is it possible to dynamically load a @safe function from a shared library ?

2020-03-13 Thread wjoe via Digitalmars-d-learn
On Friday, 13 March 2020 at 16:04:06 UTC, Mike Parker wrote: On Friday, 13 March 2020 at 15:16:06 UTC, wjoe wrote: bindSymbol(&apiVersion, "VersionOfAPI"); } Is it possible to convince the compiler to look the other way while binding @safe functions from the plugin ? It probably has

Re: Is it possible to dynamically load a @safe function from a shared library ?

2020-03-13 Thread Mike Parker via Digitalmars-d-learn
On Friday, 13 March 2020 at 16:11:53 UTC, wjoe wrote: On Friday, 13 March 2020 at 16:04:06 UTC, Mike Parker wrote: On Friday, 13 March 2020 at 15:16:06 UTC, wjoe wrote: bindSymbol(&apiVersion, "VersionOfAPI"); } Is it possible to convince the compiler to look the other way while bindi

Re: Is it possible to dynamically load a @safe function from a shared library ?

2020-03-13 Thread wjoe via Digitalmars-d-learn
On Friday, 13 March 2020 at 17:05:32 UTC, Mike Parker wrote: On Friday, 13 March 2020 at 16:11:53 UTC, wjoe wrote: On Friday, 13 March 2020 at 16:04:06 UTC, Mike Parker wrote: On Friday, 13 March 2020 at 15:16:06 UTC, wjoe wrote: bindSymbol(&apiVersion, "VersionOfAPI"); } Is it possib

std.net.curl.CurlException Couldn't resolve host name on handle

2020-03-13 Thread Vino via Digitalmars-d-learn
Hi All, Request your help, the below code is fetching the required data, after fetching the data at the end it throws the below errors , hence request your help on how to handle this issue. Code: import std.net.curl, std.stdio, std.conv: to; void main () { auto http = HTTP(); http.handle.

Re: Is it possible to dynamically load a @safe function from a shared library ?

2020-03-13 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Mar 13, 2020 at 06:11:01PM +, wjoe via Digitalmars-d-learn wrote: > On Friday, 13 March 2020 at 17:05:32 UTC, Mike Parker wrote: > > On Friday, 13 March 2020 at 16:11:53 UTC, wjoe wrote: > > > On Friday, 13 March 2020 at 16:04:06 UTC, Mike Parker wrote: [...] > > > > bindSymbol(cast(voi

Re: Is it possible to dynamically load a @safe function from a shared library ?

2020-03-13 Thread wjoe via Digitalmars-d-learn
On Friday, 13 March 2020 at 18:30:51 UTC, H. S. Teoh wrote: On Fri, Mar 13, 2020 at 06:11:01PM +, wjoe via Digitalmars-d-learn wrote: On Friday, 13 March 2020 at 17:05:32 UTC, Mike Parker wrote: > On Friday, 13 March 2020 at 16:11:53 UTC, wjoe wrote: > > On Friday, 13 March 2020 at 16:04:06

Re: Is it possible to dynamically load a @safe function from a shared library ?

2020-03-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/13/20 4:22 PM, wjoe wrote: I wasn't aware that pragma(mangle, ..) can practically name any function anything. So from what I understand, because, at least on Posix, since there's only a symbol name there's nothing I can do in my loader to verify that a function is or does what it claim to

Re: Is it possible to dynamically load a @safe function from a shared library ?

2020-03-13 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Mar 13, 2020 at 08:22:53PM +, wjoe via Digitalmars-d-learn wrote: [...] > So from what I understand, because, at least on Posix, since there's > only a symbol name there's nothing I can do in my loader to verify > that a function is or does what it claim to be/do. [...] As far as I kno

Re: Is it possible to dynamically load a @safe function from a shared library ?

2020-03-13 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Mar 13, 2020 at 04:31:16PM -0400, Steven Schveighoffer via Digitalmars-d-learn wrote: [...] > I would expect that something could be written to turn a signature > string into a mangling and also provide the correct type upon return. > Something like: > > auto f = getFunction!(@safe void f

Re: How can I append PATH to environment["PATH"] in runtime?

2020-03-13 Thread Marcone via Digitalmars-d-learn
On Friday, 13 March 2020 at 13:28:01 UTC, Steven Schveighoffer wrote: On 3/13/20 2:08 AM, Marcone wrote: environment["PATH"] ~= r";D:\folder\"; // Error Did you try the long way? environment["PATH"] = environment["PATH"] ~ r";D:\folder\"; It would be nice to have environment support opIndexO

Re: std.net.curl.CurlException Couldn't resolve host name on handle

2020-03-13 Thread Vino via Digitalmars-d-learn
On Friday, 13 March 2020 at 18:10:51 UTC, Vino wrote: Hi All, Request your help, the below code is fetching the required data, after fetching the data at the end it throws the below errors , hence request your help on how to handle this issue. Code: import std.net.curl, std.stdio, std.con

Re: std.net.curl.CurlException Couldn't resolve host name on handle

2020-03-13 Thread Andre Pany via Digitalmars-d-learn
On Saturday, 14 March 2020 at 04:24:20 UTC, Vino wrote: On Friday, 13 March 2020 at 18:10:51 UTC, Vino wrote: [...] Hi All, I was able to resolve this issue by upgrading DMD from V88 to V91.0, and now I am getting the below error when i set any of the below options http.handle.set(CurlO

Re: std.net.curl.CurlException Couldn't resolve host name on handle

2020-03-13 Thread Vino via Digitalmars-d-learn
On Saturday, 14 March 2020 at 04:24:20 UTC, Vino wrote: On Friday, 13 March 2020 at 18:10:51 UTC, Vino wrote: Hi All, Request your help, the below code is fetching the required data, after fetching the data at the end it throws the below errors , hence request your help on how to handle thi