2 * Copyright (C) 1994-1999, Index Data
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.8 1999-02-02 14:50:08 adam
8 * Updated WIN32 code specific sections. Changed header.
10 * Revision 1.7 1997/10/27 14:27:13 adam
13 * Revision 1.6 1996/10/29 13:57:25 adam
14 * Include of zebrautl.h instead of alexutil.h.
16 * Revision 1.5 1996/05/14 11:33:41 adam
17 * MEMDEBUG turned off by default.
19 * Revision 1.4 1995/09/04 12:33:26 adam
20 * Various cleanup. YAZ util used instead.
22 * Revision 1.3 1994/09/27 16:31:19 adam
23 * First version of grepper: grep with error correction.
25 * Revision 1.2 1994/09/26 16:30:56 adam
26 * Minor changes. imalloc uses xmalloc now.
28 * Revision 1.1 1994/09/26 10:16:54 adam
29 * First version of dfa module in alex. This version uses yacc to parse
30 * regular expressions. This should be hand-made instead.
51 void *imalloc (size_t size)
54 size_t words = (4*sizeof(unsigned) -1 + size)/sizeof(unsigned);
55 char *p = (char *)xmalloc( words*sizeof(unsigned) );
57 logf (LOG_FATAL, "No memory: imalloc(%u); c/f %d/%d; %ld/%ld",
58 size, alloc_calls, free_calls, alloc, max_alloc );
59 *((unsigned *)p) = size;
60 ((unsigned *)p)[1] = MAG1;
61 p += sizeof(unsigned)*2;
62 size[(unsigned char *) p] = MAG2;
63 size[(unsigned char *) p+1] = MAG3;
64 if( (alloc+=size) > max_alloc )
69 void *p = (void *)xmalloc( size );
71 logf (LOG_FATAL, "Out of memory (imalloc)" );
76 void *icalloc (size_t size)
79 unsigned words = (4*sizeof(unsigned) -1 + size)/sizeof(unsigned);
80 char *p = (char *) xcalloc( words*sizeof(unsigned), 1 );
82 logf (LOG_FATAL, "No memory: icalloc(%u); c/f %d/%d; %ld/%ld",
83 size, alloc_calls, free_calls, alloc, max_alloc );
84 ((unsigned *)p)[0] = size;
85 ((unsigned *)p)[1] = MAG1;
86 p += sizeof(unsigned)*2;
87 size[(unsigned char *) p] = MAG2;
88 size[(unsigned char *) p+1] = MAG3;
89 if( (alloc+=size) > max_alloc )
94 void *p = (void *) xcalloc( size, 1 );
96 logf (LOG_FATAL, "Out of memory (icalloc)" );
108 size = (-2)[(unsigned *) p];
109 if( (-1)[(unsigned *) p] != MAG1 )
110 logf (LOG_FATAL,"Internal: ifree(%u) magic 1 corrupted", size );
111 if( size[(unsigned char *) p] != MAG2 )
112 logf (LOG_FATAL,"Internal: ifree(%u) magic 2 corrupted", size );
113 if( (size+1)[(unsigned char *) p] != MAG3 )
114 logf (LOG_FATAL,"Internal: ifree(%u) magic 3 corrupted", size );
117 logf (LOG_FATAL,"Internal: ifree(%u) negative alloc.", size );
118 xfree( (unsigned *) p-2 );
127 fprintf( stdout, "imalloc: calls malloc/free %d/%d, ",
128 alloc_calls, free_calls );
130 fprintf( stdout, "memory cur/max %ld/%ld : unreleased",
133 fprintf( stdout, "memory max %ld", max_alloc );
134 fputc( '\n', stdout );