|
Libical API Documentation 4.0 UNRELEASED Go to the stable 3.0 documentation
|
Common memory management routines. More...
Go to the source code of this file.
Macros | |
| #define | BUFFER_RING_SIZE 2500 |
| Determines the size of the ring buffer used for keeping track of temporary buffers. | |
| #define | MIN_BUFFER_SIZE 200 |
| Determines the minimal size of buffers in the ring that are created with icalmemory_tmp_buffer(). | |
Functions | |
| void | icalmemory_add_tmp_buffer (void *buf) |
| Adds an externally allocated buffer to the ring. | |
| void | icalmemory_append_char (char **buf, char **pos, size_t *buf_size, char ch) |
| Appends a character to a buffer. | |
| void | icalmemory_append_decoded_string (char **buf, char **pos, size_t *buf_size, const char *string) |
| void | icalmemory_append_encoded_string (char **buf, char **pos, size_t *buf_size, const char *string) |
| void | icalmemory_append_string (char **buf, char **pos, size_t *buf_size, const char *string) |
| Appends a string to a buffer. | |
| void | icalmemory_free_buffer (void *buf) |
| Releases a buffer. | |
| void | icalmemory_free_ring (void) |
| Frees all memory used in the ring. | |
| void | icalmemory_get_mem_alloc_funcs (icalmemory_malloc_f *f_malloc, icalmemory_realloc_f *f_realloc, icalmemory_free_f *f_free) |
| Returns the functions used for memory management. | |
| void * | icalmemory_new_buffer (size_t size) |
| Creates new buffer with the specified size. | |
| void * | icalmemory_resize_buffer (void *buf, size_t size) |
| Resizes a buffer created with icalmemory_new_buffer(). | |
| void | icalmemory_set_mem_alloc_funcs (icalmemory_malloc_f f_malloc, icalmemory_realloc_f f_realloc, icalmemory_free_f f_free) |
| Configures the functions to use for memory management. | |
| char * | icalmemory_strdup (const char *s) |
| Creates a duplicate of a string. | |
| void * | icalmemory_tmp_buffer (size_t size) |
| Creates a new temporary buffer on the ring and returns it. | |
| char * | icalmemory_tmp_copy (const char *str) |
| Creates a copy of the given string, stored on the ring buffer, and returns it. | |
Common memory management routines.
Definition in file icalmemory.c.
| #define BUFFER_RING_SIZE 2500 |
Determines the size of the ring buffer used for keeping track of temporary buffers.
Definition at line 31 of file icalmemory.c.
| #define MIN_BUFFER_SIZE 200 |
Determines the minimal size of buffers in the ring that are created with icalmemory_tmp_buffer().
Definition at line 37 of file icalmemory.c.
| void icalmemory_add_tmp_buffer | ( | void * | buf | ) |
Adds an externally allocated buffer to the ring.
| buf | The externally allocated buffer to add to the ring |
Adds an externally allocated buffer to the ring. This ensures that libical will free() the buffer automatically, either after BUFFER_RING_SIZE other buffers have been created or added, or after icalmemory_free_ring() has been called. Note that freeing the buffers is done using the icalmemory_free_buffer() function, which by default is a wrapper around stdlib's free() function. However, if the memory management functions are customized by the user, the user must make sure to only pass in buffers that have been allocated in a compatible manner.
Definition at line 156 of file icalmemory.c.
| void icalmemory_append_char | ( | char ** | buf, |
| char ** | pos, | ||
| size_t * | buf_size, | ||
| char | ch ) |
Appends a character to a buffer.
| buf | The buffer to append the character to. |
| pos | The position to append the character at. |
| buf_size | The size of the buffer (will be changed if buffer is reallocated) |
| ch | The character to append to the buffer. |
This method will copy the character ch and a ‘’\0' character after it to the buffer @a buf starting at position @a pos, reallocing @a buf if it is too small. @a buf_size is the size of @a buf and will be changed if @a buf is reallocated. @a pos will point to the new terminating '\0'` character buf.
Definition at line 404 of file icalmemory.c.
| void icalmemory_append_decoded_string | ( | char ** | buf, |
| char ** | pos, | ||
| size_t * | buf_size, | ||
| const char * | string ) |
Decodes a string as TEXT value and then appends it to the buffer.
Only use on normally allocated memory, or on buffers created from icalmemory_new_buffer, never with buffers created by icalmemory_tmp_buffer. If icalmemory_append_decoded_string has to resize a buffer on the ring, the ring will loose track of it and you will have memory problems
| buf | a pointer to a char string buffer to be appended. The associated memory should not be part of the temporary memory managed by the library. |
| pos | the position in buf in which the new string to be appended |
| buf_size | the size of the buffer before appended |
| string | a pointer to char string to be allocated |
Definition at line 519 of file icalmemory.c.
| void icalmemory_append_encoded_string | ( | char ** | buf, |
| char ** | pos, | ||
| size_t * | buf_size, | ||
| const char * | string ) |
Encodes a string per RFC 6868 and then appends it to the specified char string buffer.
This function filters out the characters not permitted by the RFC. paramtext = *SAFE-CHAR quoted-string= DQUOTE *QSAFE-CHAR DQUOTE
Only use on normally allocated memory, or on buffers created from icalmemory_new_buffer, never with buffers created by icalmemory_tmp_buffer. If icalmemory_append_encoded_string has to resize a buffer on the ring, the ring will loose track of it and you will have memory problems.
| buf | a pointer to a char string buffer to be appended. The associated memory should not be part of the temporary memory managed by the library. |
| pos | the position in buf in which the new string to be appended |
| buf_size | the size of the buffer before appended |
| string | a pointer to char string to be allocated |
Definition at line 476 of file icalmemory.c.
| void icalmemory_append_string | ( | char ** | buf, |
| char ** | pos, | ||
| size_t * | buf_size, | ||
| const char * | string ) |
Appends a string to a buffer.
| buf | The buffer to append the string to. |
| pos | The position to append the string at. |
| buf_size | The size of the buffer (will be changed if buffer is reallocated) |
| string | The string to append to the buffer. |
This method will copy the string string to the buffer buf starting at position pos, reallocing buf if it is too small. buf_size is the size of buf and will be changed if buf is reallocated. pos will point to the last byte of the new string in buf, usually a ‘’\0'`
Definition at line 363 of file icalmemory.c.
| void icalmemory_free_buffer | ( | void * | buf | ) |
Releases a buffer.
| buf | The buffer to release |
Releases the memory of the buffer.
By default this function delegates to stdlib's free() but the used function can be configured via icalmemory_set_mem_alloc_funcs().
Definition at line 353 of file icalmemory.c.
| void icalmemory_free_ring | ( | void | ) |
Frees all memory used in the ring.
Frees all memory used in the ring. If PTHREAD is used or thread-local mode is configured, the ring buffer is allocated on a per-thread basis, meaning that if all rings are to be released, it must be called once in every thread.
Definition at line 202 of file icalmemory.c.
| void icalmemory_get_mem_alloc_funcs | ( | icalmemory_malloc_f * | f_malloc, |
| icalmemory_realloc_f * | f_realloc, | ||
| icalmemory_free_f * | f_free ) |
Returns the functions used for memory management.
| f_malloc | A pointer to the function to use for memory allocation. |
| f_realloc | A pointer to the function to use for memory reallocation. |
| f_free | A pointer to the function to use for memory deallocation. |
Retrieves the functions used by the library for memory management.
Definition at line 293 of file icalmemory.c.
| void * icalmemory_new_buffer | ( | size_t | size | ) |
Creates new buffer with the specified size.
| size | The size of the buffer that is to be created. |
This creates a new (non-temporary) buffer of the specified size. All buffers returned by this method are zeroed-out.
By default this function delegates to stdlib's malloc() but the used function can be changed via icalmemory_set_mem_alloc_funcs().
Definition at line 313 of file icalmemory.c.
| void * icalmemory_resize_buffer | ( | void * | buf, |
| size_t | size ) |
Resizes a buffer created with icalmemory_new_buffer().
| buf | The buffer to be resized. |
| size | The new size of the buffer. |
By default this function delegates to stdlib's realloc() but the used function can be configured via icalmemory_set_mem_alloc_funcs().
Definition at line 334 of file icalmemory.c.
| void icalmemory_set_mem_alloc_funcs | ( | icalmemory_malloc_f | f_malloc, |
| icalmemory_realloc_f | f_realloc, | ||
| icalmemory_free_f | f_free ) |
Configures the functions to use for memory management.
| f_malloc | The function to use for memory allocation. |
| f_realloc | The function to use for memory reallocation. |
| f_free | The function to use for memory deallocation. |
This function configures the library to use the specified functions for memory management. By default the standard system memory management functions malloc(), realloc() and free() are used.
Note: The memory management functions configured via this functions are used throughout the core libical component but not within other components like libicalvcal.
Definition at line 284 of file icalmemory.c.
| char * icalmemory_strdup | ( | const char * | s | ) |
Creates a duplicate of a string.
| s | The string to duplicate. |
Replaces strdup(). The function uses icalmemory_new_buffer() for memory allocation. It also helps trapping calls to strdup() and solves the problem that in -ansi, gcc on Red Hat claims that strdup() is undeclared.
Definition at line 240 of file icalmemory.c.
| void * icalmemory_tmp_buffer | ( | size_t | size | ) |
Creates a new temporary buffer on the ring and returns it.
| size | How big (in bytes) the buffer should be |
Creates a temporary buffer on the ring. Regardless of what size you specify, the buffer will always be at least MIN_BUFFER_SIZE big, and it will be zeroed out.
Definition at line 180 of file icalmemory.c.
| char * icalmemory_tmp_copy | ( | const char * | str | ) |
Creates a copy of the given string, stored on the ring buffer, and returns it.
| str | The string to copy |
Definition at line 220 of file icalmemory.c.