This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [RFC] Calling realloc vs. mallo/memcpy/free and _IO_vasprintf.
- From: Siddhesh Poyarekar <sid at reserved-bit dot com>
- To: Carlos O'Donell <carlos at redhat dot com>
- Cc: GNU C Library <libc-alpha at sourceware dot org>
- Date: Fri, 27 Nov 2015 11:13:46 +0530
- Subject: Re: [RFC] Calling realloc vs. mallo/memcpy/free and _IO_vasprintf.
- Authentication-results: sourceware.org; auth=none
- References: <5657C135 dot 1090807 at redhat dot com> <20151127031433 dot GA5012 at devel dot intra dot reserved-bit dot com> <5657EC65 dot 6090001 at redhat dot com>
On Fri, Nov 27, 2015 at 12:38:45AM -0500, Carlos O'Donell wrote:
> I still don't see how realloc is going to be slower since it's just
> one call, and there *might* be enough space in this chunk or the next
> to grow by one byte and that avoids the memcpy.
Agreed, in fact even in the mremap case you mentioned, the
malloc+memcpy+free ought to be slower because you end up calling two
syscalls (mmap followed by munmap) instead of just mremap in case of
realloc. I don't think there is a situation where realloc calls
mremap and the malloc+memcpy+free combination allocates on the heap.
Siddhesh