Re: @safe @nogc memory allocation

2014-05-28 Thread safety0ff via Digitalmars-d-learn
On Wednesday, 28 May 2014 at 23:57:40 UTC, Dicebot wrote: I believe within current language semantics even considering `new` pure is broken, there was a very recent thread discussing it in digitalmars.D group. If you can be sure that your code won't break basic sanity requirements (never co

Re: @safe @nogc memory allocation

2014-05-28 Thread Dicebot via Digitalmars-d-learn
On Wednesday, 28 May 2014 at 21:31:41 UTC, Nordlöw wrote: It is also because `malloc` can return null when out of memory and `new` will throw an Error. Wrapper around `malloc` that throws `OutOfMemoryError` on null can be considered of same purity class as `new`. Does this mean that I should

Re: Programming a Game in D? :D

2014-05-28 Thread David via Digitalmars-d-learn
On Wednesday, 28 May 2014 at 21:38:07 UTC, Francesco Cattoglio wrote: I'll be honest, perhaps I risk being misunderstood, but the questions you are asking denote a lack of even basic knowledge about the subject, so I really think you should do some good amount of research before even trying t

Re: Programming a Game in D? :D

2014-05-28 Thread Francesco Cattoglio via Digitalmars-d-learn
On Wednesday, 28 May 2014 at 17:46:23 UTC, David wrote: Ok, now I just wonder wich Engine. (I know everybody hates the discussion about the "best" engine.) CryEngine, UDK, Unity or a less known Engine? I'll be honest, perhaps I risk being misunderstood, but the questions you are asking denote

Re: @safe @nogc memory allocation

2014-05-28 Thread Nordlöw
It is also because `malloc` can return null when out of memory and `new` will throw an Error. Wrapper around `malloc` that throws `OutOfMemoryError` on null can be considered of same purity class as `new`. Does this mean that I should write and use such a wrapper for malloc? /Per

Re: @safe @nogc memory allocation

2014-05-28 Thread Dicebot via Digitalmars-d-learn
On Wednesday, 28 May 2014 at 21:09:26 UTC, bearophile wrote: Dicebot: It is also because `malloc` can return null when out of memory and `new` will throw an Error. Wrapper around `malloc` that throws `OutOfMemoryError` on null can be considered of same purity class as `new`. One wrapper sho

Re: @safe @nogc memory allocation

2014-05-28 Thread bearophile via Digitalmars-d-learn
Dicebot: It is also because `malloc` can return null when out of memory and `new` will throw an Error. Wrapper around `malloc` that throws `OutOfMemoryError` on null can be considered of same purity class as `new`. One wrapper should have a template argument to specify the type of the items

Re: @safe @nogc memory allocation

2014-05-28 Thread Dicebot via Digitalmars-d-learn
On Wednesday, 28 May 2014 at 20:51:08 UTC, Nordlöw wrote: malloc? There's no wrapper around it though, like there is for uninitializedArray. Is the fact that malloc() can't be pure when new is a limitiation in the type system? Do we need a yet another code tag for this? /Per It is also be

Re: @safe @nogc memory allocation

2014-05-28 Thread Nordlöw
malloc? There's no wrapper around it though, like there is for uninitializedArray. Is the fact that malloc() can't be pure when new is a limitiation in the type system? Do we need a yet another code tag for this? /Per

Re: Looping over all enum values

2014-05-28 Thread Mark Isaacson via Digitalmars-d-learn
On Wednesday, 28 May 2014 at 20:20:37 UTC, Adam D. Ruppe wrote: On Wednesday, 28 May 2014 at 20:19:45 UTC, Mark Isaacson wrote: Is there a mechanism that allows you to loop over all of an enum's values? I've wanted to do so a couple times now for CTFE/mixin templates. __traits(allMembers) on t

Re: Looping over all enum values

2014-05-28 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 28 May 2014 at 20:19:45 UTC, Mark Isaacson wrote: Is there a mechanism that allows you to loop over all of an enum's values? I've wanted to do so a couple times now for CTFE/mixin templates. __traits(allMembers) on the enum can do it or this can help too http://dlang.org/phobos/s

Looping over all enum values

2014-05-28 Thread Mark Isaacson via Digitalmars-d-learn
Is there a mechanism that allows you to loop over all of an enum's values? I've wanted to do so a couple times now for CTFE/mixin templates. I was able to loop over the underlying type when my enum was integer-based, but I can't do that if the values are strings (also that solution is quite hacky

Re: @safe @nogc memory allocation

2014-05-28 Thread monarch_dodra via Digitalmars-d-learn
On Wednesday, 28 May 2014 at 20:00:17 UTC, safety0ff wrote: I think malloc isn't @safe and alloca doesn't work if your function can throw. Yeah, uninitializedArray is also *only* trusted if the type in question has no indirections. I've heard of several bugs with alloca, but I don't know the

Re: @safe @nogc memory allocation

2014-05-28 Thread safety0ff via Digitalmars-d-learn
I think malloc isn't @safe and alloca doesn't work if your function can throw.

Re: @safe @nogc memory allocation

2014-05-28 Thread monarch_dodra via Digitalmars-d-learn
On Wednesday, 28 May 2014 at 19:43:53 UTC, Nordlöw wrote: I would like my radix sort function radixSortImpl() at https://github.com/nordlow/justd/blob/master/intsort.d to not use the GC. However, when I tag with @nogc I get the error: intsort.d(195,47): Error: @nogc function 'isort.radixSor

@safe @nogc memory allocation

2014-05-28 Thread Nordlöw
I would like my radix sort function radixSortImpl() at https://github.com/nordlow/justd/blob/master/intsort.d to not use the GC. However, when I tag with @nogc I get the error: intsort.d(195,47): Error: @nogc function 'isort.radixSortImpl!(byte[], "a", false).radixSortImpl' cannot call non-@n

Re: Programming a Game in D? :D

2014-05-28 Thread Ryan Voots via Digitalmars-d-learn
On Wednesday, 28 May 2014 at 17:46:23 UTC, David wrote: Ok, now I just wonder wich Engine. (I know everybody hates the discussion about the "best" engine.) CryEngine, UDK, Unity or a less known Engine? The best engine is the one you can get work done with. Unity seems to have a pretty good c

Re: std.algorithm range violation

2014-05-28 Thread monarch_dodra via Digitalmars-d-learn
On Wednesday, 28 May 2014 at 17:39:15 UTC, monarch_dodra wrote: On Wednesday, 28 May 2014 at 11:40:05 UTC, Wanderer wrote: Sorry about typo, I meant providor_symbol_map.sort!((x,y)=>{x.value.length>y.value.length}) above. providor_symbol_map is an Associative Array, so you can't sort that.

Re: Cost of .dup vs. instantiation

2014-05-28 Thread TheFlyingFiddle via Digitalmars-d-learn
On Wednesday, 28 May 2014 at 14:36:25 UTC, Chris wrote: I use Appender to fill an array. The Appender is a class variable and is not instantiated with each function call to save instantiation. However, the return value or the function must be dup'ed, like so: Appender!(MyType[]) append; publi

Re: Programming a Game in D? :D

2014-05-28 Thread David via Digitalmars-d-learn
On Tuesday, 27 May 2014 at 10:13:13 UTC, Szymon Gatner wrote: On Tuesday, 27 May 2014 at 10:03:36 UTC, David wrote: On Saturday, 24 May 2014 at 08:54:53 UTC, ponce wrote: Hi David, Learning programming, learning D and learning 3D are 3 significant endeavours. You might want to begin with htt

Re: std.algorithm range violation

2014-05-28 Thread monarch_dodra via Digitalmars-d-learn
On Wednesday, 28 May 2014 at 11:40:05 UTC, Wanderer wrote: Sorry about typo, I meant providor_symbol_map.sort!((x,y)=>{x.value.length>y.value.length}) above. providor_symbol_map is an Associative Array, so you can't sort that. *Usually*, you want to do what the OP did, which is to get the k

Re: Cost of .dup vs. instantiation

2014-05-28 Thread monarch_dodra via Digitalmars-d-learn
On Wednesday, 28 May 2014 at 14:36:25 UTC, Chris wrote: I use Appender to fill an array. The Appender is a class variable and is not instantiated with each function call to save instantiation. However, the return value or the function must be dup'ed, like so: Appender!(MyType[]) append; publi

Cost of .dup vs. instantiation

2014-05-28 Thread Chris via Digitalmars-d-learn
I use Appender to fill an array. The Appender is a class variable and is not instantiated with each function call to save instantiation. However, the return value or the function must be dup'ed, like so: Appender!(MyType[]) append; public auto doSomething() { scope (exit) { // clear append }

Re: std.algorithm range violation

2014-05-28 Thread maarten van damme via Digitalmars-d-learn
wow. senpai, teach me what I did wrong... 2014-05-28 13:21 GMT+02:00 bearophile via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com>: > maarten van damme: > > > writeln(providor_symbol_map.keys.sort!((x,y)=>providor_ >> symbol_map[x].length>=providor_symbol_map[y].length)); >> [/code] >

Re: std.algorithm range violation

2014-05-28 Thread Wanderer via Digitalmars-d-learn
Aha, so you want to maintain "spam word" -> "set of senders" relationship, so it's actually "map of sets" and your declaration is correct. You only need to sort map's entries (key and value pairs together). If D supports that, it should be something like providor_symbol_map.sort!((x,y)=>{x.va

Re: std.algorithm range violation

2014-05-28 Thread bearophile via Digitalmars-d-learn
Wanderer: providor_symbol_map.sort!((x,y)=>{x.value.length=>y.value.length}), This lambda doesn't return a boolean. Also, add spaces around operators and after commas. Bye, bearophile

Re: std.algorithm range violation

2014-05-28 Thread Wanderer via Digitalmars-d-learn
Sorry about typo, I meant providor_symbol_map.sort!((x,y)=>{x.value.length>y.value.length}) above.

Re: std.algorithm range violation

2014-05-28 Thread bearophile via Digitalmars-d-learn
maarten van damme: writeln(providor_symbol_map.keys.sort!((x,y)=>providor_symbol_map[x].length>=providor_symbol_map[y].length)); [/code] Try: ((x, y) => providor_symbol_map[x].length > providor_symbol_map[y].length) Bye, bearophile

Re: std.algorithm range violation

2014-05-28 Thread maarten van damme via Digitalmars-d-learn
I'm trying to analyze the usage of certain words in a large number of spam emails, and I want for every interesting word a list of 'providors', that mentioned that word. with associative arrays I hoped to get it by using array["interestingworde]. And I have to refer outside from sort(x,y) as assoc

Re: std.algorithm range violation

2014-05-28 Thread Wanderer via Digitalmars-d-learn
On Wednesday, 28 May 2014 at 10:10:41 UTC, maarten van damme via Digitalmars-d-learn wrote: an anyone explain me what I'm doing wrong here : [code] dstring[][dstring] providor_symbol_map; ... writeln(providor_symbol_map.keys.sort!((x,y)=>providor_symbol_map[x].length>=providor_symbol_map[y].len

std.algorithm range violation

2014-05-28 Thread maarten van damme via Digitalmars-d-learn
an anyone explain me what I'm doing wrong here : [code] dstring[][dstring] providor_symbol_map; ... writeln(providor_symbol_map.keys.sort!((x,y)=>providor_symbol_map[x].length>=providor_symbol_map[y].length)); [/code] output: core.exception.RangeError@std.algorithm(9429): Range violation