Is there a GC'd malloc alternative?
Bill Baxter
dnewsgroup at billbaxter.com
Mon Feb 19 13:11:49 PST 2007
0ffh wrote:
> Johan Granberg wrote:
>> 0ffh wrote:
>>
>>> I just wonder if there is no library function that
>>> works like 'malloc' but in garbage collected memory?
>>> [...]
>>> p.s.
>>> I am probably not looking for the 'new' operator,
>>> [...]
>>
>> are you sure about the new thing. I think that this code would work.
>>
>> new void[SIZE];
>>
>> where SIZE is an integer representing how large chunk of memory you
>> want to
>> reserve.
>>
>> ps. this newsgroup is all but abandoned use the digitalmars.D instead.
>
> Well, thanks, "void d[]=new void[100];" seems to compile fine.
> Now I just wonder how many bytes 100 voids weight? :-)
> Do you think it would be evil to steal the pointer out of the
> array, because I'd really like to get a pointer as a result?
No problem.
void d[]=new void[100];
some_library_fn_that_takes_a_void_ptr(d.ptr);
Works fine.
--bb
More information about the Digitalmars-d
mailing list