Re: Who wants to have some fun memory debugging?

2009-05-12 Thread grauzone
Maybe it's time to put together an instrumented GC... Wishlist: - some way to know _when_ a collection happened (or how often) - logging of allocations (module/linenumber of allocator, size of allocation, type of allocation) - per TypeInfo allocation statistics - per module allocation statisti

Re: Who wants to have some fun memory debugging?

2009-05-12 Thread Daniel Keep
Sean Kelly wrote: > ... > > At this point it's quite possible that you still have a reference to > newData in a register. If you want to be sure the collect call below > works as intended for this test, try adding: > > newData = new Data; > > here. Debugging it with ddbg under Win

Re: Who wants to have some fun memory debugging?

2009-05-12 Thread grauzone
Wild guess: there's a false pointer, that keeps one element in the list from being collected, and because the list-prev pointers are still there, all following elements won't be collected either in consequence. If I had time, I'd try two experiments: 1. before freeing everything, reset the prev

Re: Who wants to have some fun memory debugging?

2009-05-12 Thread Robert Fraser
Sean Kelly wrote: At this point it's quite possible that you still have a reference to newData in a register. That argument works for one iteration, but this fool just keeps on growing. Also, this is a pared down test from a much larger program, so this is unlikely. If you want to be sure

Re: Who wants to have some fun memory debugging?

2009-05-12 Thread Sean Kelly
Robert Fraser wrote: Simpler version, sans printf: module leak; import tango.core.Memory; struct Data { Data* prev; char[4092] something; } public void main() { Data* data; Data* newData; int i; while(true) { for(i = 0; i < 10_000; i++) {

Re: Who wants to have some fun memory debugging?

2009-05-12 Thread Robert Fraser
Simpler version, sans printf: module leak; import tango.core.Memory; struct Data { Data* prev; char[4092] something; } public void main() { Data* data; Data* newData; int i; while(true) { for(i = 0; i < 10_000; i++) { newData = new Data;

Re: A couple of questions

2009-05-12 Thread BCS
Hello Sam, Hello, For the given example below, E1: template Chain(R...) if (allSatisfy!(isInputRange, R)) { static if (R.length > 1) alias ChainImpl!(R) Chain; else alias R[0] Chain; } Q1: What's *if* statement doing right after the template definite?I can guess what the purpose is but I can n

Who wants to have some fun memory debugging?

2009-05-12 Thread Robert Fraser
Running this program with Tango SVN + DMD 1.045 or Tango 0.98 + DMD 1.041 on WinXP SP3 32-bit results in a memory leak (the program keeps increasing in size at every iteration) leak.d: --- module leak; import tango.stdc.stdio; import tango.core.Memory;

A couple of questions

2009-05-12 Thread Sam Hu
Hello, For the given example below, E1: template Chain(R...) if (allSatisfy!(isInputRange, R)) { static if (R.length > 1) alias ChainImpl!(R) Chain; else alias R[0] Chain; } Q1: What's *if* statement doing right after the template definite?I can guess what the purpose is

invariant

2009-05-12 Thread saotome
Hi all, i want to declare an invariant interger, for instance "invariant int x = 3;". But i've got this error while compiling. Error: constant 3 is not an lvalue could someone explain me what's wrong here ? I'm using dmd 2.030

Re: 3 variant questions

2009-05-12 Thread Saaa
> Dear Saaa, these varargs suck badly and you shouldn't use them. It's so > simple to introduce portability errors or heisenbugs, and it's heisenbugs :) > incredibly hard to get it right. You're better off with alternatives. > > Alternative 1: Typesafe Variadic Functions > Useful if the variadic a

Re: 3 variant questions

2009-05-12 Thread Saaa
>> > > You get an AV because you're passing the argument by value. You need to > pass its address instead. > > Try this: > > void main() { > int i; > get(file, "i", &i); > writeln(i); > } > > It will print "7". Ah of course, thanks.

Re: 3 variant questions

2009-05-12 Thread grauzone
Dear Saaa, these varargs suck badly and you shouldn't use them. It's so simple to introduce portability errors or heisenbugs, and it's incredibly hard to get it right. You're better off with alternatives. Alternative 1: Typesafe Variadic Functions Useful if the variadic arguments should have on

Re: 3 variant questions

2009-05-12 Thread John C
Saaa Wrote: > > > > import std.stdarg; > > > > assert( _arguments[0] is typeid(int*) ); > > auto arg = va_arg!(int*)(_argptr); > > *arg = 10; > > > > Probably. > > > > -- Daniel > > Calling the following returns an Access Violation Error after > correctly writing the two lines. > > void main()

Re: Threading

2009-05-12 Thread Saaa
"Georg Wrede" wrote in message news:guc6ep$2im...@digitalmars.com... > Saaa wrote: > Steven Schveighoffer wrote: >>> i.e. I want thread 1 to initialize elements 0, 1, and 2, and thread 2 to >>> initialize elements 3, 4, and 5: >>> >>> thread1 = new ProcessingThread(arrayToInit[0..3]); >>> threa

Re: 3 variant questions

2009-05-12 Thread Saaa
> > import std.stdarg; > > assert( _arguments[0] is typeid(int*) ); > auto arg = va_arg!(int*)(_argptr); > *arg = 10; > > Probably. > > -- Daniel Calling the following returns an Access Violation Error after correctly writing the two lines. void main() { int i; get( file, `i`, i); } public void

Re: Threading

2009-05-12 Thread Georg Wrede
Saaa wrote: Steven Schveighoffer wrote: i.e. I want thread 1 to initialize elements 0, 1, and 2, and thread 2 to initialize elements 3, 4, and 5: thread1 = new ProcessingThread(arrayToInit[0..3]); thread2 = new ProcessingThread(arrayToInit[3..6]); thread1.start(); thread2.start(); Should be co

Re: Threading

2009-05-12 Thread Saaa
>>> I probably should have phrased my question better with the array, what I was wondering is if it was safe for say two threads to right to the array at the same time as long as I'm sure they're not writing to the same index of the array? >>> >>> You can d

Re: Threading

2009-05-12 Thread Steven Schveighoffer
On Tue, 12 May 2009 10:12:48 -0400, Saaa wrote: I probably should have phrased my question better with the array, what I was wondering is if it was safe for say two threads to right to the array at the same time as long as I'm sure they're not writing to the same index of the array?

Re: Threading

2009-05-12 Thread Saaa
> >> I probably should have phrased my question better with the array, what I >> was >> wondering is if it was safe for say two threads to right to the array at >> the same >> time as long as I'm sure they're not writing to the same index of the >> array? > > You can do anything you want withou

Re: Threading

2009-05-12 Thread Steven Schveighoffer
On Tue, 12 May 2009 05:11:49 -0400, Brok3n Halo wrote: I probably should have phrased my question better with the array, what I was wondering is if it was safe for say two threads to right to the array at the same time as long as I'm sure they're not writing to the same index of the arra

Re: 3 variant questions

2009-05-12 Thread Daniel Keep
Saaa wrote: > ... >> var_arg!(T) will convert _argptr into the type you specify and it will >> also advance _argptr to the next argument. > What would happen if you'd cast it incorrectly if it wasn't a simple pointer > ? :D Same as would happen if you incorrectly cast anything. i.e. anything.

Re: 3 variant questions

2009-05-12 Thread Saaa
"Daniel Keep" wrote in message news:gubip2$187...@digitalmars.com... > > > Saaa wrote: >> I just noticed D1 does have std.stdarg. >> I shouldn't just search on the website :( >> (where it is missing on the phobos page) >> >>> import std.stdarg; >>> >>> assert( _arguments[0] is typeid(int*) ); >>

Re: 3 variant questions

2009-05-12 Thread Daniel Keep
Saaa wrote: > I just noticed D1 does have std.stdarg. > I shouldn't just search on the website :( > (where it is missing on the phobos page) > >> import std.stdarg; >> >> assert( _arguments[0] is typeid(int*) ); >> auto arg = va_arg!(int*)(_argptr); >> *arg = 10; >> >> Probably. > :D >> -- Dani

Re: 3 variant questions

2009-05-12 Thread Saaa
I just noticed D1 does have std.stdarg. I shouldn't just search on the website :( (where it is missing on the phobos page) > import std.stdarg; > > assert( _arguments[0] is typeid(int*) ); > auto arg = va_arg!(int*)(_argptr); > *arg = 10; > > Probably. :D > > -- Daniel So, you make arg point to

Re: 3 variant questions

2009-05-12 Thread Daniel Keep
Saaa wrote: >> Saaa wrote: >>> ... >>> Passing variadic arguments as ref I think is what I am asking for :) >> You can't. You have to explicitly take the address of the arguments. >> >> -- Daniel > > Like this ? > *_argptr = 10; > :D > > I don't know how to tell the compiler I want to write d

Re: Threading

2009-05-12 Thread Saaa
I have never used threads before, but it sounds safe to me as when the thread gets thrown of the core and later gets back nothing referred by the register has changed. Again, I am a newbie :) "Brok3n Halo" wrote in message news:gubegl$uu...@digitalmars.com... >I probably should have phrased my

Re: 3 variant questions

2009-05-12 Thread Saaa
> Saaa wrote: >> ... >> Passing variadic arguments as ref I think is what I am asking for :) > > You can't. You have to explicitly take the address of the arguments. > > -- Daniel Like this ? *_argptr = 10; :D I don't know how to tell the compiler I want to write data there.

Re: Threading

2009-05-12 Thread Brok3n Halo
I probably should have phrased my question better with the array, what I was wondering is if it was safe for say two threads to right to the array at the same time as long as I'm sure they're not writing to the same index of the array? Also I'm still getting the "Error: Win32 Exception" with my t

Re: 3 variant questions

2009-05-12 Thread Daniel Keep
Saaa wrote: > ... > Passing variadic arguments as ref I think is what I am asking for :) You can't. You have to explicitly take the address of the arguments. -- Daniel