Add xalloc_try_alloc.

* Doesn't raise exception if there's no memory
This commit is contained in:
iabdalkader 2017-01-12 04:47:09 +02:00
parent e82e3ab785
commit 2d201357a6
2 changed files with 11 additions and 0 deletions

View File

@ -24,6 +24,16 @@ void *xalloc(uint32_t size)
return mem;
}
// returns null pointer without error if size==0
void *xalloc_try_alloc(uint32_t size)
{
void *mem = gc_alloc(size, false);
if (size && (mem == NULL)) {
return NULL;
}
return mem;
}
// returns null pointer without error if size==0
void *xalloc0(uint32_t size)
{

View File

@ -10,6 +10,7 @@
#define __XALLOC_H__
#include <stdint.h>
void *xalloc(uint32_t size);
void *xalloc_try_alloc(uint32_t size);
void *xalloc0(uint32_t size);
void xfree(void *mem);
void *xrealloc(void *mem, uint32_t size);