run-time stack-based allocation

Gor Gyolchanyan gor.f.gyolchanyan at gmail.com
Mon May 7 09:56:00 PDT 2012


That won't do. This is way too ugly, considering, that it needs to be
heavily used in user code. I'm thinking an inline ASM solution, but
can't figure out when to deallocate.

On Mon, May 7, 2012 at 8:52 PM, Arne <arne at linux.nu> wrote:
> On Monday, 7 May 2012 at 16:03:15 UTC, Mehrdad wrote:
>>
>> On Monday, 7 May 2012 at 13:36:02 UTC, Gor Gyolchanyan wrote:
>>>
>>> Basically I want what alloca does, but instead of considering the
>>> constructor's scope, I want it to hand to the constructor call's enclosing
>>> scope.
>>
>>
>> I think you'd need to modify the compiler for this, since alloca is
>> 'magical'.
>
>
> wouldn't mixin's be a solution, one can inject an alloca to the current
> scope, and then call the constructor...
>
> import std.stdio;
> import std.c.stdlib;
> import std.random;
>
> mixin template Init(alias var, alias size)
> {
>  void* buf = alloca(size);
>
>  bool foo_init()
>  {
>    var = (cast(typeof(var))buf);
>
>    var[0]=0;
>    var[1]=1;
>    var[2]=2;
>
>    return true;
>  }
>
>  auto foo_dummy_statement = foo_init();
> }
>
> void main()
> {
>  int my_size = uniform(12, 24);
>  int* my_var = void; mixin Init!(my_var, my_size);
>
>  writeln(my_var[0..3]);
> }



-- 
Bye,
Gor Gyolchanyan.


More information about the Digitalmars-d mailing list