libFirm
Memory Allocation

Macros

#define XMALLOCN(type, n)   ((type*)xmalloc(sizeof(type) * (n)))
 Allocate n objects of a certain type. More...
 
#define XMALLOCNZ(type, n)   ((type*)memset(xmalloc(sizeof(type) * (n)), 0, sizeof(type) * (n)))
 Allocate n objects of a certain type and zero them. More...
 
#define XMALLOC(type)   XMALLOCN(type, 1)
 Allocate one object of a certain type. More...
 
#define XMALLOCZ(type)   XMALLOCNZ(type, 1)
 Allocate one object of a certain type and zero it. More...
 
#define XREALLOC(ptr, type, n)   ((type*)xrealloc(ptr, sizeof(type) * (n)))
 Reallocate n objects of a certain type. More...
 
#define XMALLOCF(type, member, n)   ((type*)xmalloc(offsetof(type, member) + sizeof(*((type*)0)->member) * (n)))
 Allocate an object with n elements of a flexible array member. More...
 
#define XMALLOCFZ(type, member, n)   ((type*)memset(XMALLOCF(type, member, (n)), 0, offsetof(type, member) + sizeof(*((type*)0)->member) * (n)))
 Allocate an object with n elements of a flexible array member and zero the whole object. More...
 
#define ALLOCAN(type, n)   ((type*)alloca(sizeof(type) * (n)))
 Allocate n objects of a certain type on the stack. More...
 
#define ALLOCANZ(type, n)   ((type*)memset((type*)alloca(sizeof(type) * (n)), 0, sizeof(type) * (n)))
 Allocate n objects of a certain type on the stack and zero them. More...
 
#define ALLOCAF(type, member, n)   ((type*)alloca(offsetof(type, member) + sizeof(*((type*)0)->member) * (n)))
 Allocate an object with n elements of a flexible array member on the stack. More...
 
#define OALLOCN(obst, type, n)   ((type*)obstack_alloc((obst), sizeof(type) * (n)))
 Allocate n objects of a certain type on the given obstack. More...
 
#define OALLOCNZ(obst, type, n)   ((type*)memset(OALLOCN((obst), type, (n)), 0, sizeof(type) * (n)))
 Allocate n objects of a certain type on the given obstack and zero them. More...
 
#define OALLOC(obst, type)   OALLOCN(obst, type, 1)
 Allocate one object of a certain type on the given obstack. More...
 
#define OALLOCZ(obst, type)   OALLOCNZ(obst, type, 1)
 Allocate one object of a certain type on the given obstack and zero it. More...
 
#define OALLOCF(obst, type, member, n)   ((type*)obstack_alloc((obst), offsetof(type, member) + sizeof(*((type*)0)->member) * (n)))
 Allocate an object with n elements of a flexible array member on the given obstack. More...
 
#define OALLOCFZ(obst, type, member, n)   ((type*)memset(OALLOCF((obst), type, member, (n)), 0, offsetof(type, member) + sizeof(*((type*)0)->member) * (n)))
 Allocate an object with n elements of a flexible array member on the given obstack and zero the whole object. More...
 

Functions

void * xmalloc (size_t size)
 Allocate size bytes on the heap. More...
 
void * xrealloc (void *ptr, size_t size)
 Chane size of a previously allocated memory block to size bytes. More...
 
char * xstrdup (const char *str)
 Allocates memory and copies string str into it. More...
 

Detailed Description

Macro Definition Documentation

◆ ALLOCAF

#define ALLOCAF (   type,
  member,
 
)    ((type*)alloca(offsetof(type, member) + sizeof(*((type*)0)->member) * (n)))

Allocate an object with n elements of a flexible array member on the stack.

Definition at line 107 of file xmalloc.h.

◆ ALLOCAN

#define ALLOCAN (   type,
 
)    ((type*)alloca(sizeof(type) * (n)))

Allocate n objects of a certain type on the stack.

Definition at line 97 of file xmalloc.h.

◆ ALLOCANZ

#define ALLOCANZ (   type,
 
)    ((type*)memset((type*)alloca(sizeof(type) * (n)), 0, sizeof(type) * (n)))

Allocate n objects of a certain type on the stack and zero them.

Definition at line 102 of file xmalloc.h.

◆ OALLOC

#define OALLOC (   obst,
  type 
)    OALLOCN(obst, type, 1)

Allocate one object of a certain type on the given obstack.

Definition at line 122 of file xmalloc.h.

◆ OALLOCF

#define OALLOCF (   obst,
  type,
  member,
 
)    ((type*)obstack_alloc((obst), offsetof(type, member) + sizeof(*((type*)0)->member) * (n)))

Allocate an object with n elements of a flexible array member on the given obstack.

Definition at line 133 of file xmalloc.h.

◆ OALLOCFZ

#define OALLOCFZ (   obst,
  type,
  member,
 
)    ((type*)memset(OALLOCF((obst), type, member, (n)), 0, offsetof(type, member) + sizeof(*((type*)0)->member) * (n)))

Allocate an object with n elements of a flexible array member on the given obstack and zero the whole object.

Definition at line 139 of file xmalloc.h.

◆ OALLOCN

#define OALLOCN (   obst,
  type,
 
)    ((type*)obstack_alloc((obst), sizeof(type) * (n)))

Allocate n objects of a certain type on the given obstack.

Definition at line 112 of file xmalloc.h.

◆ OALLOCNZ

#define OALLOCNZ (   obst,
  type,
 
)    ((type*)memset(OALLOCN((obst), type, (n)), 0, sizeof(type) * (n)))

Allocate n objects of a certain type on the given obstack and zero them.

Definition at line 117 of file xmalloc.h.

◆ OALLOCZ

#define OALLOCZ (   obst,
  type 
)    OALLOCNZ(obst, type, 1)

Allocate one object of a certain type on the given obstack and zero it.

Definition at line 127 of file xmalloc.h.

◆ XMALLOC

#define XMALLOC (   type)    XMALLOCN(type, 1)

Allocate one object of a certain type.

Definition at line 71 of file xmalloc.h.

◆ XMALLOCF

#define XMALLOCF (   type,
  member,
 
)    ((type*)xmalloc(offsetof(type, member) + sizeof(*((type*)0)->member) * (n)))

Allocate an object with n elements of a flexible array member.

Definition at line 86 of file xmalloc.h.

◆ XMALLOCFZ

#define XMALLOCFZ (   type,
  member,
 
)    ((type*)memset(XMALLOCF(type, member, (n)), 0, offsetof(type, member) + sizeof(*((type*)0)->member) * (n)))

Allocate an object with n elements of a flexible array member and zero the whole object.

Definition at line 92 of file xmalloc.h.

◆ XMALLOCN

#define XMALLOCN (   type,
 
)    ((type*)xmalloc(sizeof(type) * (n)))

Allocate n objects of a certain type.

Definition at line 61 of file xmalloc.h.

◆ XMALLOCNZ

#define XMALLOCNZ (   type,
 
)    ((type*)memset(xmalloc(sizeof(type) * (n)), 0, sizeof(type) * (n)))

Allocate n objects of a certain type and zero them.

Definition at line 66 of file xmalloc.h.

◆ XMALLOCZ

#define XMALLOCZ (   type)    XMALLOCNZ(type, 1)

Allocate one object of a certain type and zero it.

Definition at line 76 of file xmalloc.h.

◆ XREALLOC

#define XREALLOC (   ptr,
  type,
 
)    ((type*)xrealloc(ptr, sizeof(type) * (n)))

Reallocate n objects of a certain type.

Definition at line 81 of file xmalloc.h.

Function Documentation

◆ xmalloc()

void* xmalloc ( size_t  size)

Allocate size bytes on the heap.

This is a wrapper for malloc which calls panic() in case of errors, so no error handling is required for code using it.

◆ xrealloc()

void* xrealloc ( void *  ptr,
size_t  size 
)

Chane size of a previously allocated memory block to size bytes.

This is a wrapper for realloc which calls panic() in case of errors, so no error handling is required for code using it.

◆ xstrdup()

char* xstrdup ( const char *  str)

Allocates memory and copies string str into it.

This is a wrapper for strdup which calls panic() in case of errors, so no error handling is required for code using it.