29 #include <yaz/xmalloc.h>
46 size_t words = (4*
sizeof(unsigned) -1 + size)/
sizeof(unsigned);
47 char *p = (
char *)xmalloc( words*
sizeof(
unsigned) );
49 yaz_log (YLOG_FATAL,
"No memory: imalloc(%u); c/f %d/%d; %ld/%ld",
50 size, alloc_calls, free_calls, alloc, max_alloc );
51 *((
unsigned *)p) = size;
52 ((
unsigned *)p)[1] = MAG1;
53 p +=
sizeof(unsigned)*2;
54 size[(
unsigned char *) p] = MAG2;
55 size[(
unsigned char *) p+1] = MAG3;
56 if( (alloc+=size) > max_alloc )
61 void *p = (
void *)xmalloc( size );
63 yaz_log (YLOG_FATAL,
"Out of memory (imalloc)" );
71 unsigned words = (4*
sizeof(unsigned) -1 + size)/
sizeof(unsigned);
72 char *p = (
char *) xcalloc( words*
sizeof(
unsigned), 1 );
74 yaz_log (YLOG_FATAL,
"No memory: icalloc(%u); c/f %d/%d; %ld/%ld",
75 size, alloc_calls, free_calls, alloc, max_alloc );
76 ((
unsigned *)p)[0] = size;
77 ((
unsigned *)p)[1] = MAG1;
78 p +=
sizeof(unsigned)*2;
79 size[(
unsigned char *) p] = MAG2;
80 size[(
unsigned char *) p+1] = MAG3;
81 if( (alloc+=size) > max_alloc )
86 void *p = (
void *) xcalloc( size, 1 );
88 yaz_log (YLOG_FATAL,
"Out of memory (icalloc)" );
100 size = (-2)[(
unsigned *) p];
101 if( (-1)[(
unsigned *) p] != MAG1 )
102 yaz_log (YLOG_FATAL,
"Internal: ifree(%u) magic 1 corrupted", size );
103 if( size[(
unsigned char *) p] != MAG2 )
104 yaz_log (YLOG_FATAL,
"Internal: ifree(%u) magic 2 corrupted", size );
105 if( (size+1)[(
unsigned char *) p] != MAG3 )
106 yaz_log (YLOG_FATAL,
"Internal: ifree(%u) magic 3 corrupted", size );
109 yaz_log (YLOG_FATAL,
"Internal: ifree(%u) negative alloc.", size );
110 xfree( (
unsigned *) p-2 );
119 fprintf( stdout,
"imalloc: calls malloc/free %d/%d, ",
120 alloc_calls, free_calls );
122 fprintf( stdout,
"memory cur/max %ld/%ld : unreleased",
125 fprintf( stdout,
"memory max %ld", max_alloc );
126 fputc(
'\n', stdout );
void * icalloc(size_t size)
void * imalloc(size_t size)