Re: Why does scopedTask increase memory consumption?

2011-11-21 Thread Andrej Mitrovic
Magic uncovered, it's because the Task instantiates its own private task pool: void executeInNewThread() @trusted { pool = new TaskPool(basePtr); } Ok, so I need to keep my own thread pool or use the global one and then use task() to create a task and add it to the pool. I can do

Re: mixin on identifier

2011-11-21 Thread David Nadlinger
Turns out to be surprisingly tricky… A possible solution is: mixin template StateOne() { int value; } mixin template StateTwo() { float data; } mixin template MixinAll(T...) { static if (T.length > 0) { alias T[0] A; mixin A; mixin MixinAll!(T[1 .. $]); } } class StateSet(T

Re: Is __VERSION__ cross-compiler compatible?

2011-11-21 Thread Andrej Mitrovic
GDC does seem to use this, now that I've tested it: D:\dev\code\d_code>gdc test.d 1067L D:\dev\code\d_code>gdc -v2 test.d 2052L I've found the docs, it states this is a compiler token: http://d-programming-language.org/lex.html (section Special Tokens) But being able to target a *language versi

Re: Is __VERSION__ cross-compiler compatible?

2011-11-21 Thread Jonathan M Davis
On Tuesday, November 22, 2011 02:10:51 Andrej Mitrovic wrote: > I've seen this code used somwhere: > > static if (__VERSION__ > 2048) > { > } > > Does this work for all compilers, or is it DMD-specific? Also, does > DMD1 define this too? I'm trying to retain compatibility of some D1 > sample code

Is __VERSION__ cross-compiler compatible?

2011-11-21 Thread Andrej Mitrovic
I've seen this code used somwhere: static if (__VERSION__ > 2048) { } Does this work for all compilers, or is it DMD-specific? Also, does DMD1 define this too? I'm trying to retain compatibility of some D1 sample code but introduce D2 support as well.

Why does scopedTask increase memory consumption?

2011-11-21 Thread Andrej Mitrovic
import core.thread; import std.parallelism; import std.stdio; enum loops = 100; void runTask() { static void test() { } auto newTask = scopedTask(&test); newTask.executeInNewThread(); newTask.yieldForce(); } void main() { foreach (_; 0 .. loops) runTask(); writel

Re: mixin on identifier

2011-11-21 Thread Johannes Totz
On 21/11/2011 23:39, David Nadlinger wrote: Make T an alias parameter: class StateSet(alias T) { … } David Thanks! I was trying to get to something like this: mixin template StateOne() { int value; } mixin template StateTwo() { float data; } class StateSet(alias T ...

Re: mixin on identifier

2011-11-21 Thread David Nadlinger
Make T an alias parameter: class StateSet(alias T) { … } David On 11/22/11 12:38 AM, Johannes Totz wrote: mixin template StateOne() { intvalue; } class StateSet(T) { mixin T; } int main(string[] argv) { StateSet!StateOnes = new StateSet!StateOne(); return 0; }

mixin on identifier

2011-11-21 Thread Johannes Totz
Hi! I'm trying to do: mixin template StateOne() { int value; } class StateSet(T) { mixin T; } int main(string[] argv) { StateSet!StateOne s = new StateSet!StateOne(); return 0; } Compiler complains with: main.d(18): Error: template instance StateSet!

Re: Make a variable single-assignment?

2011-11-21 Thread Andrej Mitrovic
The only thing I can think of: struct Once(T) { this(T val) { i = val; } immutable T i; alias i this; } void main() { Once!int i = 1; // ok i = 4; // ng } However it seems I've found a little hole in the system: void foo(ref int x) { x = 2; } void mai

Re: Make a variable single-assignment?

2011-11-21 Thread Jesse Phillips
What you are describing is Head Const, and is not available. http://www.d-programming-language.org/const-faq.html#head-const It will not be added as it doesn't provide any guarantees about the code that is useful to the compiler. It can't be added to the existing system without complicating the

Re: Queue thread

2011-11-21 Thread Andrej Mitrovic
How come you don't have any threads per CPU? I guess this is a difference between multi-processor and multi-core machines maybe?

Re: Make a variable single-assignment?

2011-11-21 Thread Robert Clipsham
On 21/11/2011 14:04, Alex Rønne Petersen wrote: Hi, Is there any way to make a variable single-assignment, regardless of its type? I.e.: void foo() { int i = 0; i = 2; // Error: i cannot be reassigned } I realize const and immutable will do this, but they are transitive and infect the type, w

Re: Make a variable single-assignment?

2011-11-21 Thread Alex Rønne Petersen
On 21-11-2011 17:17, Kapps wrote: For one reason, public fields that lack a set without having to create a backing field, followed by a bulky property. It does sound lazy, but when it's something you have to repeat many times, it gets annoying. On 21/11/2011 9:43 AM, Ary Manzana wrote: On 11/21

Re: Queue thread

2011-11-21 Thread Kai Meyer
On 11/20/2011 02:36 PM, bioinfornatics wrote: Le dimanche 20 novembre 2011 à 03:09 -0800, Jonathan M Davis a écrit : On Sunday, November 20, 2011 11:59:14 bioinfornatics wrote: Dear, I would like to know if they are a way to run run a queue thread an run (nb core * 2 + 1) = nb thread in same ti

Re: Make a variable single-assignment?

2011-11-21 Thread deadalnix
Le 21/11/2011 15:04, Alex Rønne Petersen a écrit : Hi, Is there any way to make a variable single-assignment, regardless of its type? I.e.: void foo() { int i = 0; i = 2; // Error: i cannot be reassigned } I realize const and immutable will do this, but they are transitive and infect the type

Re: Make a variable single-assignment?

2011-11-21 Thread Timon Gehr
On 11/21/2011 03:04 PM, Alex Rønne Petersen wrote: Hi, Is there any way to make a variable single-assignment, regardless of its type? I.e.: void foo() { int i = 0; i = 2; // Error: i cannot be reassigned } I realize const and immutable will do this, but they are transitive and infect the type

Re: Make a variable single-assignment?

2011-11-21 Thread Kapps
For one reason, public fields that lack a set without having to create a backing field, followed by a bulky property. It does sound lazy, but when it's something you have to repeat many times, it gets annoying. On 21/11/2011 9:43 AM, Ary Manzana wrote: On 11/21/11 11:04 AM, Alex Rønne Petersen

Re: Make a variable single-assignment?

2011-11-21 Thread Ary Manzana
On 11/21/11 11:04 AM, Alex Rønne Petersen wrote: Hi, Is there any way to make a variable single-assignment, regardless of its type? I.e.: void foo() { int i = 0; i = 2; // Error: i cannot be reassigned } I realize const and immutable will do this, but they are transitive and infect the type,

Re: Make a variable single-assignment?

2011-11-21 Thread Alex Rønne Petersen
On 21-11-2011 15:48, Trass3r wrote: Don't think so. You could also wrap it in a struct with disabled opAssign, but this would also change the type. Perhaps allowing 'final' on fields and locals would be a nice way to gain this effect... - Alex

Re: Make a variable single-assignment?

2011-11-21 Thread Trass3r
Don't think so. You could also wrap it in a struct with disabled opAssign, but this would also change the type.

Make a variable single-assignment?

2011-11-21 Thread Alex Rønne Petersen
Hi, Is there any way to make a variable single-assignment, regardless of its type? I.e.: void foo() { int i = 0; i = 2; // Error: i cannot be reassigned } I realize const and immutable will do this, but they are transitive and infect the type, which I do *not* want. I simply want th