stack

What Happens When Stack and Heap Collide

Hi, I am curious to know what happens when the stack and the heap collide. If anybody has encountered this, please could they explain the scenario. Thanks in advance. ...

Are const arrays declared within a function stored on the stack?

if this was declared within a function, would it be declared on the stack? (it being const is what makes me wonder) void someFunction() { const unsigned int actions[8] = { e1, e2, etc... }; } ...

How can I write an exception stack trace in erlang after catching it?

Suppose I have something like this : try code_that_fails() catch _:_ -> ..... How do I print the stacktrace in the catch block? That block catches all exceptions, but I don't know how to print the stack... Can you help me? ...

Stack Frame Question: Java vs C++

Q1. In Java, all objects, arrays and class variables are stored on the heap? Is the same true for C++? Is data segment a part of Heap? What about the following code in C++? class MyClass{ private: static int counter; static int number; }; MyClass::number = 100; Q2. As far as my understanding goes, variab...

C++ stack and scope

I tried this code on Visual C++ 2008 and it shows that A and B don't have the same address. int main() { { int A; printf("%p\n", &A); } int B; printf("%p\n", &B); } But since A doesn't exist anymore when B gets defined, it seems to me that the same stack location could be reused... I don't understand why th...

Stack smashing detected

I am executing my a.out file .After execution the program runs for some time then exits with the message: ** stack smashing detected : ./a.out terminated ======= Backtrace: ========= */lib/tls/i686/cmov/libc.so.6(__fortify_fail+0x48)Aborted* What could be the possible reasons for this and how do I rectify it? ...

What's the size of a reference on the CLR

I was (purely out of curiosity) trying to find out what the size of an actual reference is when an allocation is made on the stack. After reading this I still don't know (this answers it only for value types or type definitions), and I still cannot seem to find it anywhere. So basically imagine a class as follows class A { string ...

LuaJit increase stack/heap size

Hi, I keep getting a out of memory error in LuaJit. How do I increase the stack or heap size? Thanks ...

What is the mechanism through which destructors are called for stack-assigned objects?

How does C++ ensure that destructors are called for stack assigned objects? What happens to the destructor function (or a pointer to it) when I assign dynamic memory as follows: class MyClass { public: ~MyClass() { std::cout<<"Destructor called."<<std::endl; } MyClass() { std::cout<<"Constructor called."<<std::endl...

Why Java Vector class is considered obsolete or deprecated?

Why Java Vector is considered a legacy class, obsolete or deprecated? Its use isn't valid when working with concurrency? And if I don't want to manually synchronize objects and just want to use a thread-safe collection without needing to make fresh copies of the underlying array (as CopyOnWriteArrayList does), then it is fine to use Ve...

How can I chronologically stack different height divs in two columns?

I have two columns and want to stack divs of different heights in order of appearance. The divs are dynamically created. I have tried to do this by floating the first story to the left and the second to the right, but their still seem to be some anomalies. Have a look at this demo, it should explain it all. http://dl.getdropbox.com/...

State Machine Implementation

I'm looking for some general Optimization Correctness Extensibility advice on my current C++ Hierarchical State Machine implementation. Sample variable isMicOn = false variable areSpeakersOn = false variable stream = false state recording { //override block for state recording isMicOn = true //here, only isMicOn is...

Which object is created in which part of memory?

public class Order { static Customer cust = new Customer(); string sEmpty = ""; public static void main(String args[]) { int iTotal = 10; string sProductName = "Salt"; Ship shp = new Ship(); } } At the above code, which object and reference is created in the which part of memory? (I mean Hea...

java inheritance versus composition (implementing a stack)

Hey everyone, I am trying to implement a Stack in java (using the list interface: Interface List). I want to implement it two different ways: using composition and inheritance. For inheritance, so far I have: import java.util.Collection; import java.util.Iterator; import java.util.List; import java.util.ListIterator; public cl...

Is there a programmatic way to check stack corruption

I am working with a multithreaded embedded application. Each thread is allocated stack sizes based on its functionality. Recently we found that one of the thread corrupted the stack by defining a array of local variables that was more than the stack size. The OS is uItron. My solution, I registered a timer for 10 mS, and this timer will...

What is a stack pointer used for in microprocessors?

I am preparing for a microprocessor exam. If the use of a program counter is to hold the address of the next instruction, what is use of stack pointer? ...

"Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call" after successful C# callback from the C++ code of GameSpy lib.

I'm making a C# application which is using GameSpy C code (the GP part). The C code is calling a callback (which is C# code) succesfully, but I get this error "Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call" right after the callback is done. I've made a DLL out of C code, BTW like this: /...

Non-recursive post order traversal

Hi, I saw the following post order traversal algorithm in some website... it seems to be correct. I just want to verify that this algorithm works correctly — is this algorithm correct for post order traversal without recursion? void postOrderTraversal(Tree *root) { node * previous = null; node * s = null; push(root); w...

Declaring array size of auto variable from input argument

I have been playing around with the stack on a Ubuntu 9.04 system running gcc 4.3.3 with the randomize_va_space kernel variable set to 0(/proc/sys/kernel/randomize_va_space) If I declare an auto variable in a function which is an array with its size being determined by the input then how is the array allocated on the stack? The functio...

When happens to value types when they're removed from a collection?

Suppose I have some simple struct like this: public struct WeightedInt { public int value; public double weight; } Then let's say I have a collection of instances of this structure: List<WeightedInt> weightedInts = new List<WeightedInt>(); As I understand value types versus reference types, value types are allocated on the ...