Re: Dispatching values to handlers, as in std.concurrency

2013-05-07 Thread Idan Arye
On Tuesday, 7 May 2013 at 00:15:06 UTC, Luís Marques wrote: On Monday, 6 May 2013 at 23:53:51 UTC, Idan Arye wrote: If the type handlers are your own classes, then you can let them check it. Have a method in the handlers that check if an object can be handled by that handler, and use it on

Argument S to typeof is not an expression

2013-05-07 Thread Meta
template Test(alias N) if (isIntegral!(typeof(N))) { struct S { typeof(N) n = N; auto opAdd(T)(T rhs) { //Error: argument S to typeof is not an expression pragma(msg, typeof(T)); //Error: variable rhs cannot be read at compile

Re: Argument S to typeof is not an expression

2013-05-07 Thread Anonimous
On Tuesday, 7 May 2013 at 06:41:25 UTC, Meta wrote: template Test(alias N) if (isIntegral!(typeof(N))) { struct S { typeof(N) n = N; auto opAdd(T)(T rhs) { //Error: argument S to typeof is not an expression pragma(msg, typeof(T));

Re: Argument S to typeof is not an expression

2013-05-07 Thread Anonimous
Sorry for my english.

How to reserve memory for a slice in a struct

2013-05-07 Thread Namal
Hello, I am new to D. According to that power of 2 rule I want to reserve 2 sized chunks to my array, But how do I do that in a struct? Say: struct Stack(int){ int a[]; } Where do I put that a.reserve(2); Because right after the declaration of a I get an error Error: unexpected ( in

Re: Argument S to typeof is not an expression

2013-05-07 Thread Dicebot
On Tuesday, 7 May 2013 at 06:41:25 UTC, Meta wrote: I don't really understand why either of these error messages are occurring. The first is just incomprehensible, and the second seems like it should work. In this case, rhs is fully accessible at compile time in the expression (a + b), so why

Re: How to reserve memory for a slice in a struct

2013-05-07 Thread John Colvin
On Tuesday, 7 May 2013 at 10:29:44 UTC, Namal wrote: Hello, I am new to D. According to that power of 2 rule I want to reserve 2 sized chunks to my array, But how do I do that in a struct? Say: struct Stack(int){ int a[]; } 2 sized chunks? Perhaps you want something like this: struct

Re: Argument S to typeof is not an expression

2013-05-07 Thread Jacob Carlborg
On 2013-05-07 08:41, Meta wrote: template Test(alias N) if (isIntegral!(typeof(N))) { struct S { typeof(N) n = N; auto opAdd(T)(T rhs) { //Error: argument S to typeof is not an expression pragma(msg, typeof(T));

Re: Argument S to typeof is not an expression

2013-05-07 Thread Dicebot
On Tuesday, 7 May 2013 at 11:03:31 UTC, Jacob Carlborg wrote: As a workaround for typeof you can use this: https://github.com/jacob-carlborg/orange/blob/master/orange/util/Traits.d#L213 You may want to update your implementation: http://dpaste.1azy.net/640a2580

Re: How to reserve memory for a slice in a struct

2013-05-07 Thread evilrat
On Tuesday, 7 May 2013 at 10:58:42 UTC, John Colvin wrote: ... int a[]; please don't use C style declarations, D style is type followed by id: int[] a;

Re: How to reserve memory for a slice in a struct

2013-05-07 Thread Steven Schveighoffer
On Tue, 07 May 2013 06:29:43 -0400, Namal soti...@mail.ru wrote: Hello, I am new to D. According to that power of 2 rule I want to reserve 2 sized chunks to my array, But how do I do that in a struct? Say: struct Stack(int){ int a[]; } Where do I put that a.reserve(2); Because right

Re: How to reserve memory for a slice in a struct

2013-05-07 Thread Maxim Fomin
On Tuesday, 7 May 2013 at 10:29:44 UTC, Namal wrote: Hello, I am new to D. According to that power of 2 rule I want to reserve 2 sized chunks to my array, But how do I do that in a struct? You can set some kind of statically allocated array size: struct S { int[] a;

Re: WinAPI callbacks and GC

2013-05-07 Thread Regan Heath
On Tue, 07 May 2013 00:03:58 +0100, Sean Kelly s...@invisibleduck.org wrote: On May 2, 2013, at 6:17 AM, Regan Heath re...@netmail.co.nz wrote: On Wed, 01 May 2013 01:12:39 +0100, Sean Kelly s...@invisibleduck.org wrote: On Apr 23, 2013, at 2:21 PM, Jack Applegame jappleg...@gmail.com

unittest + struct ctorю + nested mixin template + alias

2013-05-07 Thread ref2401
Version D 2.062 class MyClass {} struct MyStruct(T) if (is(T == class)) { string _message = nothing; this(T obj) { if (obj is null){ _message = Null reference message; } else{

Re: Argument S to typeof is not an expression

2013-05-07 Thread Meta
On Tuesday, 7 May 2013 at 10:33:58 UTC, Dicebot wrote: On Tuesday, 7 May 2013 at 06:41:25 UTC, Meta wrote: I don't really understand why either of these error messages are occurring. The first is just incomprehensible, and the second seems like it should work. In this case, rhs is fully

Re: unittest + struct ctorю + nested mixin template + alias

2013-05-07 Thread Steven Schveighoffer
On Tue, 07 May 2013 10:58:09 -0400, ref2401 refacto...@gmail.com wrote: Version D 2.062 class MyClass {} struct MyStruct(T) if (is(T == class)) { string _message = nothing; this(T obj) { if (obj is null){ _message = Null

Re: unittest + struct ctorю + nested mixin template + alias

2013-05-07 Thread ref2401
i'm using VisualD. this assertion fails assert(msg == Null reference message); in my actual code instead of variable _message an exception is thrown if (obj is null) == true. i'm using the unittest block to test exception throwing. ... this(T obj) { if (obj is

Re: How to reserve memory for a slice in a struct

2013-05-07 Thread Diggory
You could allocate space inside a class itself with something like this: class Base { int[] slice; } template Derived(size_t N) { class Derived : Base { int[N] array; this() { slice = array; } } } Base b = new Derived!32(); A bit pointless

Re: Argument S to typeof is not an expression

2013-05-07 Thread Jacob Carlborg
On 2013-05-07 13:08, Dicebot wrote: You may want to update your implementation: http://dpaste.1azy.net/640a2580 Thanks. -- /Jacob Carlborg

Deallocate array?

2013-05-07 Thread Matic Kukovec
Hi I'm running Windows Vista 64 with dmd 2.062. I have a simple program: import std.stdio, core.memory, std.cstream; void main() { string[] temp_array; for(int i=0;i500;i++) { ++temp_array.length; temp_array[temp_array.length - 1] =

Re: Deallocate array?

2013-05-07 Thread Ali Çehreli
On 05/07/2013 04:09 PM, Matic Kukovec wrote: Hi When the program waits at din.getc();, memory usage in the Task Manager is 150MB. Why isn't the memory deallocating? P.S.; I tried temp_array.clear() and destroy(temp_array), but nothing changed. GC.minimize() may work. Ali

Re: Deallocate array?

2013-05-07 Thread Matic Kukovec
On Tuesday, 7 May 2013 at 23:14:20 UTC, Ali Çehreli wrote: On 05/07/2013 04:09 PM, Matic Kukovec wrote: Hi When the program waits at din.getc();, memory usage in the Task Manager is 150MB. Why isn't the memory deallocating? P.S.; I tried temp_array.clear() and destroy(temp_array), but

Re: Deallocate array?

2013-05-07 Thread Ali Çehreli
On 05/07/2013 04:18 PM, Matic Kukovec wrote: On Tuesday, 7 May 2013 at 23:14:20 UTC, Ali Çehreli wrote: GC.minimize() may work. Tried it, no changes. Works for your test program under Linux but as the documentation says, it is not guaranteed to have any effect at all. Ali

Re: Deallocate array?

2013-05-07 Thread Matic Kukovec
On Tuesday, 7 May 2013 at 23:31:41 UTC, Ali Çehreli wrote: On 05/07/2013 04:18 PM, Matic Kukovec wrote: On Tuesday, 7 May 2013 at 23:14:20 UTC, Ali Çehreli wrote: GC.minimize() may work. Tried it, no changes. Works for your test program under Linux but as the documentation says, it is not

Re: Deallocate array?

2013-05-07 Thread Ali Çehreli
On 05/07/2013 04:42 PM, Matic Kukovec wrote: On Tuesday, 7 May 2013 at 23:31:41 UTC, Ali Çehreli wrote: On 05/07/2013 04:18 PM, Matic Kukovec wrote: On Tuesday, 7 May 2013 at 23:14:20 UTC, Ali Çehreli wrote: GC.minimize() may work. Tried it, no changes. Works for your test program

Re: Deallocate array?

2013-05-07 Thread bearophile
Matic Kukovec: The system is Windows Vista 64bit. DMD is 2.062. DMD doesn't yet produce 64 bit binaries on Windows. I have tried to solve your problem using GC.free, but I am not seeing good results... Bye, bearophile

Re: Deallocate array?

2013-05-07 Thread Juan Manuel Cabo
Why isn't the memory deallocating? The memory might be free, but still not released to the OS. Especially in windows, when you free memory it still isn't freed from your process. But you can reuse it in your program if the GC has collected it. The correct test would be to copy and paste

Re: Deallocate array?

2013-05-07 Thread Juan Manuel Cabo
I found this problem with a program that reads a large xml file (25+ lines), then stores the lines in a string[], does a comparison with another array and finally clears the original array. On the second or third file I always get an OutOfMemoryError, when the Task Manager shows about

Re: Deallocate array?

2013-05-07 Thread Steven Schveighoffer
On Tue, 07 May 2013 19:09:28 -0400, Matic Kukovec matic.kuko...@pametnidom.si wrote: Hi I'm running Windows Vista 64 with dmd 2.062. I have a simple program: import std.stdio, core.memory, std.cstream; void main() { string[] temp_array; for(int i=0;i500;i++) {