- free(m);
-}
-
-
-/* dump_alloc ******************************************************************
-
- Allocate memory in the dump area.
-
- IN:
- size.........size of block to allocate, in bytes
- may be zero, in which case NULL is returned
-
- RETURN VALUE:
- pointer to allocated memory, or
- NULL iff `size` was zero
-
- ERROR HANDLING:
- XXX This function uses `memory_checked_alloc`, which *exits* if no
- memory could be allocated.
-
- THREADS:
- dump_alloc is thread safe. Each thread has its own dump memory area.
-
- dump_alloc is a fast allocator suitable for scratch memory that can be
- collectively freed when the current activity (eg. compiling) is done.
-
- You cannot selectively free dump memory. Before you start allocating it,
- you remember the current size returned by `dump_size`. Later, when you no
- longer need the memory, call `dump_release` with the remembered size and
- all dump memory allocated since the call to `dump_size` will be freed.
-
-*******************************************************************************/
-
-void *dump_alloc(s4 size)
-{
-#if defined(DISABLE_DUMP)
-
- /* use malloc memory for dump memory (for debugging only!) */
-
- return mem_alloc(size);
-
-#else /* !defined(DISABLE_DUMP) */
-
- void *m;
- dumpinfo_t *di;
-
- /* If no threads are used, the dumpinfo structure is a static structure */
- /* defined at the top of this file. */
-
- di = DUMPINFO;
-
- if (size == 0)
- return NULL;
-
- size = ALIGN(size, ALIGNSIZE);
-
- if (di->useddumpsize + size > di->allocateddumpsize) {
- dumpblock_t *newdumpblock;
- s4 newdumpblocksize;
-
- /* allocate a new dumplist structure */
-
- newdumpblock = memory_checked_alloc(sizeof(dumpblock_t));
-
- /* If requested size is greater than the default, make the new dump */
- /* block as big as the size requested. Else use the default size. */
-
- if (size > DUMPBLOCKSIZE) {
- newdumpblocksize = size;
-
- } else {
- newdumpblocksize = DUMPBLOCKSIZE;
- }
-
- /* allocate dumpblock memory */
-
- newdumpblock->dumpmem = memory_checked_alloc(newdumpblocksize);
-
- newdumpblock->prev = di->currentdumpblock;
- newdumpblock->size = newdumpblocksize;
- di->currentdumpblock = newdumpblock;
-
- /* Used dump size is previously allocated dump size, because the */
- /* remaining free memory of the previous dump block cannot be used. */
-
- di->useddumpsize = di->allocateddumpsize;
-
- /* increase the allocated dump size by the size of the new dump block */
-
- di->allocateddumpsize += newdumpblocksize;
-
-#if defined(ENABLE_STATISTICS)
- /* the amount of globally allocated dump memory (thread save) */
-
- if (opt_stat)
- globalallocateddumpsize += newdumpblocksize;
-#endif
- }
-
- /* current dump block base address + the size of the current dump block - */
- /* the size of the unused memory = new start address */
-
- m = di->currentdumpblock->dumpmem + di->currentdumpblock->size -
- (di->allocateddumpsize - di->useddumpsize);
-
- /* increase used dump size by the allocated memory size */
-
- di->useddumpsize += size;
-
-#if defined(ENABLE_STATISTICS)
- if (opt_stat)
- if (di->useddumpsize > maxdumpsize)
- maxdumpsize = di->useddumpsize;