+2007-02-01 Jim Meyering <jim@meyering.net>
+
+ Give tools a better chance to allocate space for very large buffers.
+ * lib/xalloc.h (x2nrealloc): Use 3/2, not 2, as buffer size factor.
+
2007-02-01 Karl Berry <karl@gnu.org>
* config/srclist.txt (strtok_r.c): lose sync, no more strtok_r.h.
/* xalloc.h -- malloc with out-of-memory checking
Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
- 1999, 2000, 2003, 2004, 2006 Free Software Foundation, Inc.
+ 1999, 2000, 2003, 2004, 2006, 2007 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
allocating an initial block with a nonzero size, or by allocating a
larger block.
- In the following implementation, nonzero sizes are doubled so that
- repeated reallocations have O(N log N) overall cost rather than
- O(N**2) cost, but the specification for this function does not
- guarantee that sizes are doubled.
+ In the following implementation, nonzero sizes are increased by a
+ factor of approximately 1.5 so that repeated reallocations have
+ O(N log N) overall cost rather than O(N**2) cost, but the
+ specification for this function does not guarantee that rate.
Here is an example of use:
}
else
{
- if (((size_t) -1) / 2 / s < n)
+ if ((2 * (((size_t) -1 - 1) / 3)) / s < n)
xalloc_die ();
- n *= 2;
+ n = n + n / 2 + 1;
}
*pn = n;