Code:
void *pvPortRealloc(void *mem, size_t newsize)
{
void *p;
p = pvPortMalloc(newsize);
if (p) {
/* zero the memory */
if (mem != NULL) {
memcpy(p, mem, newsize);
vPortFree(mem);
}
}
return p;
}
而realloc的介绍是,当newsize为0时相当于free:
The realloc() function changes the size of the memory block pointed to by ptr to size bytes. The contents will be unchanged in the range from the start of the region up to the
minimum of the old and new sizes. If the new size is larger than the old size, the added memory will not be initialized. If ptr is NULL, then the call is equivalent to mal‐
loc(size), for all values of size; if size is equal to zero, and ptr is not NULL, then the call is equivalent to free(ptr). Unless ptr is NULL, it must have been returned by an
earlier call to malloc(), calloc() or realloc(). If the area pointed to was moved, a free(ptr) is done.Statistics: Posted by tobewinner — Tue Jan 19, 2016 2:43 pm
]]>