2 * Copyright (C) 1994-1996, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.6 1996-10-29 13:57:25 adam
8 * Include of zebrautl.h instead of alexutil.h.
10 * Revision 1.5 1996/05/14 11:33:41 adam
11 * MEMDEBUG turned off by default.
13 * Revision 1.4 1995/09/04 12:33:26 adam
14 * Various cleanup. YAZ util used instead.
16 * Revision 1.3 1994/09/27 16:31:19 adam
17 * First version of grepper: grep with error correction.
19 * Revision 1.2 1994/09/26 16:30:56 adam
20 * Minor changes. imalloc uses xmalloc now.
22 * Revision 1.1 1994/09/26 10:16:54 adam
23 * First version of dfa module in alex. This version uses yacc to parse
24 * regular expressions. This should be hand-made instead.
45 void *imalloc (size_t size)
48 size_t words = (4*sizeof(unsigned) -1 + size)/sizeof(unsigned);
49 char *p = (char *)xmalloc( words*sizeof(unsigned) );
51 logf (LOG_FATAL, "No memory: imalloc(%u); c/f %d/%d; %ld/%ld",
52 size, alloc_calls, free_calls, alloc, max_alloc );
53 *((unsigned *)p) = size;
54 ((unsigned *)p)[1] = MAG1;
55 p += sizeof(unsigned)*2;
56 size[(unsigned char *) p] = MAG2;
57 size[(unsigned char *) p+1] = MAG3;
58 if( (alloc+=size) > max_alloc )
63 void *p = (void *)xmalloc( size );
65 logf (LOG_FATAL, "Out of memory (imalloc)" );
70 void *icalloc (size_t size)
73 unsigned words = (4*sizeof(unsigned) -1 + size)/sizeof(unsigned);
74 char *p = (char *) xcalloc( words*sizeof(unsigned), 1 );
76 logf (LOG_FATAL, "No memory: icalloc(%u); c/f %d/%d; %ld/%ld",
77 size, alloc_calls, free_calls, alloc, max_alloc );
78 ((unsigned *)p)[0] = size;
79 ((unsigned *)p)[1] = MAG1;
80 p += sizeof(unsigned)*2;
81 size[(unsigned char *) p] = MAG2;
82 size[(unsigned char *) p+1] = MAG3;
83 if( (alloc+=size) > max_alloc )
88 void *p = (void *) xcalloc( size, 1 );
90 logf (LOG_FATAL, "Out of memory (icalloc)" );
102 size = (-2)[(unsigned *) p];
103 if( (-1)[(unsigned *) p] != MAG1 )
104 logf (LOG_FATAL,"Internal: ifree(%u) magic 1 corrupted", size );
105 if( size[(unsigned char *) p] != MAG2 )
106 logf (LOG_FATAL,"Internal: ifree(%u) magic 2 corrupted", size );
107 if( (size+1)[(unsigned char *) p] != MAG3 )
108 logf (LOG_FATAL,"Internal: ifree(%u) magic 3 corrupted", size );
111 logf (LOG_FATAL,"Internal: ifree(%u) negative alloc.", size );
112 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 );