Alloca is a function to allocate dynamically memory on the Stack in C. Such memory will be automatically deallocated when leaving the function.
Questions tagged [alloca]
87 questions
0
votes
4 answers
What does alloca(0) do and return on various platforms?
Does alloca() returns NULL if the size given is 0?
A quick search reveals that alloca(0) force garbage collection in some cases! but I am mostly interested by return value.
thanks

elmarco
- 31,633
- 21
- 64
- 68
0
votes
1 answer
How did alloca() interact with other stack allocation?
Let's start from a simple example of stack allocation:
void f() {
int a, b;
...
}
If I understand correctly. Then address of a and b has a fixed offset from stack base, namely the register ebp. That's the how compiler find them if we need…

Peter Wu
- 193
- 6
0
votes
0 answers
Fragmentation-Does Anyone know what the alignment of _alloca() is?
So I'm using Windows 10/ 32-bit OS and the compiler is Visual Studio 2022
This is the Code:
(note this code is meant only for learning)
#include
#include
int main() {
int64_t p = (int64_t)_alloca(16);
int64_t o =…

Coffee
- 13
- 3
0
votes
1 answer
What happens to members of a stack-allocated class put down with placement new on scope end?
I have this (compiling) code:
#include
#include
class Base {
std::vector handles_;
public:
Base(Base* handle) : handles_( {handle} ) { };
};
class A : public Base {
using Base::Base;
};
class B : public…

glades
- 3,778
- 1
- 12
- 34
0
votes
1 answer
Allocating structs of arbitrary constant size on the stack
I've written a small working plugin server. The plugins are implemented using .so shared objects, which are manually loaded during runtime in the "server" by calls to dlopen (header ).
All of the shared object plugins have the same…

ljleb
- 182
- 1
- 14
0
votes
6 answers
returning alloca pointer
Does this code return an invalid reference to a variable allocated on the stack? Or what:
void *f(size_t sz) {
return alloca(sz);
}
Or is it a special case that is handled by the alloca implementation / compiler support like f(alloca(size),…

user318904
- 2,968
- 4
- 28
- 37
0
votes
2 answers
How to use alloca to allocate C function pointers?
C is a mystery all the time!
I am implementing a work-crew thread execution model in which I am trying to use alloca as a faster memory allocation option. I have a strange segmentation fault while trying to execute code via function pointers stored…

nandu
- 2,563
- 2
- 16
- 14
0
votes
1 answer
How do I use _malloca instead of _alloca in Win32 C++ project?
I'm updating an old C++ DLL project. For one of the exported functions there's
BSTR __stdcall j2cs( const long lJulian, int bDMY, BSTR sDelim ) {
USES_CONVERSION;
int iDay, iMonth;
long lYear;
char chDate[20];
char chInt[10];
…

bugmagnet
- 7,631
- 8
- 69
- 131
0
votes
0 answers
How to get data stored in memory pointed to by an llvm pointer
I am building a lifter that translates armv7m assembly instructions into llvm IR. A sample of my C++ code is:
IRBuilder<> builder(TheContext); //line 0
llvm::ConstantInt* I_0 = llvm::ConstantInt::get(TheContext, llvm::APInt(/nbits/32, 0, true));…

hany erfan
- 95
- 7
0
votes
2 answers
Performance of alloca
I'm using alloca a lot these days, to allocate temporary buffers. In my application (signal processing) this is a common need.
The question is:
When allocating multiple arrays, is it better (performance-wise) to use alloca just once?
Like…

mrzacek mrzacek
- 308
- 2
- 12
0
votes
1 answer
calling alloca( ) from another function call parameter?
Why calling alloc( ) as a parameter to another function call like this func(x, alloca(size), z); is considered wrong According to a book called the linux programming interface
This is because the stack space allocated by alloca() would appear in…

KMG
- 1,433
- 1
- 8
- 19
0
votes
1 answer
Lifetime of temporary with assignment operator to check and align alloca()
In the process of writing some testing and analysis of a large code base, I have to replace thousands of calls to alloca() with my own method. On my target platform alloca() fails if the number is zero, so we want to assert that is the case. We also…

Steven
- 619
- 5
- 24
0
votes
1 answer
C sprintf function that uses malloc or the stack
I've heard there is a version of sprintf(), possibly a GNU/gcc extension which either allocates its own buffer which I must free() or perhaps works using the stack like alloca().
Either method is fine for me. Can anyone tell me what function I was…

hippietrail
- 15,848
- 18
- 99
- 158
0
votes
3 answers
Does alloca() return memory if an exception is thrown?
I'm maintaining a legacy C++ application that seems to have a slow memory leak. I've managed to "fix" the memory leak by ensuring that the current configuration no longer throws any exceptions and I can also trigger the leak and scale it by…

kutuzof
- 660
- 1
- 7
- 22
0
votes
1 answer
alloca instead of local variable in alsa
I was using a sample C ALSA program as reference and ran along the following piece of code:
...
snd_ctl_event_t *event;
snd_ctl_event_alloca(&event);
...
Based on the ALSA source code, snd_ctl_event_alloca is a macro that calls __snd_alloca which…

sshashank124
- 31,495
- 9
- 67
- 76