stack

Should I avoid recursion on the iPhone?

Should I avoid recursion with code that runs on the iPhone? Or put another way, does anyone know the max stack size on the iphone? ...

Thought experiment with __stdcall and corrupted stack (C++)

My mind was wandering today on the topic of function pointers, and I came up with the following scenario in my head: __stdcall int function (int) { return 0; } int main() { (*(int(*)(char*,char*))function)("thought", "experiment"); return 0; } AFAIK this code would corrupt the stack, so what types of issues could I be loo...

How to translate NASM "push byte" to GAS syntax?

Why I'm "porting" a NASM source to GAS and I found the following lines of code: push byte 0 push byte 37 GAS doesn't allow "push byte" or "pushb". How should I translate the above code to GAS syntax? Thanks ...

Stack corruption in C++

In C++, in which way the stack may get corrupted. One way I guess is to overwriting the stack variables by accessing an array beyond its boundaries. Is there any other way that it can get corrupted? ...

Why Must I Initialize All Fields in my C# struct with a Non-Default Constructor?

I would like to try this code: public struct Direction { private int _azimuth; public int Azimuth { get { return _azimuth; } set { _azimuth = value; } } public Direction(int azimuth) { Azimuth = azimuth } } But it fails on compilation, I understand that struct need to init all its fields...

stack, printing after the pop

i have a problem with my program. It should be program that recognize palindome through the stack. Everything works great, only thing that don't work is printing stacks(original and reversed) after the funcion is done. Here is my entire code, and the problem is at case d and e: #include <iostream> using namespace std; const int MAXST...

Call to _freea really necessary?

I am developping on Windows with DevStudio, in C/C++ unmanaged. 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 (I know about smart pointers and all those things. I have a very specific case of memory allocation I need to deal with), similar to the ...

C/C++ pattern to USE_HEAP or USE_STACK

Is there a way to define a macro (or something similar) that would allow objects to be allocated on the stack or on the heap, cleanly? eg. Current code: A a; a.someFunc(); The simplest suggestion might be the following, but as you can see below, it's not very clean to maintain 2 sets of code. #ifdef USE_STACK A a; a.someFunc();...

How to remove a stack item which is not on the top of the stack in C#

Hello, Unfortunately an item can only be removed from the stack by "pop". The stack has no "remove" method or something similar, but I have a stack (yes I need a stack!) from which I need to remove some elements between. Is there a trick to do this? ...

How to get a stack for exception.

Hi guys I have a Winform application (C#) which imports some functions from dll. Sometimes when running the application i get the following exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. I catch it in AppDomain.CurrentDomain.UnhandledE...

Escape analysis in Java

As far as I know the JVM uses escape analysis for some performance optimisations like lock coarsening and lock elision. I'm interested if there is a possibility for the JVM to decide that any particular object can be allocated on stack using escape analysis. Some resources make me think that I am right. Is there JVMs that actually do it...

Is it possible to know from which package a procedure has been called ?

Suppose that I have 2 packages : A and B. In package A, I call a procedure in package B. In procedure of packcage B, is it possible to know that procedure has been called from package A ? Thank you very much for these informations. It was very instructive. I appreciate. ...

How do I allocate a std::string on the stack using glibc's string implementation?

int main(void) { std::string foo("foo"); } My understanding is that the above code uses the default allocator to call new. So even though the std::string foo is allocated on the stack the internal buffer inside of foo is allocated on the heap. How can I create a string that is allocated entirely on the stack? ...

Thread-safe C++ stack

I'm new to C++ and am writing a multi-threaded app whereby different writers will be pushing objects onto a stack and readers pulling them off the stack (or at least pushing the pointer to an object).. Are there any structures built-into C++ which can handle this without adding locking code etc.? If not, what about the Boost libraries? ...

Is recursion generally considered to be an outdated method of traversing compared to using a stack?

I've been reading in a couple of places where people are opting to use a Stack instead of recursion. Is this because recursion is seen as being an outdated way to get-the-job-done or are both methods equally applicable in different contexts? ...

Is runtime stack kept in data segment of memory?

I'm very curious of the stack memory organization after I experiment what's going on in the background and obviously saw it's matching with tiny knowledge I acquired from books. Just wanted to check if what I've understood is correct. I have a fundamental program -- has 2 functions, first one is foo and the other is main (the entry poin...

Returning stack data in C; Does it unallocate correctly?

I was reviewing a friend's code and got into an interesting debate on how C/C++ allocates memory on the stack and manages its release. If I were to create an array of 10 objects in a function, but return said array, does it release when the function pops (hence making the given data invalid) or is it placed into the heap (which raises th...

What data structure will hold a bounded stack of items in LIFO ?

I'm looking for a data structure that is basically a bounded stack. If I declare that the stack can hold at most 3 items, and I push another item in, the oldest item is popped. ...

Stack capacity in C#

Hi All, Could one say me how much the stack capacity is in C#. I am trying to form 3D mesh closed object by using an array of 30.000 items. Thanks in advance George ARKIN ...

How to change processor stack?

Why doesn't this code print "test"? #include <stdio.h> #include <stdlib.h> void foo ( void ) { printf("test\n"); } __declspec(naked) void bar ( void ) { asm { push 0x000FFFFF call malloc pop ecx push eax add eax, 0x000EFFFF mov ecx, esp mov esp, eax push ecx call foo ...