Re: GC allocation issue

2014-03-20 Thread monarch_dodra
On Friday, 21 March 2014 at 00:56:22 UTC, Etienne wrote: I'm trying to store a copy of strings for long-running processes with malloc. I tried using emplace but the copy gets deleted by the GC. Any idea why? Could you show the snippet where you used "emplace"? I'd like to know how you are usi

Re: Function to print a diamond shape

2014-03-20 Thread Jay Norwood
On Friday, 21 March 2014 at 00:31:58 UTC, bearophile wrote: This is a somewhat common little exercise: Write a function Bye, bearophile I like that replicate but easier for me to keep track of the counts if I work from the center. int blanks[]; blanks.length = n; int stars[]; stars.length

Re: Troubles with taskPool.amap, lambdas and more

2014-03-20 Thread Vladimir Panteleev
On Wednesday, 19 March 2014 at 00:13:10 UTC, bearophile wrote: A problem (that is not a regression) is that taskPool.amap doesn't seem able to accept a lambda for some reason. The reason for that is that any function in D currently can have at most one context pointer. For class and struct met

Re: Function to print a diamond shape

2014-03-20 Thread Ali Çehreli
On 03/20/2014 02:25 PM, Ali Çehreli wrote: Write a function that takes the size of a diamond and produces a diamond of that size. I have learned a lot, especially the following two: 1) chain'ing iotas is an effective way of producing non-monotonic number intervals (and more). 2) There is s

Re: GC allocation issue

2014-03-20 Thread Etienne Cimon
On 2014-03-20 21:46, Etienne Cimon wrote: On 2014-03-20 21:08, Adam D. Ruppe wrote: On Friday, 21 March 2014 at 00:56:22 UTC, Etienne wrote: I tried using emplace but the copy gets deleted by the GC. Any idea why? That's extremely unlikely, the GC doesn't know how to free manually allocated t

Re: GC allocation issue

2014-03-20 Thread Etienne Cimon
On 2014-03-20 21:08, Adam D. Ruppe wrote: On Friday, 21 March 2014 at 00:56:22 UTC, Etienne wrote: I tried using emplace but the copy gets deleted by the GC. Any idea why? That's extremely unlikely, the GC doesn't know how to free manually allocated things. Are you sure that's where the crash

Re: GC allocation issue

2014-03-20 Thread Adam D. Ruppe
On Friday, 21 March 2014 at 00:56:22 UTC, Etienne wrote: I tried using emplace but the copy gets deleted by the GC. Any idea why? That's extremely unlikely, the GC doesn't know how to free manually allocated things. Are you sure that's where the crash happens? Taking a really quick look at

Re: GC allocation issue

2014-03-20 Thread Etienne
On 2014-03-20 8:39 PM, bearophile wrote: Etienne: I'm running some tests on a cache store where I planned to use only Malloc for the values being stored, I'm hoping to eliminate the GC in 95% of the program, but to keep it only for actively used items.. Usually 95%-100% of a D program uses th

Re: GC allocation issue

2014-03-20 Thread bearophile
Etienne: I'm running some tests on a cache store where I planned to use only Malloc for the values being stored, I'm hoping to eliminate the GC in 95% of the program, but to keep it only for actively used items.. Usually 95%-100% of a D program uses the GC and the 0%-5% uses malloc :-) By

Re: Function to print a diamond shape

2014-03-20 Thread bearophile
Ali Çehreli: This is a somewhat common little exercise: Write a function that takes the size of a diamond and produces a diamond of that size. When printed, here is the output for size 11: * *** * *** * *** * *** * *** *

Re: Function to print a diamond shape

2014-03-20 Thread Brad Anderson
On Thursday, 20 March 2014 at 22:46:53 UTC, Ali Çehreli wrote: On 03/20/2014 03:03 PM, Brad Anderson wrote: > I'm not entirely happy with it but: I am not happy with my attempt either. :) >void main() >{ > import std.algorithm, std.range, std.stdio, std.conv; > > enum length

Re: Function to print a diamond shape

2014-03-20 Thread Ali Çehreli
On 03/20/2014 03:48 PM, Timon Gehr wrote: On 03/20/2014 10:25 PM, Ali Çehreli wrote: This is a somewhat common little exercise: Write a function that takes the size of a diamond and produces a diamond of that size. When printed, here is the output for size 11: * *** * ***

Re: Function to print a diamond shape

2014-03-20 Thread Ali Çehreli
On 03/20/2014 02:52 PM, Chris Williams wrote: On Thursday, 20 March 2014 at 21:25:03 UTC, Ali Çehreli wrote: What interesting, boring, efficient, slow, etc. ways are there? Ali Well one of the more convoluted methods that I can think of would be to define a square as a set of four vectors, ro

Re: Function to print a diamond shape

2014-03-20 Thread Timon Gehr
On 03/20/2014 10:25 PM, Ali Çehreli wrote: This is a somewhat common little exercise: Write a function that takes the size of a diamond and produces a diamond of that size. When printed, here is the output for size 11: * *** * *** * *** *

Re: Function to print a diamond shape

2014-03-20 Thread Ali Çehreli
On 03/20/2014 03:03 PM, Brad Anderson wrote: > I'm not entirely happy with it but: I am not happy with my attempt either. :) >void main() >{ > import std.algorithm, std.range, std.stdio, std.conv; > > enum length = 5; > auto rng = > chain(iota(length), iota(length

Re: GC allocation issue

2014-03-20 Thread Rene Zwanenburg
On Thursday, 20 March 2014 at 20:48:18 UTC, Etienne wrote: I'm running some tests on a cache store where I planned to use only Malloc for the values being stored, I'm hoping to eliminate the GC in 95% of the program, but to keep it only for actively used items.. My problem is: when the progra

Re: Function to print a diamond shape

2014-03-20 Thread monarch_dodra
On Thursday, 20 March 2014 at 21:25:03 UTC, Ali Çehreli wrote: What interesting, boring, efficient, slow, etc. ways are there? Ali I'd be interested in seeing a solution using "iota", and the currently proposed "each" or "tee". A quick protype to draw a triangle would be: iota(0, n).each!(

Re: Function to print a diamond shape

2014-03-20 Thread Brad Anderson
On Thursday, 20 March 2014 at 21:25:03 UTC, Ali Çehreli wrote: This is a somewhat common little exercise: Write a function that takes the size of a diamond and produces a diamond of that size. When printed, here is the output for size 11: * *** * *** * *

Re: Function to print a diamond shape

2014-03-20 Thread Chris Williams
On Thursday, 20 March 2014 at 21:25:03 UTC, Ali Çehreli wrote: What interesting, boring, efficient, slow, etc. ways are there? Ali Well one of the more convoluted methods that I can think of would be to define a square as a set of four vectors, rotate 45 degrees, and then create a rasterizer

Re: Function to print a diamond shape

2014-03-20 Thread Ali Çehreli
On 03/20/2014 02:30 PM, Justin Whear wrote: > What's the appropriate output for an even number? Great question! :) Size must be odd. I have this in my function: enforce(size % 2, format("Size cannot be an even number. (%s)", size)); Ali

Re: Function to print a diamond shape

2014-03-20 Thread Justin Whear
On Thu, 20 Mar 2014 14:25:02 -0700, Ali Çehreli wrote: > This is a somewhat common little exercise: Write a function that takes > the size of a diamond and produces a diamond of that size. > > When printed, here is the output for size 11: > > * > *** > * >*** > *

Function to print a diamond shape

2014-03-20 Thread Ali Çehreli
This is a somewhat common little exercise: Write a function that takes the size of a diamond and produces a diamond of that size. When printed, here is the output for size 11: * *** * *** * *** * *** * *** * What interesting

GC allocation issue

2014-03-20 Thread Etienne
I'm running some tests on a cache store where I planned to use only Malloc for the values being stored, I'm hoping to eliminate the GC in 95% of the program, but to keep it only for actively used items.. My problem is: when the program reaches 40MB it suddenly goes down to 0.9MB and blocks.

Re: Template with template?

2014-03-20 Thread John Colvin
On Thursday, 20 March 2014 at 19:38:25 UTC, Chris wrote: On Thursday, 20 March 2014 at 18:54:30 UTC, John Colvin wrote: On Thursday, 20 March 2014 at 18:39:32 UTC, Chris wrote: On Thursday, 20 March 2014 at 17:49:52 UTC, John Colvin wrote: On Thursday, 20 March 2014 at 16:40:50 UTC, Chris wrot

Re: bool Associative Array Synchronized

2014-03-20 Thread Etienne
On 2014-03-20 2:47 PM, H. S. Teoh wrote: On Thu, Mar 20, 2014 at 06:39:10PM +, Chris Williams wrote: On Thursday, 20 March 2014 at 18:06:18 UTC, Etienne wrote: Right, I was assuming it was always ordered, but modern processor pipelines are different I guess. Even without rearranging the o

Re: Template with template?

2014-03-20 Thread Meta
On Thursday, 20 March 2014 at 19:38:25 UTC, Chris wrote: I thought the array T[] traits could hold any _type_ the template Trait is instantiated into. That's where I got it wrong. This is the best explanation for this restriction that I can think of: struct Person(T) { static if (is(T =

Re: Template with template?

2014-03-20 Thread Philippe Sigaud
> > >> > I thought the array T[] traits could hold any _type_ the template Trait is > instantiated into. Different instantiations of a template could become totally unrelated types (heck, even things that are *not* types: function definitions, values, code blocks, ...). So there is now way for an

Re: Template with template?

2014-03-20 Thread Chris
On Thursday, 20 March 2014 at 18:54:30 UTC, John Colvin wrote: On Thursday, 20 March 2014 at 18:39:32 UTC, Chris wrote: On Thursday, 20 March 2014 at 17:49:52 UTC, John Colvin wrote: On Thursday, 20 March 2014 at 16:40:50 UTC, Chris wrote: On Thursday, 20 March 2014 at 16:32:34 UTC, Vladimir P

Re: Template with template?

2014-03-20 Thread John Colvin
On Thursday, 20 March 2014 at 18:39:32 UTC, Chris wrote: On Thursday, 20 March 2014 at 17:49:52 UTC, John Colvin wrote: On Thursday, 20 March 2014 at 16:40:50 UTC, Chris wrote: On Thursday, 20 March 2014 at 16:32:34 UTC, Vladimir Panteleev wrote: On Thursday, 20 March 2014 at 16:28:46 UTC, Chr

Re: bool Associative Array Synchronized

2014-03-20 Thread H. S. Teoh
On Thu, Mar 20, 2014 at 06:39:10PM +, Chris Williams wrote: > On Thursday, 20 March 2014 at 18:06:18 UTC, Etienne wrote: > >Right, I was assuming it was always ordered, but modern processor > >pipelines are different I guess. > > Even without rearranging the order of your code, your bit exists

Re: Template with template?

2014-03-20 Thread Chris
On Thursday, 20 March 2014 at 17:49:52 UTC, John Colvin wrote: On Thursday, 20 March 2014 at 16:40:50 UTC, Chris wrote: On Thursday, 20 March 2014 at 16:32:34 UTC, Vladimir Panteleev wrote: On Thursday, 20 March 2014 at 16:28:46 UTC, Chris wrote: How can I instantiate Person with Trait, i.e. a

Re: bool Associative Array Synchronized

2014-03-20 Thread Chris Williams
On Thursday, 20 March 2014 at 18:06:18 UTC, Etienne wrote: Right, I was assuming it was always ordered, but modern processor pipelines are different I guess. Even without rearranging the order of your code, your bit exists in RAM but all the logic takes place in a CPU register, meaning that a

Re: bool Associative Array Synchronized

2014-03-20 Thread Etienne
On 2014-03-20 1:58 PM, John Colvin wrote: Also, atomicity is not a strong enough guarantee for implementing a mutex, which is what I assume you are trying to do. You need ordering guarantees as well. Heh. Will do!

Re: bool Associative Array Synchronized

2014-03-20 Thread Etienne
On 2014-03-20 1:52 PM, Steven Schveighoffer wrote: On Thu, 20 Mar 2014 13:43:58 -0400, Etienne wrote: I'd like to "cowboy it" on an AA that looks like this: __gshared bool[string] m_mutex; I think it'll be much faster for my code because this AA could need to be checked and switched possibly

Re: Template with template?

2014-03-20 Thread Adam D. Ruppe
Or make trait a class, storing the interface and passing the trait to the new Person in the constructor.

Re: bool Associative Array Synchronized

2014-03-20 Thread John Colvin
On Thursday, 20 March 2014 at 17:43:58 UTC, Etienne wrote: I'd like to "cowboy it" on an AA that looks like this: __gshared bool[string] m_mutex; I think it'll be much faster for my code because this AA could need to be checked and switched possibly millions of times per second and I wouldn't

Re: bool Associative Array Synchronized

2014-03-20 Thread Steven Schveighoffer
On Thu, 20 Mar 2014 13:43:58 -0400, Etienne wrote: I'd like to "cowboy it" on an AA that looks like this: __gshared bool[string] m_mutex; I think it'll be much faster for my code because this AA could need to be checked and switched possibly millions of times per second and I wouldn't wan

Re: Template with template?

2014-03-20 Thread John Colvin
On Thursday, 20 March 2014 at 16:40:50 UTC, Chris wrote: On Thursday, 20 March 2014 at 16:32:34 UTC, Vladimir Panteleev wrote: On Thursday, 20 March 2014 at 16:28:46 UTC, Chris wrote: How can I instantiate Person with Trait, i.e. a template with a template? struct Trait(T0, T1) { T0 name; T1

bool Associative Array Synchronized

2014-03-20 Thread Etienne
I'd like to "cowboy it" on an AA that looks like this: __gshared bool[string] m_mutex; I think it'll be much faster for my code because this AA could need to be checked and switched possibly millions of times per second and I wouldn't want to slow it down with a mutex protecting it. I'm thin

Re: Template with template?

2014-03-20 Thread Chris
On Thursday, 20 March 2014 at 16:32:34 UTC, Vladimir Panteleev wrote: On Thursday, 20 March 2014 at 16:28:46 UTC, Chris wrote: How can I instantiate Person with Trait, i.e. a template with a template? struct Trait(T0, T1) { T0 name; T1 value; T1[T0] map; this(T0 name, T1 value) { this.

Re: Template with template?

2014-03-20 Thread Vladimir Panteleev
On Thursday, 20 March 2014 at 16:28:46 UTC, Chris wrote: How can I instantiate Person with Trait, i.e. a template with a template? struct Trait(T0, T1) { T0 name; T1 value; T1[T0] map; this(T0 name, T1 value) { this.name = name; this.value = value; map[name] = value; } }

Re: Template with template?

2014-03-20 Thread John Colvin
On Thursday, 20 March 2014 at 16:28:46 UTC, Chris wrote: How can I instantiate Person with Trait, i.e. a template with a template? struct Trait(T0, T1) { T0 name; T1 value; T1[T0] map; this(T0 name, T1 value) { this.name = name; this.value = value; map[name] = value; } }

Template with template?

2014-03-20 Thread Chris
How can I instantiate Person with Trait, i.e. a template with a template? struct Trait(T0, T1) { T0 name; T1 value; T1[T0] map; this(T0 name, T1 value) { this.name = name; this.value = value; map[name] = value; } } class Person(T) { T traits[]; void addTrait(T trait)

Re: dmd v2.065 compatibility

2014-03-20 Thread Sönke Ludwig
Am 14.03.2014 11:43, schrieb Chris: [1] Yesterday I tried to build a project with dub. dub had downloaded and installed dmd v2.065. The project and accompanying library had been built with dmd v2.064. dub said that the project was up to date and didn't need compiling. However, I got a long long e