Unitialized allocation

Koroskin Denis 2korden at gmail.com
Fri Jun 27 07:27:17 PDT 2008


On Fri, 27 Jun 2008 18:10:43 +0400, Jarrett Billingsley  
<kb3ctd2 at yahoo.com> wrote:

> "Mael" <mael.primet at gmail.com> wrote in message
> news:g42p4r$2air$1 at digitalmars.com...
>> Hello,
>>
>> another newbie question :
>> I think it is possible to allocate unitialized data on the stack using
>> char[512] mydata = void ;
>> is there a way to allocate unitialized data on the heap ?
>
> With Phobos, std.gc.malloc is supposed to return uninitialized data.   
> Here's
> a little template function to make it easy:
>
> import std.gc;
>
> T[] allocUninit(T)(size_t len)
> {
>     return (cast(T*)std.gc.malloc(len * T.sizeof))[0 .. len];
> }
>
> ...
>
> auto arr = allocUninit!(char)(512);
>
> The equivalent in Tango is GC.malloc from tango.core.Memory.
>
>

This surely should be available at a language level.


More information about the Digitalmars-d-learn mailing list