Skip to content

Commit

Permalink
Add xalloc_try_alloc.
Browse files Browse the repository at this point in the history
* Doesn't raise exception if there's no memory
  • Loading branch information
iabdalkader committed Jan 12, 2017
1 parent e82e3ab commit 2d20135
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/omv/xalloc.c
Expand Up @@ -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)
{
Expand Down
1 change: 1 addition & 0 deletions src/omv/xalloc.h
Expand Up @@ -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);
Expand Down

0 comments on commit 2d20135

Please sign in to comment.