Everything

realloc


Memory re-allocation

[Classification]

Standard library

[Syntax]

#include <stdlib.h>

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

[Return value]

When area allocation succeeds, a pointer to that area is returned. When the area could not be allocated, a null pointer is returned.

[Description]

This function changes the size of the area pointed to by ptr to the size indicated by size. The contents of the area are unchanged up to the smaller of the previous size and the specified size. If the area is expanded, the contents of the area greater than the previous size are not initialized. When ptr is a null pointer, the operation is the same as that of malloc (size). Otherwise, the area that was acquired by calloc, malloc, or realloc must be specified for ptr.

[Caution]

The memory area management functions automatically allocate memory area as necessary from the heap memory area.

Also, the size of the default is 0x1000 bytes, so when it's changed, the heap memory area must be allocated. The area allocation should be performed first by an application.

 

[Heap memory setup example]

#include    <stddef.h>
#define     SIZEOF_HEAP 0x1000
int     _REL_sysheap[SIZEOF_HEAP >> 2];
size_t  _REL_sizeof_sysheap = SIZEOF_HEAP;

Remark 1.

The variable "_REL_sysheap" points to the starting address of heap memory. This value must be a multiple of 4.

Remark 2.

The required heap memory size (bytes) should be set for the variable "_REL_sizeof_sysheap".