Is D's GC.calloc and C's memset played the same role?

FrankLike via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Dec 23 16:24:44 PST 2014


On Tuesday, 23 December 2014 at 20:22:12 UTC, ketmar via 
Digitalmars-d-learn wrote:
> On Tue, 23 Dec 2014 15:37:12 +0000
> FrankLike via Digitalmars-d-learn 
> <digitalmars-d-learn at puremagic.com>
> wrote:
>
>> you will find the different:
>>   D: PROCESSENTRY32* pe32 = 
>> cast(PROCESSENTRY32*)GC.calloc(PROCESSENTRY32.sizeof);
>> 
>> C++:PROCESSENTRY32 pe32;
>> 
>> GC.calloc means: memset ?!
>
> do you see that shining star there? here it is, right in the 
> end:
> `PROCESSENTRY32*`. and do you see that same star in C sample?

Yes,if you not do like it,it  will  not  work.

> jokes aside, it's dead simple: C code using stack-allocated

Not joke.it works fine,you can  run  it.
Not  C,it's  C++.
> struct
> (`PROCESSENTRY32` without an inderection) and D code using
> heap-allocated struct (`PROCESSENTRY32*` with indirection).
>
> hence C code using `memset()`, yet D code using `GC.calloc()`.



More information about the Digitalmars-d-learn mailing list