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

ketmar via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Dec 23 12:22:03 PST 2014


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?

jokes aside, it's dead simple: C code using stack-allocated 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()`.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20141223/babbbf56/attachment.sig>


More information about the Digitalmars-d-learn mailing list