The provided memory allocation functions are used by explicit libwget memory allocations. They differ from the standard ones in that they exit the program in an out-of-memory situation with EXIT_FAILURE. That means, you don't have to check the returned value against NULL.
You can provide a out-of-memory function that will be called before exit(), e.g. to print out a "No memory" message.
To work around this behavior, provide your own allocation routines, namely malloc(), calloc(), realloc().
◆ wget_set_oomfunc()
void wget_set_oomfunc |
( |
void(*)(void) |
oom_callback | ) |
|
- Parameters
-
[in] | oom_callback | Pointer to your custom out-of-memory function |
Set a custom out-of-memory function.
◆ wget_malloc()
void* wget_malloc |
( |
size_t |
size | ) |
|
- Parameters
-
[in] | size | Number of bytes to allocate |
- Returns
- A pointer to the allocated (uninitialized) memory
Like the standard malloc(), except that it doesn't return NULL values. If an out-of-memory condition occurs the oom callback function is called (if set). Thereafter the application is terminated by exit(EXIT_FAILURE);
◆ wget_calloc()
void* wget_calloc |
( |
size_t |
nmemb, |
|
|
size_t |
size |
|
) |
| |
- Parameters
-
[in] | nmemb | Number of elements (each of size size ) to allocate |
[in] | size | Size of element |
- Returns
- A pointer to the allocated (initialized) memory
Like the standard calloc(), except that it doesn't return NULL values. If an out-of-memory condition occurs the oom callback function is called (if set). Thereafter the application is terminated by exit(EXIT_FAILURE);
◆ wget_realloc()
void* wget_realloc |
( |
void * |
ptr, |
|
|
size_t |
size |
|
) |
| |
- Parameters
-
[in] | ptr | Pointer to old memory area |
[in] | size | Number of bytes to allocate for the new memory area |
- Returns
- A pointer to the new memory area
Like the standard realloc(), except that it doesn't return NULL values. If an out-of-memory condition occurs or size is 0, the oom callback function is called (if set). Thereafter the application is terminated by exit(EXIT_FAILURE);