Thread overview | ||||||||
---|---|---|---|---|---|---|---|---|
|
February 19, 2007 Is there a GC'd malloc alternative? | ||||
---|---|---|---|---|
| ||||
Hi, I'm new to D but got into it pretty quickly... it's heaven for a lazy old C coder! }:->>> I just wonder if there is no library function that works like 'malloc' but in garbage collected memory? Happy hacking, 0ffh p.s. I am probably not looking for the 'new' operator, as 'new' seems to take only certain types as "argument", not the size of the requested memory chunk, as does 'malloc'. |
February 19, 2007 Re: Is there a GC'd malloc alternative? | ||||
---|---|---|---|---|
| ||||
Posted in reply to 0ffh | 0ffh wrote:
>
> Hi, I'm new to D but got into it pretty quickly...
> it's heaven for a lazy old C coder! }:->>>
>
> I just wonder if there is no library function that
> works like 'malloc' but in garbage collected memory?
>
> Happy hacking, 0ffh
>
> p.s.
> I am probably not looking for the 'new' operator,
> as 'new' seems to take only certain types as
> "argument", not the size of the requested memory
> chunk, as does 'malloc'.
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.
|
February 19, 2007 Re: Is there a GC'd malloc alternative? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Johan Granberg | 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?
Cheers, 0ffh
|
February 19, 2007 Re: Is there a GC'd malloc alternative? | ||||
---|---|---|---|---|
| ||||
Posted in reply to 0ffh | 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 |
February 19, 2007 Re: Is there a GC'd malloc alternative? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Bill Baxter | Okay, thanks, you have all been very helpful! I just couldn't find that information online, although now I probably could... :-) Am currently writing an interpreter and moved from C to D to take advantage of the built-in garbage collector, saves me loads of work and removes lots of opportunities for errors! Happy hacking, 0ffh |
February 20, 2007 Re: Is there a GC'd malloc alternative? | ||||
---|---|---|---|---|
| ||||
Posted in reply to 0ffh | 0ffh wrote:
>
>
> 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?
>
> Cheers, 0ffh
I'm not trying to be pedantic, but I get the feeling that "void[] d = new void[100];" would be more appropriate to D style than using the C style declaration of "void d[] = new void[100];". That is, put array/pointer decorations on the type rather than the variable name. Just thought you'd like to know.
|
Copyright © 1999-2021 by the D Language Foundation