ldmud-3.4.1/doc/
ldmud-3.4.1/doc/efun.de/
ldmud-3.4.1/doc/efun/
ldmud-3.4.1/doc/man/
ldmud-3.4.1/doc/other/
ldmud-3.4.1/mud/
ldmud-3.4.1/mud/heaven7/
ldmud-3.4.1/mud/lp-245/
ldmud-3.4.1/mud/lp-245/banish/
ldmud-3.4.1/mud/lp-245/doc/
ldmud-3.4.1/mud/lp-245/doc/examples/
ldmud-3.4.1/mud/lp-245/doc/sefun/
ldmud-3.4.1/mud/lp-245/log/
ldmud-3.4.1/mud/lp-245/obj/Go/
ldmud-3.4.1/mud/lp-245/players/lars/
ldmud-3.4.1/mud/lp-245/room/death/
ldmud-3.4.1/mud/lp-245/room/maze1/
ldmud-3.4.1/mud/lp-245/room/sub/
ldmud-3.4.1/mud/lp-245/secure/
ldmud-3.4.1/mud/morgengrauen/
ldmud-3.4.1/mud/morgengrauen/lib/
ldmud-3.4.1/mud/sticklib/
ldmud-3.4.1/mud/sticklib/src/
ldmud-3.4.1/mudlib/uni-crasher/
ldmud-3.4.1/pkg/
ldmud-3.4.1/pkg/debugger/
ldmud-3.4.1/pkg/diff/
ldmud-3.4.1/pkg/misc/
ldmud-3.4.1/src/autoconf/
ldmud-3.4.1/src/hosts/
ldmud-3.4.1/src/hosts/GnuWin32/
ldmud-3.4.1/src/hosts/amiga/
ldmud-3.4.1/src/hosts/win32/
ldmud-3.4.1/src/ptmalloc/
ldmud-3.4.1/src/util/
ldmud-3.4.1/src/util/erq/
ldmud-3.4.1/src/util/indent/hosts/next/
ldmud-3.4.1/src/util/xerq/
ldmud-3.4.1/src/util/xerq/lpc/
ldmud-3.4.1/src/util/xerq/lpc/www/
ldmud-3.4.1/test/t-030925/
ldmud-3.4.1/test/t-040413/
ldmud-3.4.1/test/t-041124/
/*---------------------------------------------------------------------------
 * Determine the malloc() overhead.
 *
 *---------------------------------------------------------------------------
 * Utilityprogram for the configure script to estimate the overhead
 * of the system malloc(). The algorithm is to allocate two blocks and
 * measuring the difference in addresses. This is repeated for various
 * block sizes and the minimum of the found differences is selected.
 *
 * Usage: overhead [--terse]
 *
 * If '--terse' is given, overhead prints just the number otherwise
 * a nice message.
 *
 * Exit status is 1 if the overhead could not be determined.
 *---------------------------------------------------------------------------
 */

#include <stdio.h>
#if defined(HAVE_STDLIB_H) || defined(AMIGA)
#  include <stdlib.h>
#endif
#ifdef HAVE_LIBC_H
#  include <libc.h>
#endif

/*-------------------------------------------------------------------------*/
int
main (int argc, char **argv)

{
    int i, d, min;
    char *p, *q;
    int terse;
    int total = 12, negative = 0, min_index = 0;

    terse = argc > 1 && !strcmp(argv[1], "--terse");

    i = 0x8000;
    min = i;
    d = i;
    do
    {
	p = malloc(i);
	q = malloc(i);
	total++;
	d = q - (p+i);
	if (d <= min)
	{
	    if (d < 0)
	    {
		negative++;
		if (negative*3 > total*2)
		{
		    fprintf(
		      stderr,
		      "Malloc returns does not return increasing addresses\n"
		    );
		    if (terse)
			printf("0");
		    exit(1);
		}
		continue;
	    }
	    if (d == min)
		break;
	    min = d;
	    min_index = i;
	    if (d == 0)
		break;
	}
	i -= sizeof(char *);
    } while (i >= 0x7f00);

    d = 0x8000 - min_index;

    if (d > 0x100 || min > 0x1000)
    {
	fprintf(stderr, "no credible value for EXTERN_MALLOC_OVERHEAD found\n");
	if (terse)
	    printf("0");
	fflush(stdout);
	exit(1);
    }

    printf(terse ? "%d" : "Suggested EXTERN_MALLOC_OVERHEAD: %d\n", d);
    if (!terse && d != min)
	printf("Actual overhead encountered for the above setting:%d\n", min);
    return 0;
} /* main() */

/***************************************************************************/