Questions tagged [alloca]

Alloca is a function to allocate dynamically memory on the Stack in C. Such memory will be automatically deallocated when leaving the function.

87 questions
0
votes
0 answers

Expression-local variable

I have tried to come up (just as an experiment, nothing serious) with a macro that wraps alloca in a more object-oriented way, using special "constructor" that returns the size the instance will need together with a pointer to a function that should…
IS4
  • 11,945
  • 2
  • 47
  • 86
0
votes
1 answer

Using alloca- with c2hs

Consider from the c2hs documentation that this: {#fun notebook_query_tab_label_packing as ^ `(NotebookClass nb, WidgetClass cld)' => {notebook `nb' , widget `cld' , alloca- `Bool' peekBool*, alloca- …
George
  • 6,927
  • 4
  • 34
  • 67
0
votes
0 answers

alloca() with VLAs and C++

The only alloca() replacement for C++ I have found on the Internet looks something like this: template void alloca_(::std::size_t const n, F&& f) noexcept(noexcept(f({}))) { alignas(::std::max_align_t) char p[n]; f(p); } But,…
user1095108
  • 14,119
  • 9
  • 58
  • 116
0
votes
0 answers

Is it safe to alloca the buffer for regerror?

regerror returns the number of bytes that are needed to store the error message. Since the application I'm working with isn't going "deep" in the stack (i.e. no deeply nested function calls) I was thinking about using alloca (which the application…
Daniel Jour
  • 15,896
  • 2
  • 36
  • 63
0
votes
1 answer

when _malloca can not allocate memory on heap

When alloca can't allocate memory on heap it creates structured exception stackoverflow and program halt with Stackoverflow. Ok. But when _malloca can not allocate memory on heap it says nothing. I allocate great amount of memory and after that use…
Ivan Ivanov
  • 2,076
  • 16
  • 33
0
votes
1 answer

How to get the address literally allocated by allocaInstr in llvm?

I am trying to do some instrumentation over an ll file. One of the task I want to achieve is the following. Whenever I meet an AllocaInstr like: %1 = alloca i32 I want to instrument a function call __save_addr() after it as follows: %1 = alloca…
ZLW
  • 151
  • 9
0
votes
2 answers

Is this use of alloca() valid?

After using an std vector to hold my move list for my chess engine, I realised that because chess has an averaging factor of 35 (i.e. something like 35 legal moves from a typical position), the vector was resizing a lot, thereby negatively impacting…
0
votes
4 answers

Is it possible to write an _alloca-like function in C?

The function _alloca (alloca) allocates memory on the stack, which does not require "free". Is it possible to write a function that allocates on the stack in C? Another way of phrasing it: _alloca does it! Or is this not possible in C for other…
B. Nadolson
  • 2,988
  • 2
  • 20
  • 27
0
votes
1 answer

Undefined symbols for architecture x86_64: "_alloca"

I'm trying to make the project polyworld but get an error compiling qt_clust.o g++ -o bin/qt_clust .bld/qt_clust/tools/clustering/qt_clust.o -L/usr/lib -L/usr/local/lib -L/usr/include -lz -lgsl -lgslcblas -lgomp and get "_alloca", referenced from: …
crizCraig
  • 8,487
  • 6
  • 54
  • 53
0
votes
2 answers

c++ releasing "_alloca" ted memory from stack

I know that the behavior ot _alloca is to release the memory off the stack when you leave the function. Is there a way to release the memory earlier?
dmjalund
  • 285
  • 2
  • 9
0
votes
1 answer

Dynamically-Allocated Stack Memory with Class Scope

Several compilers support extensions to C++ whereby one can dynamically allocate memory on the stack. For instance, g++ supports alloca() as well as VLAs. All of these extensions come with the caveat that the dynamically-allocated memory is…
void-pointer
  • 14,247
  • 11
  • 43
  • 61
-1
votes
1 answer

Is there a way to explicitly manipulate variable data on stack in GNU C?

(GNU) C offers at least two mechanisms for manipulating variable data on stack - the first one is the alloca function and its relatives (e.g. strdupa), and the second is the "Variable Lenght Array" feature. The problem with alloca is that it doesn't…
Maciek Godek
  • 172
  • 12
1 2 3 4 5
6