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 16:36:45 PST 2014


On Wed, 24 Dec 2014 00:24:44 +0000
FrankLike via Digitalmars-d-learn <digitalmars-d-learn at puremagic.com>
wrote:

> 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()`.

you did quoted the relevant part. let me repeat it:

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()`.

i.e. D code using *pointer* *to* *struct*, so you must allocate it
manually.
-------------- 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/20141224/d04aa2f3/attachment.sig>


More information about the Digitalmars-d-learn mailing list