NAME

zkRealloc - memory reallocator

SYNOPSIS

#include "zkStdlib.h"

void* zkRealloc(void* ptr, size_t size);

DESCRIPTION

The zkRealloc() function changes the size of the memory object pointed to by ptr to the size specified by size. The contents of the object will remain unchanged up to the lesser of the new and old sizes. If the new size of the memory object would require movement of the object, the space for the previous instantiation of the object is freed. If the new size is larger, the contents of the newly allocated portion of the object are unspecified. If size is 0 and ptr is not NULL, the object pointed to is freed. If the space cannot be allocated, the object remains unchanged.

If ptr is NULL, zkRealloc() behaves like zkMalloc() for the specified size.

If ptr does not match a pointer returned earlier by zkCalloc(), zkMalloc() or zkRealloc() or if the space has previously been deallocated by a call to zkFree() or zkRealloc(), the behaviour is undefined.

The order and contiguity of storage allocated by successive calls to zkRealloc() is unspecified. The pointer returned if the allocation succeeds is suitably aligned so that it may be assigned to a pointer to any type of object and then used to access such an object in the space allocated (until the space is explicitly freed or reallocated). Each such allocation will yield a pointer to an object disjoint from any other object. The pointer returned points to the start (lowest byte address) of the allocated space. If the space cannot be allocated, NULL is returned.

RETURN VALUE

Upon successful completion with a size not equal to 0, zkRealloc() returns a pointer to the (possibly moved) allocated space. If size is 0, either NULL or a unique pointer that can be successfully passed to zkFree() is returned. If there is not enough available memory, zkRealloc() returns NULL  and sets errno to [ENOMEM].

ERRORS

The zkRealloc() function will fail if:

[ENOMEM]
Insufficient memory is available.