Hi,
Rene W. Olsen wrote:
I don't know what realloc() does, the code looks like this
while (size > 0) { interface->altsetting = realloc(interface->altsetting, sizeof(struct usb_interface_descriptor) * (interface->num_altsetting + 1)); if (!interface->altsetting) { if (usb_debug >= 1) fprintf(stderr, "couldn't malloc interface->altsetting\n"); return -1; } .... }
So I was wonder is its extend or just allocating a new block of memory?
Both.
If the original pointer is NULL, it is equivalent to a malloc. If it's not, it will re-allocate the block, and the contents will remain the same (up to min(oldsize, newsize)). If size is zero, it's equivalent to a free.
Note that it does not necessarily operate in-place. It might also allocate at a new address, and copy the contents.
Here's a link to the manpage: http://www.rt.com/man/realloc.3.html
Regards,