
Go to the source code of this file.
| Defines | |
| #define | ENOMEM 12 | 
| Memory functions. | |
| #define | MALLOC(SIZE) malloc( SIZE ) | 
| #define | CALLOC(COUNT, SIZE) calloc( COUNT, SIZE ) | 
| #define | FREE(PTR) free( PTR ) | 
| #define | REALLOC(OLDPTR, OLDSIZE, NEWSIZE) realloc( OLDPTR, NEWSIZE ) | 
| #define | MALLOC_STRUCT(T) (struct T *) MALLOC(sizeof(struct T)) | 
| #define | CALLOC_STRUCT(T) (struct T *) CALLOC(1, sizeof(struct T)) | 
| #define | Elements(x) (sizeof(x)/sizeof((x)[0])) | 
| Number of elements in an array. | |
| #define | Offset(TYPE, MEMBER) ((unsigned)&(((TYPE *)NULL)->MEMBER)) | 
| Offset of a field in a struct, in bytes. | |
| Functions | |
| static void * | align_malloc (size_t bytes, uint alignment) | 
| Return memory on given byte alignment. | |
| static void | align_free (void *ptr) | 
| Free memory returned by align_malloc(). | |
| static void * | mem_dup (const void *src, uint size) | 
| Duplicate a block of memory. | |
| #define CALLOC | ( | COUNT, | |||
| SIZE | ) | calloc( COUNT, SIZE ) | 
Definition at line 100 of file u_memory.h.
| #define CALLOC_STRUCT | ( | T | ) | (struct T *) CALLOC(1, sizeof(struct T)) | 
Definition at line 151 of file u_memory.h.
| #define Elements | ( | x | ) | (sizeof(x)/sizeof((x)[0])) | 
| #define ENOMEM 12 | 
| #define FREE | ( | PTR | ) | free( PTR ) | 
Definition at line 101 of file u_memory.h.
| #define MALLOC | ( | SIZE | ) | malloc( SIZE ) | 
Definition at line 99 of file u_memory.h.
| #define MALLOC_STRUCT | ( | T | ) | (struct T *) MALLOC(sizeof(struct T)) | 
Definition at line 149 of file u_memory.h.
| #define Offset | ( | TYPE, | |||
| MEMBER | ) | ((unsigned)&(((TYPE *)NULL)->MEMBER)) | 
| #define REALLOC | ( | OLDPTR, | |||
| OLDSIZE, | |||||
| NEWSIZE | ) | realloc( OLDPTR, NEWSIZE ) | 
Definition at line 102 of file u_memory.h.
| static void align_free | ( | void * | ptr | ) |  [static] | 
Free memory returned by align_malloc().
Definition at line 186 of file u_memory.h.
References FREE.
00188 { 00189 #if defined(HAVE_POSIX_MEMALIGN) 00190 FREE(ptr); 00191 #else 00192 void **cubbyHole = (void **) ((char *) ptr - sizeof(void *)); 00193 void *realAddr = *cubbyHole; 00194 FREE(realAddr); 00195 #endif /* defined(HAVE_POSIX_MEMALIGN) */
| static void* align_malloc | ( | size_t | bytes, | |
| uint | alignment | |||
| ) |  [static] | 
Return memory on given byte alignment.
Definition at line 158 of file u_memory.h.
References align_pointer(), assert, and MALLOC.
00160 { 00161 #if defined(HAVE_POSIX_MEMALIGN) 00162 void *mem; 00163 alignment = (alignment + (uint)sizeof(void*) - 1) & ~((uint)sizeof(void*) - 1); 00164 if(posix_memalign(& mem, alignment, bytes) != 0) 00165 return NULL; 00166 return mem; 00167 #else 00168 char *ptr, *buf; 00169 00170 assert( alignment > 0 ); 00171 00172 ptr = (char *) MALLOC(bytes + alignment + sizeof(void *)); 00173 if (!ptr) 00174 return NULL; 00175 00176 buf = (char *) align_pointer( ptr + sizeof(void *), alignment ); 00177 *(char **)(buf - sizeof(void *)) = ptr; 00178 00179 return buf; 00180 #endif /* defined(HAVE_POSIX_MEMALIGN) */
| static void* mem_dup | ( | const void * | src, | |
| uint | size | |||
| ) |  [static] | 
Duplicate a block of memory.
Definition at line 202 of file u_memory.h.
References MALLOC.
00204 { 00205 void *dup = MALLOC(size); 00206 if (dup) 00207 memcpy(dup, src, size); 00208 return dup;
 1.5.4
 1.5.4