stack

segmentation fault on Unix - possible stack corruption

hello, i'm looking at a core from a process running in Unix. Usually I can work my around and root into the backtrace to try identify a memory issue. In this case, I'm not sure how to proceed. Firstly the backtrace only gives 3 frames where I would expect alot more. For those frames, all the function parameters presented appears to co...

Proper stack and heap usage in C++?

I've been programming for a while but It's been mostly Java and C#. I've never actually had to manage memory on my own. I recently began programming in C++ and I'm a little confused as to when I should store things on the stack and when to store them on the heap. My understanding is that variables which are accessed very frequently shou...

Why does the Mac ABI require 16-byte stack alignment for x86-32?

I can understand this requirement for the old PPC RISC systems and even for x86-64, but for the old tried-and-true x86? In this case, the stack needs to be aligned on 4 byte boundaries only. Yes, some of the MMX/SSE instructions require 16byte alignments, but if that is a requirement of the callee, then it should ensure the alignments ar...

How do I push An instance of a c++ class wrapped with swig onto a lua stack?

I have a class that is wrapped with swig, and registered with lua. I can create an instance of this class in a lua script, and it all works fine. But say I have an instance of a class made in my c++ code with a call to new X, and I have la lua_state L with a function in it that I want to call, which accepts one argument, an instance of ...

How to identify if an object should be on the stack or not?

I was looking for a rule of thumb for allocating objects on stack or heap in C++. I have found many discussions here on SO. Many people said, it's about the lifetime of an object. If you need more lifetime than the scope of the function, put it in the heap. That makes perfect sense. But what made me confusing is, many people said, allo...

Stack unwinding in case of structured exceptions

This question provides more clarity on the problem described here. I did some more investigation and found that the stack unwinding is not happening in the following piece of code: class One { public: int x ; }; class Wrapper { public: Wrapper(CString csText):mcsText(csText) { CString csTempText; csTempText.Format...

64bit Thread Overhead

What's the overhead of a thread on 64bit windows? I believe it was 1mb of userspace for the stack and a smaller amount of kernel space in 32bit. Thanks ...

Design a stack that can also dequeue in O(1) amortized time?

I have an abstract data type that can be viewed as a list stored left to right, with the following possible operations: Push: add a new item to the left end of the list Pop: remove the item on the left end of the list Pull: remove the item on the right end of the list Implement this using three stacks and constant additional memory, so ...

Stack Operation in Javascript

I am implementing a stack in JavaScript. Consider: Stack{0,1,2,3} Top:0 Now the user pops the value of 2: Stack{0,1,3} Top:0 Is this an acceptable behavior for a stack? I am rolling my own stack, but is there any built in code that would do this for me? My Code: function Stack() //Creating Stack Object { // Create...

Should a list of objects be stored on the heap or stack?

I have an object(A) which has a list composed of objects (B). The objects in the list(B) are pointers, but should the list itself be a pointer? I'm migrating from Java to C++ and still haven't gotten fully accustomed to the stack/heap. The list will not be passed outside of class A, only the elements in the list. Is it good practice to a...

Building a stack in Entity Framework

One type of entity in my model (let's call it E1) needs to be able to treat its relationship with another entity type (E2) as a stack. Reciprocally, that other entity needs to be able to see all related entities of the first type where the E2 is at the top of the stack, and separately every case where the E2 is within a stack for an E1. ...

What is the direction of stack growth in most modern systems?

I am preparing some training materials in C and I want my examples to fit the typical stack model. What direction does a C stack grow in Linux, Windows, Mac OSX (PPC and x86), Solaris, and most recent Unixes? ...

Creating a Menu Stack

Hello, I'm trying to create a menu system that allows you to go backward and forward while returning the final selected data to the calling method. Take for example a orderFood() method displays a menu of choices of types of food that can be ordered. If someone selects seafood a seafood() method would run and query what types of seafo...

Strange stack behavior in C

I'm worried that I am misunderstanding something about stack behavior in C. Suppose that I have the following code: int main (int argc, const char * argv[]) { int a = 20, b = 25; { int temp1; printf("&temp1 is %ld\n" , &temp1); } { int temp2; printf("&temp2 is %ld\n" , &temp2); } return 0; ...

Visual Studio 2008 - show heap

Hi Is it possible to view the heap and stack during debugging? ...

C# Indexer memory question

Hi I have the following code inside main method: List<Rectangle> rects = new List<Rectangle>(); for (int i = 0; i < 5; i++) { rects.Add(new Rectangle(1, 1, 1, 1)); } foreach (Rectangle item in rects) { Console.WriteLine(item); } rects[1].Inflate(100, 100); foreach (Rectangle item in rects) { Console.WriteLine(item); } ...

How do I create an array in C++ which is on the heap instead of the stack?

I have a very large array which must be 262144 elements in length (and potentially much larger in future). I have tried allocating the array on the stack like so: #define SIZE 262144 int myArray[SIZE]; However, it appears that when I try and add elements past a certain point, the values are different when I try to access them. I under...

Differentiate Between Pointer and Reference at Run Time ANSI C++

How does one differentiate between pointers and references at runtime? For example, if I wanted to free a pointer of a data type without knowing whether it were a pointer or not how would I do so? Is there any method to tell if a variable has been allocated on the stack or through malloc()? void destInt(int* var) { free(var); } int...

About C/C++ stack allocation

While studying C++ (and C) I had some particular doubts regarding the working of stack allocation, that I can't find a solution to: Does stack allocation call malloc/free functions implicitly? If not; how does it assure there is no conflict between stack allocation and heap allocation? If yes; does stack allocation in C++ implicitly ca...

What is the difference among heap spraying, heap overflow, heap overrun?

What is the difference among heap spraying, heap overflow, heap overrun? Can those terms be replaced with buffer spraying, buffer overflow, buffer overrun? Do they have the same definitions as well? ...