Force struct allocation on the heap?

Lars Kyllingstad public at kyllingen.NOSPAMnet
Sun Oct 19 05:17:38 PDT 2008


Benji Smith wrote:
> Looking at the official docs, I can't find the D1 syntax for forcing a 
> struct to be allocated on the heap (so that it can safely be returned 
> from a function). I'm pretty sure it's possible (without wrapping the 
> struct in a class or an array), but I can't for the life of me remember 
> how it's done.
> 
> Thanks for your help!
> 
> --benji

You allocate a struct on the heap using the "new" keyword.

   struct Foo { ... }
   Foo* foo = new Foo;

Note that "new" returns a pointer for non-object types.

-Lars


More information about the Digitalmars-d-learn mailing list