Re: new T[size] vs .reserve - alloca

2013-02-06 Thread Nick Treleaven
On 05/02/2013 16:39, bearophile wrote: Nick Treleaven: ^ I know you're aware of this, but maybe others might not know the default-argument alloca wrapping trick: For some usages it's an improvement over raw usage of alloca. I did see this in past, but sometimes I forget. Sorry if I sounded

Re: new T[size] vs .reserve - alloca

2013-02-06 Thread Nick Treleaven
On 05/02/2013 22:15, monarch_dodra wrote: On Tuesday, 5 February 2013 at 21:14:32 UTC, Nick Treleaven wrote: On 05/02/2013 21:13, Nick Treleaven wrote: I've just tried it with dmd 2.059 (haven't upgraded yet) sorry, 2.060 Right, it's "alias" being finicky, because "args.length" isn't an act

Re: new T[size] vs .reserve - alloca

2013-02-05 Thread monarch_dodra
On Tuesday, 5 February 2013 at 21:14:32 UTC, Nick Treleaven wrote: On 05/02/2013 21:13, Nick Treleaven wrote: I've just tried it with dmd 2.059 (haven't upgraded yet) sorry, 2.060 Right, it's "alias" being finicky, because "args.length" isn't an actual variable (it's a property). The proble

Re: new T[size] vs .reserve - alloca

2013-02-05 Thread Nick Treleaven
On 05/02/2013 21:13, Nick Treleaven wrote: I've just tried it with dmd 2.059 (haven't upgraded yet) sorry, 2.060

Re: new T[size] vs .reserve - alloca

2013-02-05 Thread Nick Treleaven
On 05/02/2013 21:02, monarch_dodra wrote: On Tuesday, 5 February 2013 at 20:47:46 UTC, Nick Treleaven wrote: On 05/02/2013 16:47, monarch_dodra wrote: T[] stack(T, alias N)(void* m = alloca(T.sizeof * N)) { return (cast(T*)m)[0 .. N]; } This works if you know N at compile-time. But there

Re: new T[size] vs .reserve - alloca

2013-02-05 Thread monarch_dodra
On Tuesday, 5 February 2013 at 20:47:46 UTC, Nick Treleaven wrote: On 05/02/2013 16:47, monarch_dodra wrote: On Tuesday, 5 February 2013 at 16:37:41 UTC, Nick Treleaven wrote: I've just realized this doesn't work for variable-length allocation: T[] stack(T)(size_t N, void* m = alloca(T.sizeof

Re: new T[size] vs .reserve - alloca

2013-02-05 Thread Nick Treleaven
On 05/02/2013 16:47, monarch_dodra wrote: On Tuesday, 5 February 2013 at 16:37:41 UTC, Nick Treleaven wrote: I've just realized this doesn't work for variable-length allocation: T[] stack(T)(size_t N, void* m = alloca(T.sizeof * N)) Error: undefined identifier N, did you mean alias T? N is no

Re: new T[size] vs .reserve - alloca

2013-02-05 Thread Namespace
Why not: [code] T[] stack(T, const size_t N)(void* m = alloca(T.sizeof * N)) { return (cast(T*)m)[0 .. N]; } [/code] ?

Re: new T[size] vs .reserve - alloca

2013-02-05 Thread monarch_dodra
On Tuesday, 5 February 2013 at 16:37:41 UTC, Nick Treleaven wrote: On 05/02/2013 16:17, Nick Treleaven wrote: On 03/02/2013 13:22, bearophile wrote: Era Scarecrow: On Sunday, 3 February 2013 at 09:11:59 UTC, Namespace wrote: Sure, but alloca has the same ugly interface as malloc. :/ You me

Re: new T[size] vs .reserve - alloca

2013-02-05 Thread bearophile
Nick Treleaven: ^ I know you're aware of this, but maybe others might not know the default-argument alloca wrapping trick: For some usages it's an improvement over raw usage of alloca. I did see this in past, but sometimes I forget. Bye, bearophile

Re: new T[size] vs .reserve - alloca

2013-02-05 Thread Nick Treleaven
On 05/02/2013 16:17, Nick Treleaven wrote: On 03/02/2013 13:22, bearophile wrote: Era Scarecrow: On Sunday, 3 February 2013 at 09:11:59 UTC, Namespace wrote: Sure, but alloca has the same ugly interface as malloc. :/ You mean that you have to specify how many raw bytes you want, then cast

Re: new T[size] vs .reserve - alloca

2013-02-05 Thread Nick Treleaven
On 03/02/2013 13:22, bearophile wrote: Era Scarecrow: On Sunday, 3 February 2013 at 09:11:59 UTC, Namespace wrote: Sure, but alloca has the same ugly interface as malloc. :/ You mean that you have to specify how many raw bytes you want, then cast it to what you need? I never thought alloca