Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages

  
 
  

home | help
xt_realloc(3)		    Library Functions Manual		   xt_realloc(3)

LIBRARY
     #include <xtend/mem.h>
     -lxtend

SYNOPSIS
     void    *xt_realloc(void *array, size_t nelem, size_t size)

ARGUMENTS
     array:  Address of the previously allocated array
     nelem:  Number of objects to allocate
     size:   Size of a single object

DESCRIPTION
     xt_realloc()  is a simple wrapper around realloc(3) that requires three ar-
     guments representing the original array, the new number of objects to allo-
     cate and the size of an element.  This prevents  the  very  common  mistake
     with realloc(3) of forgetting to multiply by the size of an element.

     Specifying  the  size  using  sizeof(*variable)  has the advantage of being
     type-independent.	I.e. if you change the type of the variable,  this  code
     need  not be updated.  Simply add one * to whatever the return value is as-
     signed to.

RETURN VALUES
     Address of the newly allocated array, or NULL if allocation failed

EXAMPLES
     size_t	 widget_list_size = 1024;
     widget_t	 *widgets;

     widgets = xt_malloc(widget_list_size, sizeof(*widgets));
     widget_list_size *= 2;
     widgets = xt_realloc(widgets, widget_list_size, sizeof(*widgets));

SEE ALSO
     realloc(3)

								   xt_realloc(3)

Want to link to this manual page? Use this URL:
<https://man.freebsd.org/cgi/man.cgi?query=xt_realloc&sektion=3&manpath=FreeBSD+Ports+15.1.quarterly>

home | help