MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / ztrymalloc_usable

Function ztrymalloc_usable

src/zmalloc.cpp:111–127  ·  view source on GitHub ↗

Try allocating memory, and return NULL if failed. * '*usable' is set to the usable size if non NULL. */

Source from the content-addressed store, hash-verified

109/* Try allocating memory, and return NULL if failed.
110 * '*usable' is set to the usable size if non NULL. */
111void *ztrymalloc_usable(size_t size, size_t *usable) {
112 ASSERT_NO_SIZE_OVERFLOW(size);
113 void *ptr = malloc(MALLOC_MIN_SIZE(size)+PREFIX_SIZE, MALLOC_LOCAL);
114
115 if (!ptr) return NULL;
116#ifdef HAVE_MALLOC_SIZE
117 size = zmalloc_size(ptr);
118 update_zmalloc_stat_alloc(size);
119 if (usable) *usable = size;
120 return ptr;
121#else
122 *((size_t*)ptr) = size;
123 update_zmalloc_stat_alloc(size+PREFIX_SIZE);
124 if (usable) *usable = size;
125 return (char*)ptr+PREFIX_SIZE;
126#endif
127}
128
129/* Allocate memory or panic */
130void *zmalloc(size_t size, enum MALLOC_CLASS /*mclass*/) {

Callers 4

zmallocFunction · 0.85
ztrymallocFunction · 0.85
zmalloc_usableFunction · 0.85
ztryrealloc_usableFunction · 0.85

Calls 2

mallocFunction · 0.85
zmalloc_sizeFunction · 0.85

Tested by

no test coverage detected