Share this page

# calloc

Memory Allocation Functions

Allocates an array and initializes all elements to zero.

    void *calloc( size_t num elems, size_t elem_size);

num elems | The number of elements in the array.
elem_size | The size of each element.

## Return Values

Returns a void * type pointer to the allocated space. If the system could not allocate the requested block of memory or if any of the parameters was 0, returns a NULL pointer.

For calloc details, refer to your C language documentation.

## Example

The following example uses calloc to allocate a buffer of length 1024.

Copy code

    #include <malloc.h>
        char * buf;
        if ((buf = (char *)calloc(1024, sizeof(char))) == NULL) {
            lr_output_message ("Insufficient memory available");
            return -1;
        }
        lr_output_message ("Memory allocated. Buffer address = %.8x", buf);
        // Do something with the buffer here ...
        // Now free the buffer
        free(buf);

    Example: Output:
    Action.c(11): Memory allocated. Buffer address = 007b9d88

Tips to improve your search results... VuGen Function Reference Version 26.1-26.3 Function Reference 26.1-26.3 All View Local Help Center View Online Help Center Version: