18
голосов
5ответов
61868 просмотров

Creating array of objects on the stack and heap

Consider the following code: class myarray { int i; public: myarray(int a) : i(a){ } } How can you create an array of objects of myarray on the stack and how can you create an array of objects on the heap?

0
голосов
5ответов
600 просмотров

Using an abstract class to implement a stack of elements of the derived class

I have to do this for a basic C++ lecture at my university, so just to be clear: i would have used the STL if i was allowed to. The Problem: I have a class named "shape3d" from which i derived the classes "cube" and "sphere". Now i have to implement "shape3d_stack", which is meant be able of hol...

759
голосов
24ответов
407190 просмотров

How do you implement a Stack and a Queue in JavaScript?

What is the best way to implement a Stack and a Queue in JavaScript? I'm looking to do the shunting-yard algorithm and I'm going to need these data-structures.

2
голосов
3ответов
2229 просмотров

How to debug 'value of ESP was not saved across function call' error?

On rare occasions when my program exits, I get a "value of ESP has not been saved across a function call" error. The error is quite random and hard to reproduce. How do I debug this error (VC++ 2008)? How harsh it is, as it only occurs on shutdown? Is the error visible also in release mode?

1
голосов
3ответов
5571 просмотров

Pseudo Code for converting infix to postfix

I'm struggling getting the pseudo code for this. Scan string left to right for each char If operand add it to string Else if operator add to stack .... i'm struggling on how to handle ( )s

7
голосов
10ответов
2945 просмотров

Without using recursion how can a stack overflow exception be thrown?

Without using recursion how can a stack overflow exception be thrown?

1
голосов
3ответов
524 просмотров

return the value in a stack - C++

I have the following defined: Stack<ASTNode*>* data; The way the class is defined, if I do data->push() or data->pop(), I directly push onto the stack or pop off the stack. To get the node at the top of the stack I would do data->peek(). For testing purposes, I would like to pri...

2
голосов
5ответов
140 просмотров

Are there any cases when I would want to use an explicit stack over recursion?

Are there any cases when I would want to use an explicit stack data-structure in my algorithms, as opposed to doing recursion (which uses the call stack)? Is there any benefit to doing it one way over the other? I would think using the explicit data-structure would be more performant because it...

1
голосов
5ответов
276 просмотров

C++ inheritence for on-stack objects

I have a base class, Token. It has no implementation and as such acts as a marker interface. This is the type that will be used by callers. { Token t = startJob(jobId); // ... (tasks) // t falls out of scope, destructors are called } I have a derived class, LockToken. It wraps arou...

2
голосов
3ответов
134 просмотров

How to stack information from different variables?

Help! I have 2 variables from different datasets. Each variable has a different name in each dataset. However, the variables are delivering the same type of information for a single resspondent. Ex. Variables 1 & 2 for respondent #1 DR1IFDCD 11111000 32104950 51101010 81103080 11111000 ...

14
голосов
7ответов
8140 просмотров

Stack vs. Heap in .NET

In your actual programming experience, how did this knowledge of STACK and HEAP actually rescue you in real life? Any story from the trenches? Or is this concept good for filling up programming books and good for theory?

7
голосов
10ответов
1243 просмотров

Is it possible to create a linked list on the stack in C++?

I just started learning C++ couple of weeks ago. So now I have this school assignment problem that asks me to implement a linked-list without using "new" or anything to do with dynamically allocating memory (and cannot use any ADT from STL). The prof says that everything can be done on the stack,...

22
голосов
9ответов
14853 просмотров

Why would you ever want to allocate memory on the heap rather than the stack?

Possible Duplicate: When is it best to use a Stack instead of a Heap and vice versa? I've read a few of the other questions regarding the heap vs stack, but they seem to focus more on what the heap/stack do rather than why you would use them. It seems to me that stack allocation would a...

6
голосов
2ответов
3427 просмотров

Why does the caller have to clear the stack in the cdecl calling convention?

From: http://en.wikipedia.org/wiki/X86_calling_conventions push c push b push a call function_name add esp, 12 ;Stack clearing mov x, eax Why do we need to explicitly add 12 to ESP to clear the stack since the called function should have poped the parameters off the stack therefore restoring t...

0
голосов
2ответов
521 просмотров

Call stack corruption between boundaries

This feels a lot like finding a needle in a hay stack but here goes. I'm building a Windows Mobile 6.1 application. Specifically I'm trying to port over the OpenCV framework. Having successfully (doubtfully) compiled OpenCV for the ARM4I architecture, I'm trying it out in a simple hello world st...

1
голосов
5ответов
151 просмотров

Stack footprint of an array of types in C

I have the following function void DoSomething(int start[10], int end[10]) When I call it via void Do(void) { int start[10] = {1,2,3,4,5,6,7,8,9,0}; int end[10] = {1,2,3,4,5,6,7,8,9,0}; DoSomething(start,end); } do I put two pointers (8 byte all together) or two arrays each of 40 byte...

4
голосов
2ответов
419 просмотров

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 ver...

1
голосов
3ответов
1737 просмотров

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 ...

0
голосов
2ответов
3899 просмотров

"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

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 D...

52
голосов
9ответов
114884 просмотров

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?

9
голосов
8ответов
8331 просмотров

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 registe...

3
голосов
5ответов
4889 просмотров

java inheritance versus composition (implementing a stack)

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.uti...

-10
голосов
2ответов
371 просмотров

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 create...

0
голосов
2ответов
1364 просмотров

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 ...

2
голосов
2ответов
581 просмотров

C++ Stack Implementation

Hey all! Having a little trouble with my stack. Im trying to print each element that I've pushed onto the stack. Starting with the stack ctor we know that we have a fixed size for the array. So I allocate the items struct object to hold just that much space: stack::stack(int capacity) { it...

-1
голосов
5ответов
8686 просмотров

Stacks in Java with exceptions

Question : b) A Stack is a last-in first-out (LIFO) data structure. Write a Java class Stacklnt that stores a stack of integers using an alray as its private data structure. A Stacklnt has: A maximum size, which is set when a Stacklnt object is created. An exception should be thrown if the si...

1
голосов
3ответов
1251 просмотров

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 ...

681
голосов
5ответов
221083 просмотров

Why is Java Vector (and Stack) class considered obsolete or deprecated?

Why is Java Vector considered a legacy class, obsolete or deprecated? Isn't its use 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 CopyOnWrite...

2
голосов
6ответов
466 просмотров

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...

3
голосов
1ответов
1924 просмотров

LuaJit increase stack/heap size

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