FreeBSD/contrib/subversion/subversion/libsvn_fs_fs/cached_data.c
/* Determine the optimal size of a string buf that shall receive a
 * (full-) text of NEEDED bytes.
 *
 * The critical point is that those buffers may be very large and
 * can cause memory fragmentation.  We apply simple heuristics to
 * make fragmentation less likely.
 */
Determine the optimal size of a string buf that shall receive a
(full-) text of NEEDED bytes.

The critical point is that those buffers may be very large and
can cause memory fragmentation.  We apply simple heuristics to
make fragmentation less likely.
Determine the optimal size of a string buf that shall receive a ( full - ) text of NEEDED bytes . The critical point is that those buffers may be very large and can cause memory fragmentation . We apply simple heuristics to make fragmentation less likely .
static apr_size_t
optimimal_allocation_size(apr_size_t needed)
{
  const apr_size_t overhead = 0x400;
  apr_size_t optimal;
  if (needed <= SVN__STREAM_CHUNK_SIZE)
    return needed;
  if (needed >= APR_SIZE_MAX / 2 - overhead)
    return needed;
  optimal = SVN__STREAM_CHUNK_SIZE;
  while (optimal - overhead < needed)
    optimal *= 2;
  return optimal - overhead;
}
static apr_size_t optimimal_allocation_size ( apr_size_t needed ) { const apr_size_t overhead = 0x400 ; apr_size_t optimal ; if ( needed <= SVN__STREAM_CHUNK_SIZE ) return needed ; if ( needed >= APR_SIZE_MAX / 2 - overhead ) return needed ; optimal = SVN__STREAM_CHUNK_SIZE ; while ( optimal - overhead < needed ) optimal *= 2 ; return optimal - overhead ; }
Determine the optimal size of a string buf that shall receive a
 (full-) text of NEEDED bytes.
Determine the optimal size of a string buf that shall receive a ( full - ) text of NEEDED bytes .
/* For all allocations, assume some overhead that is shared between
   * OS memory managemnt, APR memory management and svn_stringbuf_t. */ /* If an allocation size if safe for other ephemeral buffers, it should
   * be safe for ours. */ /* Paranoia edge case:
   * Skip our heuristics if they created arithmetical overflow.
   * Beware to make this test work for NEEDED = APR_SIZE_MAX as well! */ /* As per definition SVN__STREAM_CHUNK_SIZE is a power of two.
   * Since we know NEEDED to be larger than that, use it as the
   * starting point.
   *
   * Heuristics: Allocate a power-of-two number of bytes that fit
   *             NEEDED plus some OVERHEAD.  The APR allocator
   *             will round it up to the next full page size.
   */ /* This is above or equal to NEEDED. */