Re: Deallocate array?

2013-05-07 Thread Steven Schveighoffer
On Tue, 07 May 2013 19:09:28 -0400, Matic Kukovec 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;i<500;i++) { ++temp_

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 1.3GB

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 the

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 Matic Kukovec
On Tuesday, 7 May 2013 at 23:58:53 UTC, Ali Çehreli wrote: 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.minimiz

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

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

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: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

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

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;i<500;i++) { ++temp_array.length; temp_array[temp_array.length - 1] =

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

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 thoug

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: unittest + struct ctorю + nested mixin template + alias

2013-05-07 Thread Steven Schveighoffer
On Tue, 07 May 2013 10:58:09 -0400, ref2401 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 reference message";

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 access

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: WinAPI callbacks and GC

2013-05-07 Thread Regan Heath
On Tue, 07 May 2013 00:03:58 +0100, Sean Kelly wrote: On May 2, 2013, at 6:17 AM, Regan Heath wrote: On Wed, 01 May 2013 01:12:39 +0100, Sean Kelly wrote: On Apr 23, 2013, at 2:21 PM, Jack Applegame wrote: According WinAPI documentation, CtrlHandler will be called in new additio

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; this(size_

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 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 after the declarati

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: 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: 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)); //Error:

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 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

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 decla

Re: Argument S to typeof is not an expression

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

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));