No subject
Mon Dec 5 13:53:56 CET 2011
"The realloc() function returns a pointer to the newly allocated
memory, which is suitably aligned for any kind of variable and may be
different from ptr, or NULL if the request fails. "
So all you need to do is allocate a new block and memcpy() the old
data. Note also:
"If realloc() fails the original block is left untouched; it is not
freed or moved."
"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 malloc(size)"
"if size is equal to zero, and ptr is not NULL, then the call is
equivalent to free(ptr)"
"If the area pointed to was moved, a free(ptr) is done."
The last two are NOPs for early heap as we have no way to track free'd blocks
Keep in mind that 'real' realloc() has access to information providing
the size of the source block of allocated memory, so it can do a
memcpy using (at least a good guess of) the size of the source block.
In the early heap case, we do not have that data, so we would need to
memcpy the entire size of the destination block - this will likely
bring in garbage (no problem as we there is nothing in the spec to
forbid that) and _might_ have some interesting boundary conditions
(what happens if we memcpy past the end of an early heap block into
ga-ga land?)
Regards,
Graeme
More information about the U-Boot
mailing list