Should Wine use alloca or not?
tntjpgriff at tsnxt.co.uk
Mon Feb 12 09:04:57 CST 2001
> Yes, LocalAlloc is for 16 bit source code compabillity and shouldn't be
> used by Win32 code.
Oops, ok, HeapAlloc then :-)
> So perhaps we should debate whether we should use alloca or not.
I'll throw my reasons in:
-alloca with unknown length argument resolves to a function call, so isn't as
effiecient as just moving the stack pointer.
-it does not fail gracefully, it segfaults (according to the gcc docs).
-Its not available on all platforms
-Over/underwriting stack memory leads to very hard to debug problems
(corrupted stack). Dynamic memory may catch this with page protection.
-It may not play well with exceptions, and even when it does, it slows them
down horribly (lists of stack allocated memory must be kept in order to
unwind the stack correctly). Where we may be mixing c++ and windows style
exceptions this could be especially bothersome.
-Its easy to get it wrong when memory is allocated in a code block, because
the standard says the memory can be freed at the end of the block or the
function. Its easy to forget this and use the memory outside of the block,
which will fail on some implementations.
Thats why I say 'style-wise' I don't use it (I do have real reasons). There
are too many potential problems lurking there for my liking. I see it as an
optimisation, if required it should be added later, commented and only once
the need to use it has been demonstrated by profiling.
Just my 2p worth...
"Don't wait for the seas to part, or messiahs to come,
Dont you sit around and waste this chance ..." -Live
tntjpgriff at tsnxt.co.uk , jon_p_griffiths at yahoo.com
More information about the wine-devel