run-time stack-based allocation

Gor Gyolchanyan gor.f.gyolchanyan at gmail.com
Wed May 9 13:52:22 PDT 2012


I thought function default parameters need to be statically known...
isn't it the case?

On Thu, May 10, 2012 at 12:17 AM, Tove <tove at fransson.se> wrote:
> On Tuesday, 8 May 2012 at 07:03:35 UTC, Gor Gyolchanyan wrote:
>>
>> Cool! Thanks! I'l definitely check it out! I hope it's DDOCed :-D
>>
>
> I just invented an absolutely wicked way of using alloca() in the parent
> context... unfortunately frame_size is static but with some work, it's still
> an usable method since it's mutable!
>
> struct Wicked
> {
>  static int frame_size = 0;
>
>  auto Create(void* buf=alloca(frame_size))
>  {
>    for(byte i=0;i<frame_size;++i)
>      (cast(byte*)buf)[i]=i;
>
>    struct Frame
>    {
>      size_t size;
>    }
>
>    Frame* xxx = cast(Frame*)buf;
>    xxx.size=frame_size;
>
>    return xxx;
>  }
>
>  @disable this();
>
>  this(size_t size)
>  {
>    frame_size = size;
>  }
> }



-- 
Bye,
Gor Gyolchanyan.


More information about the Digitalmars-d mailing list