Maybe I am missing something obvious, but if alloca() is simply allocating
from the stack, why not just replace these with stack buffers? For example:
void function1(void)
{
/* Define a buffer of max size, aligned to int, needed from the
stack. */
int buf[256];
function2(buf);
}
I'm sure people will answer "because you will waste stack space if you
don't
need the max size and perhaps blow your stack". I don't see that
argument
holding up, because if you had a worst case vorbis stream come in, it would
still blow up with alloca() if it had to use larger allocations. Plus,
defining a buffer off the stack takes no cycles. If we are worried about
large buffers blowing the stack, we probably shouldn't be using alloca()
either, we should use malloc/free.
Another idea is to pre-allocate a number of buffers of a large enough size
when your Vorbis_init() (not sure what the proper name is) type function is
done, then just re-use those each time to avoid the continual malloc/free.
P.S. - I throw my 2 cents in that Vorbis shouldn't use Malloc/Free(), but
instead ask for Malloc/Free() function pointers. These may be common in
desktop computing but they are absolutely shunned in some applications (e.g.
game consoles).
Thanks,
Dave.
-----Original Message-----
From: Chris Hanson [mailto:cmh@bDistributed.com]
Sent: Thursday, November 16, 2000 4:42 PM
To: vorbis-dev@xiph.org
Subject: Re: [vorbis-dev] BeOS on PPC compile, thread question.
At 8:21 AM +0100 11/16/00, Segher Boessenkool wrote:>And replacing the alloca()'s with malloc()/free() pairs _could_ be
>useful. (1st for people without alloca() (who cares about-em anyway), and
>2nd for people who are concerned about performance. I'll test if it
makes
>a speed difference.)
I think moving from alloca to malloc and free is a good idea because
alloca is not part of ANSI C and (to my knowledge) cannot be portably
implemented in ANSI C.
-- Chris
--- >8 ----
List archives: http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to
'vorbis-dev-request@xiph.org'
containing only the word 'unsubscribe' in the body. No subject is
needed.
Unsubscribe messages sent to the list will be ignored/filtered.