Re: Deallocate array?

2013-05-10 Thread Steven Schveighoffer
On Fri, 10 May 2013 04:44:14 -0400, Matic Kukovec wrote: Thanks for the explanation guys. Hope there will be improvements in D's GC in the future. Also "delete temp_array" also works instead of "GC.free(temp_array.ptr)". And you also need to call "GC.minimize()" after a delete/GC.free() if

Re: Deallocate array?

2013-05-10 Thread Matic Kukovec
Thanks for the explanation guys. Hope there will be improvements in D's GC in the future. Also "delete temp_array" also works instead of "GC.free(temp_array.ptr)". And you also need to call "GC.minimize()" after a delete/GC.free() if you want to shrink the memory use after the for loop:

Re: Deallocate array?

2013-05-09 Thread Ali Çehreli
On 05/09/2013 07:43 PM, Steven Schveighoffer wrote: > On Thu, 09 May 2013 22:14:41 -0400, Ali Çehreli wrote: >> Then, each of those strings point at 22 bytes of individully allocated >> memory areas. > > No, each array points at static data. Strings are immutables stored in > the data segmen

Re: Deallocate array?

2013-05-09 Thread Steven Schveighoffer
On Thu, 09 May 2013 22:14:41 -0400, Ali Çehreli wrote: On a 32-bit system string is 8 bytes (e.g. by pragma(msg, string.sizeof)). So you have a single array of 800 million bytes. Then, each of those strings point at 22 bytes of individully allocated memory areas. No, each array points at

Re: Deallocate array?

2013-05-09 Thread Ali Çehreli
On 05/09/2013 05:58 PM, Matic Kukovec wrote: > Hi again Steve, or anyone else whose reading this. > I was playing around with D and C# and need help getting this array > stuff to work. [...] > My question is what is how do i get the same C# functionality in D > without running out of memory and

Re: Deallocate array?

2013-05-09 Thread Matic Kukovec
Hi again Steve, or anyone else whose reading this. I was playing around with D and C# and need help getting this array stuff to work. My D program: import std.stdio, std.cstream, std.array; void main() { string[] temp_array = new string[1]; for(int i=0;i<1;i++)

Re: Deallocate array?

2013-05-08 Thread Steven Schveighoffer
On Wed, 08 May 2013 08:28:50 -0400, Matic Kukovec wrote: Thanks for the explanation Steve. Can you please give me a correct example of: - creating a dynamic string array auto arr = new char[N]; N can be a runtime value. - looping over it and adding values Not sure what you mean here.

Re: Deallocate array?

2013-05-08 Thread Matic Kukovec
On Wednesday, 8 May 2013 at 12:03:08 UTC, Steven Schveighoffer wrote: On Wed, 08 May 2013 06:20:45 -0400, Matic Kukovec wrote: Was playing around with the code and found that this WORKS: (note the "app_temp_array.reserve(5000);" at the top, without this line it doesn't work) [snip] T

Re: Deallocate array?

2013-05-08 Thread Steven Schveighoffer
On Wed, 08 May 2013 06:20:45 -0400, Matic Kukovec wrote: Was playing around with the code and found that this WORKS: (note the "app_temp_array.reserve(5000);" at the top, without this line it doesn't work) [snip] The memory usage shrinks from 400MB to 2MB, which is right! Why? Thi

Re: Deallocate array?

2013-05-08 Thread Matic Kukovec
Was playing around with the code and found that this WORKS: (note the "app_temp_array.reserve(5000);" at the top, without this line it doesn't work) import std.stdio, core.memory, std.cstream, std.array; void main() { string[] temp_array; Appender!(string[]) app_temp_array =

Re: Deallocate array?

2013-05-08 Thread Matic Kukovec
On Wednesday, 8 May 2013 at 08:59:57 UTC, Minas Mina wrote: On Tuesday, 7 May 2013 at 23:09:29 UTC, 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

Re: Deallocate array?

2013-05-08 Thread Minas Mina
On Tuesday, 7 May 2013 at 23:09:29 UTC, 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_arra

Re: Deallocate array?

2013-05-08 Thread Matic Kukovec
Thanks you guys for all the suggestions. bearophile: I am not creating 64 bit binaries. Tried compiling with or without the "-m32" flag. I have played around with GC.free, see below for more details. Juan Manuel Cabo: I tried your methods, but no change. The original program I described earlie

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