libgit2

git_allocator

Version:

An instance for a custom memory allocator

Setting the pointers of this structure allows the developer to implement custom memory allocators. The global memory allocator can be set by using "GIT_OPT_SET_ALLOCATOR" with the git_libgit2_opts function. Keep in mind that all fields need to be set to a proper function.

Signature

typedef struct git_allocator { void *(*)(size_t, const char *, int) gmalloc void *(*)(size_t, size_t, const char *, int) gcalloc char *(*)(const char *, const char *, int) gstrdup char *(*)(const char *, size_t, const char *, int) gstrndup char *(*)(const char *, size_t, const char *, int) gsubstrdup void *(*)(void *, size_t, const char *, int) grealloc void *(*)(void *, size_t, size_t, const char *, int) greallocarray void *(*)(size_t, size_t, const char *, int) gmallocarray void (*)(void *) gfree };

Members

void *(*)(size_t, const char *, int)
gmalloc

Allocate n bytes of memory

void *(*)(size_t, size_t, const char *, int)
gcalloc

Allocate memory for an array of nelem elements, where each element has a size of elsize. Returned memory shall be initialized to all-zeroes

char *(*)(const char *, const char *, int)
gstrdup

Allocate memory for the string str and duplicate its contents.

char *(*)(const char *, size_t, const char *, int)
gstrndup

Equivalent to the gstrdup function, but only duplicating at most n + 1 bytes

char *(*)(const char *, size_t, const char *, int)
gsubstrdup

Equivalent to gstrndup, but will always duplicate exactly n bytes of str. Thus, out of bounds reads at str may happen.

void *(*)(void *, size_t, const char *, int)
grealloc

This function shall deallocate the old object ptr and return a pointer to a new object that has the size specified by size. In case ptr is NULL, a new array shall be allocated.

void *(*)(void *, size_t, size_t, const char *, int)
greallocarray

This function shall be equivalent to grealloc, but allocating neleme * elsize bytes.

void *(*)(size_t, size_t, const char *, int)
gmallocarray

This function shall allocate a new array of nelem elements, where each element has a size of elsize bytes.

void (*)(void *)
gfree

This function shall free the memory pointed to by ptr. In case ptr is NULL, this shall be a no-op.

Parameter To

Versions