Alex Rivera | Logout

Call to _freea really necessary?

Asked 2009-04-09T15:59:38.913
9

I am developing on Windows in C/C++ unmanaged with DevStudio.

I want to allocate some memory on the stack instead of the heap, because I don't want to have to deal with releasing that memory manually, similar to the use of A2W() and W2A() macros.

  • I know about smart pointers and all those things. I have a very specific case of memory allocation I need to deal with.

_alloca does that, but it is deprecated. It is suggested to use _malloca instead. But _malloca documentation says that a call to _freea is mandatory for each call to _malloca. It then defeats my purpose to use _malloca, I will use malloc() or new instead.

Anybody knows if I can get away with not calling _freea without leaking, and what the impacts are internally?

Otherwise, I will end-up just using the deprecated _alloca function.

Edit
Report

1 Answer

1

To allocate memory on the stack, simply declare a variable of the appropriate type and size.

answered 2009-04-09T16:01:19.317

Your Answer