On 17.07.2014 23:52, Ali Çehreli wrote:
When called with an existing buffer, GC.realloc conditionally clears the
newly extended part of the memory. An excerpt from druntime/src/gc/gc.d:
void *realloc(void *p, size_t size, uint bits = 0, size_t *alloc_size =
null, const TypeInfo ti = null) nothrow
{
// ...
if (p !is oldp && !(bits & BlkAttr.NO_SCAN))
{
memset(p + size, 0, *alloc_size - size);
}
return p;
}
>
> (Disclaimer: Although undocumented, I assume that clearing the memory
> is an intended feature of GC.realloc.)
>
It clears the memory beyond the requested size. This is usually not
accessible to the user (at least if he didn't provide the alloc_size
parameter).
I believe this is meant to avoid false pointers in the memory range that
the user will not fill with other data. It is not meant to mimick calloc.