The basic allocation interface. More...
Functions | |
| void | mi_free (void *p) |
| Free previously allocated memory. | |
| void | mi_cfree (void *p) |
| Checked free: just as mi_free() but always checks if the pointer p belongs to our heap. | |
| void * | mi_malloc (size_t size) |
| Allocate size bytes. | |
| void * | mi_zalloc (size_t size) |
| Allocate zero-initialized size bytes. | |
| void * | mi_calloc (size_t count, size_t size) |
| Allocate zero-initialized count elements of size bytes. | |
| void * | mi_realloc (void *p, size_t newsize) |
| Re-allocate memory to newsize bytes. | |
| void * | mi_expand (void *p, size_t newsize) |
| Try to re-allocate memory to newsize bytes in place. | |
| void * | mi_mallocn (size_t count, size_t size) |
| Allocate count elements of size bytes. | |
| void * | mi_reallocn (void *p, size_t count, size_t size) |
| Re-allocate memory to count elements of size bytes. | |
| void * | mi_reallocf (void *p, size_t newsize) |
| Re-allocate memory to newsize bytes,. | |
| char * | mi_strdup (const char *s) |
| Allocate and duplicate a string. | |
| char * | mi_strndup (const char *s, size_t n) |
| Allocate and duplicate a string up to n bytes. | |
| char * | mi_realpath (const char *fname, char *resolved_name) |
| Resolve a file path name. | |
| size_t | mi_usable_size (void *p) |
| Return the available bytes in a memory block. | |
| size_t | mi_good_size (size_t size) |
| Return the probable allocation block size for a given required size. | |
The basic allocation interface.
| void * mi_calloc | ( | size_t | count, |
| size_t | size ) |
Allocate zero-initialized count elements of size bytes.
| count | number of elements. |
| size | size of each element. |
Returns a unique pointer if called with either size or count of 0.
| void mi_cfree | ( | void * | p | ) |
Checked free: just as mi_free() but always checks if the pointer p belongs to our heap.
| p | pointer to a block that is freed, or any other arbitrary pointer. This is safe to use when a pointer might be invalid or allocated by another allocator (in which case the pointer is ignored and not freed). |
| void * mi_expand | ( | void * | p, |
| size_t | newsize ) |
Try to re-allocate memory to newsize bytes in place.
| p | pointer to previously allocated memory (or NULL). |
| newsize | the new required size in bytes. |
| void mi_free | ( | void * | p | ) |
Free previously allocated memory.
The pointer p must have been allocated before (or be NULL).
| p | pointer to the block that is freed, or NULL. See also mi_cfree() for a checked free that validates the pointer before free-ing. |
| size_t mi_good_size | ( | size_t | size | ) |
Return the probable allocation block size for a given required size.
| size | The minimal required size in bytes. |
Generally, mi_usable_size(mi_malloc(size)) == mi_good_size(size). This function can be used to reduce internal wasted space when allocating buffers for example.
| void * mi_malloc | ( | size_t | size | ) |
Allocate size bytes.
| size | number of bytes to allocate. |
| void * mi_mallocn | ( | size_t | count, |
| size_t | size ) |
Allocate count elements of size bytes.
| count | The number of elements. |
| size | The size of each element. |
If there is no overflow, it behaves exactly like mi_malloc(count*size).
| void * mi_realloc | ( | void * | p, |
| size_t | newsize ) |
Re-allocate memory to newsize bytes.
| p | pointer to previously allocated memory (or NULL). |
| newsize | the new required size in bytes. |
| void * mi_reallocf | ( | void * | p, |
| size_t | newsize ) |
Re-allocate memory to newsize bytes,.
| p | pointer to previously allocated memory (or NULL). |
| newsize | the new required size in bytes. |
In contrast to mi_realloc(), if NULL is returned, the original pointer p is freed (if it was not NULL itself). Otherwise the original pointer is either freed or returned as the reallocated result (in case it fits in-place with the new size). If the pointer p is NULL, it behaves as mi_malloc(newsize). If newsize is larger than the original size allocated for p, the bytes after size are uninitialized.
| void * mi_reallocn | ( | void * | p, |
| size_t | count, | ||
| size_t | size ) |
Re-allocate memory to count elements of size bytes.
| p | Pointer to a previously allocated block (or NULL). |
| count | The number of elements. |
| size | The size of each element. |
If there is no overflow, it behaves exactly like mi_realloc(p,count*size).
| char * mi_realpath | ( | const char * | fname, |
| char * | resolved_name ) |
Resolve a file path name.
| fname | File name. |
| resolved_name | Should be NULL (but can also point to a buffer of at least PATH_MAX bytes). |
If resolved_name was NULL, the returned result should be freed with mi_free().
Replacement for the standard realpath() such that mi_free() can be used on the returned result (if resolved_name was NULL).
| char * mi_strdup | ( | const char * | s | ) |
| char * mi_strndup | ( | const char * | s, |
| size_t | n ) |
Allocate and duplicate a string up to n bytes.
| s | string to duplicate (or NULL). |
| n | maximum number of bytes to copy (excluding the terminating zero). |
Replacement for the standard strndup() such that mi_free() can be used on the returned result.
| size_t mi_usable_size | ( | void * | p | ) |
Return the available bytes in a memory block.
| p | Pointer to previously allocated memory (or NULL) |
The returned size can be used to call mi_expand successfully. The returned size is always at least equal to the allocated size of p.
| void * mi_zalloc | ( | size_t | size | ) |
Allocate zero-initialized size bytes.
| size | The size in bytes. |