alloca

Is it possible to predict a stack overflow in C on Linux?

There are certain conditions that can cause stack overflows on an x86 Linux system: struct my_big_object[HUGE_NUMBER] on the stack. Walking through it eventually causes SIGSEGV. The alloca() routine (like malloc(), but uses the stack, automatically frees itself, and also blows up with SIGSEGV if it's too big). Update: alloca() isn't f...

Resizing dynamic stack allocations in C++

Hi, I'm writing a small ray tracer using bounding volume hierarchies to accelerate ray tracing. Long story short, I have a binary tree and I might need to visit multiple leafs. Current I have a node with two children left and right, then during travel() if some condition, in this example intersect(), the children are visited: class Bo...

Why is alloca not considered good practice?

Alloca allocates memory from Stack rather then heap which is case in malloc. So, when I return from the routine the memory is freed. So, actually this solves my problem of freeing up of dynamically allocated memory . Freeing of memory allocated through malloc is a major headache and if somehow missed leads to all sorts memory problems. ...

alloca() of a templated array of types: how to do this?

I have a smart pointer type, and would like to construct an object that takes a pointer of that type and a count (dynamically calculated at runtime) and allocates enough memory from the stack to hold that many instances of the object the smart pointer points to. I can't seem to find quite the right syntax to achieve this; is it possible?...

What is the purpose of the %"alloca point" line which occurs in llvm code?

I've been looking at some LLVM assembly produced by llvm-gcc lately and I've noticed a recurring statement of which I'm not sure its purpose. For example, the following C program: int main(void) { void (*f)(void) = (0x21332); f(); } When compiled with "llvm-gcc -emit-llvm -S" will produce the following code (irrelevant parts re...

alloca and ObjectiveC Garbage Collector

In an objective C project with GC enabled, I am allocating an array of variable size on the stack like this: MaValue *myStack = alloca((sizeof(id) * someLength)); (The reason why I want to do this is not important:) Then, within a loop, I push and pop stuff on/from myStack. Some of the things I push onto the stack are new objects that...

Is alloca part of the C++ standard?

The title says it all. ...

How to GCC compile without _alloca ?

For some reason, I should use gcc to compile a C file, then link against Visual C++ 2008 project. (I used the current latest gcc version: cygwin gcc 4.3.4 20090804.) But there is one problem: gcc always allocate a big array with _alloca, and VC linker can't resolve the symbol __alloca. for example, int func() { int big[10240]; ...

What's the difference between alloca(n) and char x[n]?

What is the difference between void *bytes = alloca(size); and char bytes[size]; //Or to be more precise, char x[size]; void *bytes = x; ...where size is a variable whose value is unknown at compile-time. ...

In which cases is alloca() useful?

Why would you ever want to use alloca() when you could always allocate a fixed size buffer on the stack large enough to fit all uses? This is not a rhetorical question... ...

Is alloca completely replaceable?

I've read quite a few places that alloca is obsolete and should not be used and Variable Length Arrays should be used instead. My question is this: Is alloca completely replaceable by variable length arrays? In my particular instance I have something that looks like this: typedef struct { int *value; size_t size; } some_typ...