Fergus Henderson <fjh@cs.mu.oz.au> wrote,
On 04-Dec-2000, Marcin 'Qrczak' Kowalczyk <qrczak@knm.org.pl> wrote:
Mon, 4 Dec 2000 04:15:28 -0800, Simon Marlow <simonmar@microsoft.com> pisze:
Ok, so the malloc/free is the most expensive part. I'm moderately surprised:) Perhaps we could do a better job, but we'll never do better than ByteArrays as long as the bracket is required.
BTW, withCString in my implementation which handles charsets does not use alloca but malloc. It's because we don't know the length of the resulting char[] until we convert it, so we cannot preallocate it. We must guess an initial size and realloc the array as needed.
I don't know the details of withCString, so this might not be applicable, but an alternative that is likely to be more efficient is to use a static or alloca()'ed buffer for the initial try, and if it doesn't fit then switch to using malloc()/realloc(). At the end, you can check whether the final buffer pointer is equal to the original fixed-size static or alloca()'ed buffer, and only free it if it is not. Or you can keep a separate boolean flag.
Would have to be alloca'ed; otherwise, Concurrent would kill us. Manuel