library_realloc

Reallocates a block of memory.

Library:LibC
Service:Library

Syntax

  #include <library.h> 
   
  void *library_realloc   (
     void    *handle, 
     void    *old, 
     size_t   size);
  

Parameters

handle

(IN) Points to the handle for the NLM.

old

(IN) Points to a previously allocated memory block.

size

(IN) Specifies the size (in bytes) for the memory block. The requested size can be smaller or larger than the previously allocated memory block.

Return Values

If successful, returns a pointer to the start of the reallocated memory. Otherwise, returns NULL if there is insufficient memory available or if the size parameter is 0.

Remarks

The library_realloc function calls the library_malloc function to enlarge a block of memory. Asking for a smaller allocation may not result in the block actually being smaller.

Memory allocation is not limited to 64 KB. The size parameter is 32 bits.

When the value of the old parameter is NULL, a new block of memory of specified by the size parameter is allocated. Otherwise, the function reallocates space to the specified size by either:

  • Shrinking the allocated size of the old allocated memory block when size is sufficiently smaller than the size of the old block. This is not guaranteed to be the behavior.

  • Allocating a new block and copying the contents of the old block to the new block or at least as much as fits into the new size.

Because this function has the ability to allocate a new block, no other pointers should point to the memory of the old block. When a new block is allocated, these old pointers point to freed memory, with potentially disastrous results.

See Also