Quote:
Originally Posted by
shamrock
Use of alloca is discouraged because it is system dependent...
How system dependent? Linux has it, Windows has it, IRIX has it, Solaris has it, BSD has it, OSX has it, HPUX seems to have it... The only platform I can think of offhand that I can't verify is AIX, and that's a "maybe", not a "no". It seems too useful, even internally, for vendors to
not implement... I will admit that some
embedded platforms implement it
badly(a severe error on systems with no malloc!), allowing alloca'd memory to be overwritten by further function calls, but I'm not aware of an embedded platform with threading. I suspect the kind of stack management needed for threading also lets alloca exist.
Quote:
also the memory returned cant be passed to other functions since it is freed as soon as the function that calls alloca exits.
You can certainly pass it to other functions if you keep in mind its scope, the exact same way you can pass references to stack variables if you keep in mind their scope. For a thread, it will be valid as long as the thread exists.
Quote:
With alloca portability is the biggest concern if developing apps for different platforms.
Please note any platforms you know of that don't have alloca.