Vadym Stetsyak wrote:
Hello, muchan!
have a look at stackalloc keyword, but beware this is unsafe mode.
It's interesting, that it's possible but declared as "unsafe"...
In this wording, all my C++ programing was in unsafe mode. :)
Everybody now a days seems to see pointer as an evil, but in C++,
often declaring a alias (reference) of the content of pointer,
it can be used just like normal variable.
If I could do something like this:
unsafe void func()
{
Obj *op = stackalloc Obj;
Obj &o = *op; // o as alias to the pointee of op
// ... using o as the stack allocated object ...
} // at the end of scope it disappears from stack
This is equivalent to my C++ way of writing auto variable of the
function scope... In C++, using stack allocated variables feels
safer than memory managiment with calling "new".
But GC way looks like "just calling new, and don't worry about it".
Thank you very much.
muchan