d malloc
via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Aug 9 02:08:14 PDT 2014
On Friday, 8 August 2014 at 18:51:49 UTC, ketmar wrote:
>> Why are void pointers better than ulong, if I may ask
> there is at least one reason: GC. yes, it is conservative, but
> there's no reason to scan ulong[] for any pointers, so you may
> lost your objects if there is no other references to 'em.
And `ulong` is always 64 bits large, while pointer size depends
on the system architecture (32 bits vs 64 bits). If you really,
really must use an integral type instead of a pointer, use
`size_t`, which is defined to have the same size as a pointer.
But as ketmar said, the GC may not see recognize it then. `void*`
also has the advantage that you don't need to case if you assign
to it, because pointers convert to `void*` implicitly. In your
case, however, you likely are better off if you use `S*`, then
you don't need to do any conversions at all.
More information about the Digitalmars-d-learn
mailing list