Escaping ref to stack mem sometimes allowed in @safe?

2016-10-16 Thread Nick Sabalausky via Digitalmars-d-learn
This compiles. Is it supposed to? @safe ubyte[] foo() { ubyte[512] buf; auto slice = buf[0..$]; // Escaping reference to stack memory, right? return slice; } Or is the escaping reference detection not intended to be 100%? Or something else I'm missing? Should I

Re: Escaping ref to stack mem sometimes allowed in @safe?

2016-10-16 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/14/16 4:49 PM, Nick Sabalausky wrote: This compiles. Is it supposed to? @safe ubyte[] foo() { ubyte[512] buf; auto slice = buf[0..$]; // Escaping reference to stack memory, right? return slice; } Yes, this still is a problem, but Walter has a fix in the works. https://is

Re: Building DMD with DMD or LDC

2016-10-16 Thread ketmar via Digitalmars-d-learn
On Friday, 14 October 2016 at 15:13:58 UTC, Jonathan M Davis wrote: On Thursday, October 13, 2016 19:07:44 Nordlöw via Digitalmars-d-learn wrote: Is there a large speed difference in compilation time depending on whether the DMD used is built using DMD or LDC? I would be shocked if there weren

Re: Building DMD with DMD or LDC

2016-10-16 Thread ketmar via Digitalmars-d-learn
On Saturday, 15 October 2016 at 07:39:31 UTC, ketmar wrote: p.s. this is all about GNU/Linux on x86 arch. for other OS/arch it may be completely different.

Re: Variables with scoped destruction in closures

2016-10-16 Thread ketmar via Digitalmars-d-learn
On Saturday, 15 October 2016 at 05:41:05 UTC, Walter Bright wrote: The problem is the closure is generated when it is expected that the delegate will survive past the end of the scope (it's the whole point of a closure). But with a destructor that runs at the end of the scope, it cannot survive

Re: Variables with scoped destruction in closures

2016-10-16 Thread ketmar via Digitalmars-d-learn
On Saturday, 15 October 2016 at 07:55:30 UTC, ketmar wrote: p.s. compiler doesn't complain each time, only in some circumstances. i don't remember the exact code now, but some of it has nothing to do with closures at all -- no std.algo, no templates with lambda args, etc.

Using dub.json parameters in code

2016-10-16 Thread Gustav via Digitalmars-d-learn
Hi, I want to use the variables from dub.json. For example, use the parameter "name" to display information message. Now I read dub.json. Is there a way to import them? Please excuse any mistakes as English is my second language.

Re: Using dub.json parameters in code

2016-10-16 Thread cym13 via Digitalmars-d-learn
On Saturday, 15 October 2016 at 17:36:10 UTC, Gustav wrote: Hi, I want to use the variables from dub.json. For example, use the parameter "name" to display information message. Now I read dub.json. Is there a way to import them? Please excuse any mistakes as English is my second language.

Re: Cannot link with libphobos2.a with GCC 6.2 on Ubuntu 16.10

2016-10-16 Thread tcak via Digitalmars-d-learn
On Thursday, 13 October 2016 at 17:02:32 UTC, Nordlöw wrote: I just upgraded my Ubuntu to 16.10 and now my rebuilding of dmd from git master fails as /usr/bin/ld: idgen.o: relocation R_X86_64_32 against symbol `__dmd_personality_v0' can not be used when making a shared object; recompile with

Re: Speed of synchronized

2016-10-16 Thread tcak via Digitalmars-d-learn
On Sunday, 16 October 2016 at 08:41:26 UTC, Christian Köstlin wrote: Hi, for an exercise I had to implement a thread safe counter. This is what I came up with: [...] Could you try that: class ThreadSafe3Counter: Counter{ private long counter; private core.sync.mutex.Mutex mtx; publi

Re: Cannot link with libphobos2.a with GCC 6.2 on Ubuntu 16.10

2016-10-16 Thread tcak via Digitalmars-d-learn
On Sunday, 16 October 2016 at 17:42:44 UTC, tcak wrote: On Thursday, 13 October 2016 at 17:02:32 UTC, Nordlöw wrote: [...] I have upgraded my Ubuntu to 16.10 yesterday as well, and I am getting following error: /usr/bin/ld: obj/Debug/program.o: relocation R_X86_64_32 against symbol `_D9Exc

Speed of synchronized

2016-10-16 Thread Christian Köstlin via Digitalmars-d-learn
Hi, for an exercise I had to implement a thread safe counter. This is what I came up with: ---SNIP--- import std.stdio; import core.thread; import std.conv; import std.datetime; static import core.atomic; import core.sync.mutex; int NR_OF_THREADS = 100; int NR_OF_INCREMENTS = 1; interface

Re: Building DMD with DMD or LDC

2016-10-16 Thread Johan Engelen via Digitalmars-d-learn
On Saturday, 15 October 2016 at 07:39:31 UTC, ketmar wrote: On Friday, 14 October 2016 at 15:13:58 UTC, Jonathan M Davis wrote: On Thursday, October 13, 2016 19:07:44 Nordlöw via Digitalmars-d-learn wrote: Is there a large speed difference in compilation time depending on whether the DMD used i

Re: Cannot link with libphobos2.a with GCC 6.2 on Ubuntu 16.10

2016-10-16 Thread Nordlöw via Digitalmars-d-learn
On Sunday, 16 October 2016 at 20:01:21 UTC, tcak wrote: Hmm. As the error message says, I compiled the program by adding "-fPIC", it really has stopped giving error messages. That came to me weird. Which flag(s) in `src/posix.mak` did you change?

Is this should work?

2016-10-16 Thread markov via Digitalmars-d-learn
void test(string line){ ... }; void main(){ string[] list; foreach (line; list) new Thread({test(line);}).start(); ... }

Re: Cannot link with libphobos2.a with GCC 6.2 on Ubuntu 16.10

2016-10-16 Thread Nordlöw via Digitalmars-d-learn
On Sunday, 16 October 2016 at 22:00:48 UTC, Nordlöw wrote: Which flag(s) in `src/posix.mak` did you change? Does make -f posix.mak MODEL_FLAG=-fPIC work? I'm sitting on a 16.04 system right now (which I don't dare to upgrade until this is fixed) so I'm just guessing.

Render SVG To Display And Update Periodically

2016-10-16 Thread Jason C. Wells via Digitalmars-d-learn
I have in mind a project to render instruments (speed, pressure, position) to a screen using SVG. I am able to produce the SVG easily enough. What I am looking for is a library/canvas/toolkit that I can use in D inside of a loop and update the instrument readouts. This whole project is a vehi

Re: Is this should work?

2016-10-16 Thread Ali Çehreli via Digitalmars-d-learn
On 10/16/2016 03:22 PM, markov wrote: void test(string line){ ... }; void main(){ string[] list; foreach (line; list) new Thread({test(line);}).start(); ... } It works in an unexpected way: In D, all those threads would close over the same 'line' loop variable, which happens to poi

Re: Render SVG To Display And Update Periodically

2016-10-16 Thread rikki cattermole via Digitalmars-d-learn
On 17/10/2016 2:20 PM, Jason C. Wells wrote: I have in mind a project to render instruments (speed, pressure, position) to a screen using SVG. I am able to produce the SVG easily enough. What I am looking for is a library/canvas/toolkit that I can use in D inside of a loop and update the instrume

Re: Speed of synchronized

2016-10-16 Thread Daniel Kozak via Digitalmars-d-learn
Dne 16.10.2016 v 10:41 Christian Köstlin via Digitalmars-d-learn napsal(a): My question now is, why is each mutex based thread safe variant so slow compared to a similar java program? The only hint could be something like: https://blogs.oracle.com/dave/entry/java_util_concurrent_reentrantlock_vs

Re: Cannot link with libphobos2.a with GCC 6.2 on Ubuntu 16.10

2016-10-16 Thread tcak via Digitalmars-d-learn
On Sunday, 16 October 2016 at 22:36:15 UTC, Nordlöw wrote: On Sunday, 16 October 2016 at 22:00:48 UTC, Nordlöw wrote: Which flag(s) in `src/posix.mak` did you change? Does make -f posix.mak MODEL_FLAG=-fPIC work? I'm sitting on a 16.04 system right now (which I don't dare to upgrade un

Re: Speed of synchronized

2016-10-16 Thread Christian Köstlin via Digitalmars-d-learn
On 16/10/16 19:50, tcak wrote: > On Sunday, 16 October 2016 at 08:41:26 UTC, Christian Köstlin wrote: >> Hi, >> >> for an exercise I had to implement a thread safe counter. This is what >> I came up with: >> >> [...] > > Could you try that: > > class ThreadSafe3Counter: Counter{ > private long

Re: Speed of synchronized

2016-10-16 Thread Christian Köstlin via Digitalmars-d-learn
On 17/10/16 06:55, Daniel Kozak via Digitalmars-d-learn wrote: > Dne 16.10.2016 v 10:41 Christian Köstlin via Digitalmars-d-learn napsal(a): > >> My question now is, why is each mutex based thread safe variant so slow >> compared to a similar java program? The only hint could be something >> like:

Re: Speed of synchronized

2016-10-16 Thread Daniel Kozak via Digitalmars-d-learn
Dne 17.10.2016 v 07:55 Christian Köstlin via Digitalmars-d-learn napsal(a): to run java call ./gradlew clean build -> counter.AtomicIntCounter@25992ae3 expected: 200 got: 100 in: 22ms counter.AtomicLongCounter@2539f946 expected: 200 got: 100 in: 17ms counter.ThreadSafe2Counter@52

Re: Speed of synchronized

2016-10-16 Thread Daniel Kozak via Digitalmars-d-learn
On Monday, 17 October 2016 at 06:38:08 UTC, Daniel Kozak wrote: Dne 17.10.2016 v 07:55 Christian Köstlin via Digitalmars-d-learn napsal(a): [...] I am still unable to get your java code working: [kozak@dajinka threads]$ ./gradlew clean build :clean :compileJava :processResources UP-TO-DATE :c