what is _alloca()?
what is _alloca()?
I was trying to add some c++ to my kernel and got a linker error for _alloca so what is it, the parameters, and is there a dealloca because i used my generic sbrk() as alloca but it didn't give me an error and i have no dealloc
Re:what is _alloca()?
alloca should allocate memory on the stack, so that when the function returns the memory is automatically freed.
Now, the question of how thats done is not something I can answer. Its usually compiler magic.
Now, the question of how thats done is not something I can answer. Its usually compiler magic.
Re:what is _alloca()?
It's in the FAQ
How kernel, compiler, and C library work together (near the bottom)
It'll appear if you have a function with more than 4KB of local variables, or (possibly) if you have a local variable which doesn't have a constant size (e.g. an array with a variable sized number of elements).
You might be able to find a proper implementation (for GCC) in libgcc, but I can't find it on the GCC website any more... ???
How kernel, compiler, and C library work together (near the bottom)
It'll appear if you have a function with more than 4KB of local variables, or (possibly) if you have a local variable which doesn't have a constant size (e.g. an array with a variable sized number of elements).
You might be able to find a proper implementation (for GCC) in libgcc, but I can't find it on the GCC website any more... ???
Re:what is _alloca()?
I understand what it does now but how the crap would you make it and how is the memory automatically freed at the exit of a function without calling another function to free
btw
btw
so is there anyway to avoid using itThe alloca function is machine and compiler dependent. On many systems its implementation is buggy. Its use is discouraged.
- Colonel Kernel
- Member
- Posts: 1437
- Joined: Tue Oct 17, 2006 6:06 pm
- Location: Vancouver, BC, Canada
- Contact:
Re:what is _alloca()?
AFAIK, you would implement it on x86 just by subtracting a certain amount from esp. When the function returns, it will restore the stack pointer of the calling frame, thus "freeing" the alloca'd memory just like local variables are freed.
Top three reasons why my OS project died:
- Too much overtime at work
- Got married
- My brain got stuck in an infinite loop while trying to design the memory manager
Re:what is _alloca()?
A lot of effort has gone into the FAQ. Many questions are answered there - including those about alloca().Jordan3 wrote: so is there anyway to avoid using it
Every good solution is obvious once you've found it.