This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [Fwd: basic_string<> - useless because of its poor performance]
On Fri, Jul 06, 2001 at 02:35:19AM -0500, Loren James Rittle wrote:
> + // This version assumes the malloc implementation prefers to
> + // align allocations over the size of a page to a page boundary
> + // and under the size of a page to a power of 2.
> + const size_t __pagesize = 4096; // This magic constant, from OS.
> + const size_t __malloc_header_size = 0; // This one, from malloc.
> + if ((__size + __malloc_header_size) > __pagesize)
> + {
> + size_t __extra =
> + (__pagesize - ((__size + __malloc_header_size) % __pagesize))
> + % __pagesize;
> + __capacity += __extra / sizeof(_CharT);
> + __size = (__capacity + 1) * sizeof(_CharT) + sizeof(_Rep);
> + }
> + else if (__size > 128) // This magic constant is from stl_alloc.h.
> + {
> + size_t __extra =
> + (256 - ((__size + __malloc_header_size) % 256)) % 256;
> + __capacity += __extra / sizeof(_CharT);
> + __size = (__capacity + 1) * sizeof(_CharT) + sizeof(_Rep);
> + }
> +
The comments are not consistant with the code. It does not align to a
power of 2 for small sizes, does it? It seems to align to a boundary of
256 bytes (256, 512, 768, 1024, 1280, ...) for sizes larger than 128 and
not touch the size at all for sizes smaller or equal than 128.
--
Carlo Wood <carlo@alinoe.com>