FAQ Database Discussion Community


How can I avoid a stack overflow when Fortran RESHAPE produces a large, internal, temporary array?

stack,fortran,heap,stack-overflow,reshape
I have some Fortran code that calls RESHAPE to reorder a matrix such that the dimension that I am now about to loop over becomes the first varying dimension (Column-major order in Fortran). This has nothing to do with C/Fortran interoperability. Now the matrix is rather large and when I...

Unstacking a data frame

stack,reshape2,melt
I have a data frame which looks like this: d <- c("a", "b", "c", "a", "b", "c", "a", "b", "c") par <- c("a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9") df1 <- as.data.frame(cbind(id, par)) I would like it to look like this: a <- c("a1", "a4", "a7") b <-...

Codility : Brackets Determine whether a given string of parentheses is properly nested

java,stack,brackets
Problem description from codility : A string S consisting of N characters is considered to be properly nested if any of the following conditions is true: S is empty; S has the form "(U)" or "[U]" or "{U}" where U is a properly nested string; S has the form "VW"...

Copy Elements From Stack to Queue

java,stack,queue
I'm supposed to copy elements from a stack to a queue. I haven't been able to think of a way to keep the stack the way it is and still copy its elements to a queue. I ended up with this method which removes the elements completely from the stack...

trace stack external library eclipse

java,eclipse,debugging,stack,mpi
I imported mpi.jar library in Eclipse and everything works perfectly. I would like to trace the stack of my application but I don't know I to do it. For example, my app calls a method from mpi.jar library called send() and I would like to understand what send() does. I...

C++ int PriorityQueue using stack

c++,arrays,stack,priority-queue
Im just starting to learn C++ programming and for exercise i found this task. I have to write a PriorityQueue using dynamic, array based, integer stack. This is what i have got so far. #include <iostream> using namespace std; class PrioQueue { private: int *bottom_; int *top_; int size_; public:...

Why in C++ overwritingis is slower than writing?

c++,performance,stack,heap-memory
I have to run a piece of code that manages a video stream from camera. I am trying to boost it, and I realized a weird C++ behaviour. (I have to admit I am realizing I do not know C++) The first piece of code run faster than the seconds,...

Small Stack Size In Visual Studio [duplicate]

c++,visual-studio,stack
This question already has an answer here: why is stack memory size so limited? 7 answers Just curious, why is the default stack size in Visual Studio for C++ just 1MB? With modern computers, 1MB is extremely small. Is there a problem with changing my settings to something like...

Allocated on the heap or the stack? [closed]

c#,memory,stack,heap
I recently asked a question about StackOverflowExeptions and the explanations were very helpful! However, I wrote a method and tried to figure out where T cached is allocated (heap/stack): private Dictionary<Type, Component> _cachedComponents = new Dictionary<Type, Component>(); public T GetCachedComponent<T>() where T : Component { //Not yet sure if the...

Where exactly is this object being stored? (Swift)

function,swift,memory,stack,heap
Consider the following code: class Foo { } func foo() -> (Void -> Foo) { var foo = Foo() return { foo } } var fooGen = foo() Now whenever I call fooGen, I get my stored Foo instance. But where exactly is foo being stored? Is it inside the...

Using Stack for variable allocation mips

assembly,stack,mips
I am trying to convert c functions into mips assembly code as a practice. I was trying to allocate the space on stack for local variables & function arguments. But I get alignment errors at run time. I know that the memory should be aligned with appropriate data structure (i.e....

LC3 Stack Implementation

stack,lc3
I have a problem I'm trying to figure out: Write an LC-3 assembly language program that asks the user to input a string (the end of the input string is the enter key), and prints the words of this string in reverse order. For example, if the input string is...

Reuse thread struct after thread_join in C

c,multithreading,stack,pthreads
I have an array of thread variables on the stack, which the main thread later joins with. I have to run the same number of threads again later, and was wondering if I can still use the same array of thread structs to create new threads, or if the thread...

Whit is the stack size on Cygwin/Windows 64bit?

c,stack,size
i tried to search on the net but i didn't find anything about it. Only how to increase stack size and similar. I want to know the stack size on cygwin 64 bit for windows. I'm programming with C on netbeans and i tried to make a stack overflow to...

How to make a stack grow dynamically?

c++,class,memory,stack,heap
Here is a little program with my Stack class: #include <iostream> using namespace std; #include <iomanip> template <typename T> class Stack { private: T *stackPtr; int size; T top; public: Stack(int = 10); ~Stack(); bool push(const T ); bool pop(); void printStack(); }; int main() { Stack <int> myStack(5); cout...

How do process virtual machines implement callback support?

callback,stack,vm-implementation
Preamble: This question is asked as a VM implementor, looking to support native callbacks (more specifically wndProc). For Process VMs I mean for Smalltalk, Java, Python, etc. VMs are usually very careful of what gets into the stack. This is because during GC they will use the stack as a...

What does “taking operands immediately following the opcode” mean?

java,jvm,stack
I am reading the book Inside the Java 2 Virtual Machine and I can't understand what this means: The Java Virtual Machine is stack-based rather than register-based because its instructions take their operands from the operand stack rather than from registers. Instructions can also take operands from other places, such...

What is the advantage of dynamic memory control?

c++,memory,dynamic,stack,difference
For example, I want to make a stack. I can do it in that way, using the dynymic memory control, with new and delete opereations: #include <iostream> using namespace std; struct List { int x; List *Next,*Head; }; void Add(int x, List *&MyList) { List *temp=new List; temp->x=x; temp->Next=MyList->Head; MyList->Head=temp;...

Generic Constructor Issues in Stack Array Implementation?

java,generics,constructor,stack
I'm working on a generic stack implementation in Java and have run into a few issues with the constructor. The class Stack226Array implements Stack226, which was given to us. So, I have my constructor declared as follows: public void Stack226Array(int initialCapacity) { this.stack = (T[]) new Object[initialCapacity]; this.top = 0;...

Kernel - Scheduler : what happens when switching between process

process,linux-kernel,stack,kernel,scheduler
Context: I don't really understand how the kernel saves the state of a running code when it gets to exceed its time slice. I don't visualize what happens actually. Question: 1) Where is stored the current running code (and its stack ?) ? 2) When the kernel will "see" the...

How to check for existing activities when back button pressed

android,android-intent,android-activity,stack
Generally, when the back button is clicked, I call finish(), and I am taken back to the previous activity (which is my MenuActivity) : @Override public void onBackPressed() { finish(); } However, sometimes the there are no other activities running when the back button is clicked and the app simply...

Defining Stack dynamically in class constructor, which is private member

c++,dynamic,stack
Friends I defined a stack class, which makes stack of a structure, and an other class which uses stack (creating dynamically) like below struct A{ int a; ..... }; class stack{ private: int head,max; A* data; // pointer of structure 'A' public: stack(int length){ // constructor to allocate specified memory...

Why the errors?

c,pointers,stack
# include <stdio.h> # include <stdlib.h> #define MAX 1000 struct stack { int st[MAX]; int *top ; }; int main() { struct stack *s = malloc(sizeof(struct stack)); s->(*top) = -1; return 0; } I am writing a piece of code for stack implementation in C. This is a practice assignment....

Different performances in Go slices resize

go,stack,benchmarking,slice
I'm spending some time experimenting with Go's internals and I ended up writing my own implementation of a stack using slices. As correctly pointed out by a reddit user in this post and as outlined by another user in this SO answer Go already tries to optimise slices resize. Turns...

Adding 2 large numbers using stack?

c,stack
I'm currently learning C programming language (it's my very first programming language too). I'm now dealing with the problem that adding 2 large numbers using stack. I've written some codes to solve it but I'm facing some errors. Here is my code. Main program #include "stack.h" #include <string.h> int main(){...

Why does the Java.Util.Stack not pop last element in the loop?

java,collections,stack
I have a very Basic Question Stack<Integer> s=new Stack<integer>(); s.push(New Integer(1)); s.push(New Integer(2)); s.push(New Integer(3)); for(int i=0;i<s.size();i++){ System.out.println("i: "+i+" size:"+s.size()); System.out.print(s.pop()); if(s.size()>=1) System.out.print(" ->"); } This results in an output of 3->2-> And Not 3->2->1 Shouldn't the loop run thrice , Is the condition i < s.size() changing as the...

array based implementation of stack in C

c,arrays,stack
I'm referring to this source for array-based implementation of stacks. Somewhere on the page, it says, Dynamically-sized stack: Now, we will add one more choice to how we'll implement our stack. We want to be able to decide the maximum size of the stack at run-time (not compile-time). Thus, we...

Incomprehensible expression in Stack ADT implementation

c,stack
There is a stack ADT implementation below. In this implemantation, programmer has used linked list. struct Node { char *elem; struct Node *next; }; static struct Node *new_node(void *elem, int elem_size) { struct Node *n = malloc(sizeof(struct Node)); n->elem = malloc(elem_size); memcpy(n->elem, elem, elem_size); n->next = NULL; retrun n; }...

How many calls will be stored in stack?

java,recursion,stack,fibonacci
Could someone please explain how many calls will be stored in stack for the recursive method below and why? When is something stored in stack exactly? Apparently it is 49 calls, but I don't understand why. Thanks. public static long fib( int n ){ // n = 50 if( n...

Most efficient way to implement stack and queue together?

algorithm,data-structures,stack,queue
What would be the most appropriate way to implement a stack and a queue together efficiently, in a single data structure. The number of elements is infinite. The retrieval and insertion should both happen in constant time.

popStack pops out data that I didn't push (stack adt)

c,data-structures,stack,adt
This is a code to push 0 and 1 and pop 1 and 0 again. However, it pops 2 and 2. I can't seem to figure out why. #include <stdio.h> #include <stdlib.h> #include <stdbool.h> #include "stackADT.h" int main (void) { STACK* stack; int data; stack = createStack (); int i;...

How does Linux remember its Kernel Stack Pointer?

linux,linux-kernel,stack,kernel,interrupt
I know that there are two types of stack in Linux : user stack for each user threads and Kernel Stack for kernel threads (but 1 process). The interruptions, more precisely, the interruption procedures, are the bridges between this two modes, kernel (0) and user (3). The interrupt vector table...

Which smart pointer to use in Stack implementation?

c++,stack,smart-pointers
From what I've understood correctly: scoped_ptr: no overhead, cannot be copied or moved. unique_ptr: no overhead, cannot be copied, can be moved. shared_ptr: some overhead (reference counting), can be copied. Having said that, if there is a need for several owners, then shared_ptr should be used. Now, in this program...

Print Stack Trace intefering with Print Line

java,exception,stack,trace
Sorry if this is a nooby question. When using System.out.println() followed by printing a stack trace, the two seem to overlap and interfere with eachother. This code: System.out.println("Multiple definitions for " + analyzer.name + ":"); for (String name : resultNames) { System.out.println('\t' + name); } throw new RuntimeException("Multiple class definitions...

C++ Stack implementation unexpected output

c++,pointers,object,stack
#include <iostream> using namespace std; /*Stack last in first out algorithm pop, push, print*/ class Node{ private: int a; public: Node *next; Node(){ next = NULL; }; Node(int b){ int a = b; next = NULL; } int getValue(); }; int Node::getValue(){ return a; } class Stack{ Node *top; public:...

Evaluate postfix expression

java,linked-list,stack
I have to write a program that converts infix to postfix and then evaluates the postfix expression. I have done the conversion part. However I am a bit confused about the evaluating part. The method that evaluates the expression takes a Linked List representation of the postfix expression. That's making...

How to find maximum value in rasterbrick?

r,stack,raster
I know there is a similar question but it is not in rasterbrick. I would like to find the maximum value in this raster brick, I tried which.max but I don't understand the input. I would like to know what is the maximum value, and also get a list of...

Getting “symbols not found” errors implementing a Stack as Linked List using templates

c++,templates,linked-list,stack
I'm trying to create a stack using a linked list. I've already got it working using integers, but now I want to implement Templates to it. There are no errors detected before compile, but after running I get these errors: *Undefined symbols for architecture x86_84: "Stack::printStack()", referenced from: _main in...

How to share data (array) between recursive calls?

java,recursion,stack,heap
I know Each recursive call has its own copy of data stored in its reserved area in the stack. However how can a recursive call access shared public static data declared in the main for example ? Is this data in the stack or heap ?...

Performance difference between arrays, stacks and queues

java,arrays,stack,queue
What is the search performance of arrays, stacks and queues? I think that arrays are the quickest and most straightforward, because I can access any element immediately by calling it using its index. Is this correct? What about the performance of stacks and queues? How do they compare?...

C++ array based stack implementation throwing errors

c++,stack
I'm kinda new to C++, so this must be something trivial. I've implemented a stack using an array but can't seem to call from main. Here's my main( ). #include <iostream> #include <cstdlib> #include "stack.cpp" int main(){ myStack = new Stack(10); return 0; } Here's my .hpp #include <string> class...

Where do I delete objects? I'm out of scope

c++,object,delete,stack
From what I have gathered it's imperative to delete anything that has been allocated with new. Having said that I feel I'm out of scope in my program to be able to access & delete those objects. GameStateStack.h #include <iostream> class node { public: std::string gameState; node * nextGameState; };...

What is a kernel stack used for?

process,operating-system,stack,kernel,context-switch
The following is a description I read of a context switch between process A and process B. I don't understand what a kernel stack is used for. There is suppose to be a per process kernel stack. And the description I am reading speaks of saving registers of A onto...

call function with float in assembly x86 x87

c,assembly,x86,stack,x87
I'm new to assembly programming and, as a part of a bigger program I have need to pass floating point values to another C-function. I have a call from my test program to my assembly function, that only pushes the parameters on the right stack, and calls a second C...

What happens when I move %esp to %ebp?

assembly,stack
I know this is a pretty basic question, but here it goes: I am starting to learn Assembler, and I'm trying to understand how the stack works. At first, when I pass a value to an assembler function, I'd access it like this: movl 4(%esp),%eax # first parameter movl 8(%esp),%ebx...

Understanding Stack, Heap and Memory Management

c++,pointers,memory-management,stack,heap
int *ip = new int[10]; for (int i = 0; i<10; i++) *(ip+i) = i; myfun(ip); // assume that myfun takes an argument of // type int* and returns no result delete [] ip; The above code is a small segment of a test function that I am trying to...

What is exactly the d__Xa part in stack in async code?

windows-runtime,stack,async-await
When I have this row in a stack of an exception: WebApiAccessService.<GetStudentKey>d__14a.MoveNext() What is the "d__14a"? Is it something which could tell me (without symbols) some offset from the start of the method?...

Which stack is used by Interrupt Handler - Linux

linux,linux-kernel,stack,interrupt-handling,top-halves
In a multitasking system when any hardware generates a interrupt to a particular CPU, where CPU can be performing either of below cases unless it is already serving a ISR: User mode process is executing on CPU Kernel mode process is executing on CPU Would like to know which stack...

Permutation At A Railway Track(Stack Implementation)

algorithm,stack,combinatorics
Engines numbered 1, 2, ..., n are on the line at the left, and it is desired to rearrange(permute) the engines as they leave on the right-hand track. An engine that is on the spur track can be left there or sent on its way down the right track,...

Mysterious printf argument when disassembling c program

c,assembly,stack,printf
So I have this c code: #include <stdio.h> int main(void) { int a; int b; int c; a=b=c=5; printf("Hi%d%d%dHi",a,b,c); } I compiled it on ubuntu with: gcc program.c -o program -ggdb -m32 -O2 And then disassembled it with: objdump -M intel program -d And in main printf() gets called like...

C# stack push call issue

c#,stack
I'm having an issue where my C# stack will accept a pushed value but then overwrite the previously existing elements in the stack with the new value as well. Here's a chunk of the constructor for reference: public class MazNav //handles processing and navigation { private Maze m; private static...

Does PHP have a peek array operation?

php,arrays,stack,queue
I would like to peek at the first element of an array. This operation would be equivalent to this code: function peek($list) { $item = array_shift($list); array_unshift($list, $item); return $item; } This code just seems really heavy to me and peek is often provided by queue and stack libraries. Does...

Beginner's confusion about x86 stack

c,stack
I'm a 17-year-old highschool student that wanted to learn how to hack, but then found out that he really likes learning about x86, yesterday. With that said, I have no formal training and I'm just going off of what I'm reading on the internet. Here is an image I drew...

What is the correct way to implement a stack in Go so that it will store structs?

types,go,stack
I'm trying to make a stack that will store a series of Huffman Tree structs. Currently I'm using an implementation that I found on github. package util type item struct { value interface{} next *item } //Stack the implementation of stack //this stack is not thread safe! type Stack struct...

Stack with push and pop functions not working

c++,null,crash,stack
This is the program. #include<iostream> #include<string> using namespace std; struct stack { int inf; stack* link; } *start, *p; void push(stack*, stack*, int); void pop(stack*, stack*); int main() { int s = 0; string thing; cin >> thing; while (thing != "end") { if (thing == "push") { push(start, p,...

Efficient retrieval of last and second to last element of ArrayStack in Scala?

scala,stack
I am using a mutable ArrayStack in Scala but do not know how to access the last element (and second to last element) efficiently (constant time) without popping the items from the stack. Is it possible to access the elements?

where to declare object to use it (fltk)

c++,stack,heap,fltk
I am having a problem accessing an object or its methods in fltk. I have a Class named MyWindow which is a child class of Fl_Window. so basically i would like to use an object which is either declared int the main or Mywindow in private section. My problem is...

Does adding scope {} brackets to let variables go out of scope have the same effect as calling and ending a function or some sort of empty loop?

java,scope,stack,brackets
I wonder if it is possible to let variables go out of scope while only adding brackets around some piece of code and if it's any different from the other ways to let variables go out of scope: 0) adding brackets: private void methodExample() { { int example = 5;...

Return Address Manipulation does not work

assembly,stack
So my goal is to change the return address to skip the one byte 0xE8. The return address is at the top of the stack after calling this function, right? So poping, add 1 and pushing the value should do the job. At least it looks like that at first...

JavaScript stack, LIFO stack: value not as expected

javascript,stack
I have the following code. var stackMapIn = []; var stackMapOut = []; var stackBack = []; stackMapOut.push("m1"); $scope.clickLinks = function(initialOut,initialIn,extra,backIn,backOut,name){ $('div#'+initialOut+'Map,'+extra).fadeOut('slow',function(){ $('.'+initialOut+'Details,.bkbtn'+backOut).css("display","none"); $('.'+initialIn+'Details,.bkbtn'+backIn).css("display","block"); $('.noQuery').css("display","none"); $("#buildingHeader").html(name); $('div#'+initialIn+'Map').fadeIn('slow'); }) stackMapOut.push(initialIn);...

Flood Fill and Stack Implementation Not working

c,stack,flood-fill
So I have two structs that work together. This is a game that works like a bubble pop game. When a balloon pops in the grid I want to use flood fill to remove the balloons an then have it using a stack so I can undo the process later....

Balancing parenthesis detection?

java,algorithm,stack
So I need to create a program that can determine if a set of parentheses is balanced or not as well as determine which parenthesis is the first "offending parenthesis" meaning the first parenthesis to not be part of a balanced pair. I could only come up with a program...

Implement two stack in one array

arrays,data-structures,stack
How to implement two stack in one array A[1..n] in such a way that neither stack overflows unless total no. of elements in both stack together is n. PUSH and POP should run in O(1) time ? What's wrong with this algo ? //A[1...n], top1 is pointer pointing to top...

Dynamic Character Array - Stack

c,multidimensional-array,stack
General Background I had a need for a character array that contained a dynamic number of character arrays based on the number of files located in a specific folder. I was able to accomplish this by initializing char (*FullPathNames)[MAX_FILENAME_AND_PATHNAME_LENGTH] and then using FullPathNames = malloc( sizeof(*FullPathNames) * NumOfFiles * MAX_FILENAME_AND_PATHNAME_LENGTH...

What is the purpose of stack, if you can do the same operations with an array?

c++,arrays,stack,theory
How frequent is a "stack" used in programming? In other words, would we loose something if we replace a stack with an array? Or is there any special case where a stack can't be replaced by anything else? I'm just a C++ beginner, and all I know about stacks is...

Stack behavior when returning a pointer to local variable

stack,rust
I have a simple example where the behaviour of Rust does not match my mental image, so I am wondering what am I missing: fn make_local_int_ptr() -> *const i32 { let a = 3; &a } fn main() { let my_ptr = make_local_int_ptr(); println!("{}", unsafe { *my_ptr } ); }...

STACK in c program. pop operation not working

c,stack
Guys what is wrong with this program. I am having problems with pop operation, it shows an extra value even after stack is empty. ?? void initstack (struct stack * p, int maxSize) void push (struct stack * p, int item) int pop (struct stack * p) void display (struct...

fread(), solaris to unix portability and use of uninitialised values

c,linux,memory,stack,portability
Valgrind found the following error and I, after reading the documentation, the code and other questions in here couldn't figure it out why. Valgrind: first warning ~$ valgrind --vgdb=yes --vgdb-error=0 --read-var-info=yes --leak-check=yes --track-origins=yes debitadmin* debitadmin ==20720== Conditional jump or move depends on uninitialised value(s) ==20720== at 0x4013BC6: initialise (dbg.c:199) ==20720==...

Where is Heap and Stack on Physical Memory? [closed]

c++,memory,stack,heap
I read by some googling about Heap & Stack, but most answer says just its concept description, differences. I am curious other things. as title says, Where is Heap and Stack on Physical Memory? How is their size? For example, I use 12 giga byte memory at my desktop PC,...

Stack Iterator in C++

c++,oop,iterator,stack
I want to understand what iterators are, how they are made. So int this code iterators are created for Stack.My question are how we can write Stack s2(s1), if we don't have class named Stack which has explicit constructor, insted we have StackIter class , which has explicit constructor ?...

Overfilling of Stack and Queue Capacity (c++)

c++,stack,queue
After many hours of research, reading, going over sample codes... I am stuck (or fried). I have a memory leak which dumps nothing into my Stack and Queue 'lists'. The premise is that I am trying to create find if a word or phrase is a palindrome by using Stacks...

Infinite loop when calling the stack print function

c++,stack,output,infinite-loop
This program should takes a postfix arithmetic expression then compiles the values of that expression.. Each time an integer is read, its gonna get pushed into the stack.. Otherwise, Two integers would be popped if +,-,* is read. class Stack { Node *head; public: Stack() { head = NULL; };...

How to stack Charts with amchart?

graph,stack,scrollbar,amcharts
is it possible to stack 2 or more graphs in one chart? with the same Scrollbar / Chartcursor? I tried it with the live editor, but havn't found any option to make this possible. Here som pictures for explaination: At the moment i have this graph: http://imgur.com/XpU42xK But i want...

How to call this function recursively?

javascript,recursion,stack,intern
I'm trying to come up with basic web crawler. The stack keeps track of all the URLs to visit in future. Until the stack gets empty, want to get list of all hrefs used within a web page. Tried to use arguments.calee but it returns: RangeError: Maximum call stack size...

Memory: Stack and Swap

linux,memory,stack,heap,swap
When there isn't enough RAM, dynamically allocated variables on the heap can take advantage of swap space on the disk (albeit causing performance degradations). My question is if the stack in memory can take advantage of the swap space as well. For example, the following program places a large array...

Stack Struct Updating Incorrectly During push Function

c,arrays,struct,stack
As part of an assignment, I am currently pushing an array of 2 integers to a stack style structure. With each push, it should add the new array of integers to the top of the stack. Instead it adds one, and changes the whole stack to match the new array....

Lock Free Bounded Stack C++11 atomics

c++,multithreading,c++11,stack,lock-free
I was thinking about using very basic bounded (preallocated) stack to keep track of my threads ids in correct LIFO order. So i was wondering if my implementation is thread safe: // we use maximum 8 workers size_t idle_ids_stack[8]; // position current write happening at std::atomic_uint_fast8_t idle_pos(0); // this function...

(Assembly 8086) How can I return from a function to a different segment?

assembly,stack,stack-overflow,8086
I got an assigment to write to programs. One which gets input from the user, using a function that allocates a string on the stack, and writes to it, one character at a time, until it gets an "Enter". And another program that uses the flaws of the first one,...

Trouble replicating a stack buffer overflow exploit

c,stack,overflow
I am having trouble replicating the stack buffer overflow example given by OWASP here. Here is my attempt: $ cat test.c #include <stdio.h> #include <string.h> void doit(void) { char buf[8]; gets(buf); printf("%s\n", buf); } int main(void) { printf("So... The End...\n"); doit(); printf("or... maybe not?\n"); return 0; } $ gcc test.c...

MASM console window creation troubles (maybe my stack frame??)

winapi,assembly,stack,x86-64,masm
I'm having trouble with the following code snippet. I'm compiling an asm file with a c++ file using visual studio express 2012. I've tried debugging calculating the addresses of the stack pointers and memory locations (still learning assembly obviously), but can't find a fault. (As I'm new it's probably something...

When is my struct too large?

swift,class,struct,stack,heap
We're encouraged to use struct over class in Swift. This is because The compiler can do a lot of optimizations Instances are created on the stack which is a lot more performant than malloc/free calls The downside to struct variables is that they are copied each time when returning from...

Create fixed size array on stack

c#,arrays,stack
I need a fixed data structure that (for performance reasons) is managed on the stack, but behaves like an array I am aware that I can create something like this: using System; namespace X { public sealed struct CustomArray<T> { private const Int32 n = 2; private T _field_1; private...

Printing Abstract Syntax Tree, infinite recursion issue

c,recursion,stack,abstract-syntax-tree
For the final project in my C programming class, we are implementing a reverse polish notation calculator which can either evaluate an expression for correctness, return the corresponding infix expression, or print out mock assembly code. To do so, we are to implement both a stack and a Abstract Syntax...

Why is the Stack not passing the input form the command line

c,pointers,types,stack,structure
How can I find where the error is? It prints out nested incorrect, I think that it is not pushing anything into the stack, but the peek function is giving an error. I am really confused as to why vim doesn't highlight any errors and it still compiles. #include <stdio.h>...

infix to postfix in java using stack class

java,stack,infix-notation
I'm trying to write infix to postfix program in java using stack. Here is my code: import java.io.*; import java.util.*; public class ONP{ public static void main(String args[]) throws java.io.IOException, NumberFormatException ,EmptyStackException{ BufferedReader br= new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(br.readLine()); StringBuilder out= new StringBuilder(); Stack st=new Stack(); for(int i=0;i<n;i++){ String input=br.readLine();...

String immutable? [duplicate]

java,string,stack,heap,immutability
This question already has an answer here: Immutability of Strings in Java [duplicate] 10 answers Can anyone answer me please? public class ReplaceString{ public static void main(String arg[]) { String a = "Hariom"; a = a.replace('H', 'b'); System.out.println(a); } } ...

jquery - Access array by level

jquery,arrays,stack
Suppose I have this array below: ['uploads'] { ['file_1'] { //maybe some attributes here } ['file_2'] { //maybe some attributes here } ['folder_1'] { ['file_1'] { //maybe some attributes here } ['file_2'] { //maybe some attributes here } ['folder_1'] { ['file_1'] { //maybe some attributes here } ['file_2'] { //maybe...

C# exception OutOfMemory

c#,exception,memory,stack,out-of-memory
I would need some help how to handle this exception: StackTrace : at System.Configuration.BaseConfigurationRecord.EvaluateOne(String[] keys, SectionInput input, Boolean isTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult) at System.Configuration.BaseConfigurationRecord.Evaluate(FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult, Boolean getLkg, Boolean getRuntimeObject, Object& result, Object& resultRuntimeObject) at...

Segmentation fault (core dumped) STACK

c,stack
I'm trying to implement a simple stack, but I have a segmentation problem: struct node { int key; struct node *next; }; static struct node *head, *z, *t; int main(int argc, char** argv) { push(5); push(9); push(8); push(pop()+pop()); push(4); push(6); push(pop()*pop()); push(pop()*pop()); push(7); push(pop()+pop()); push(pop()*pop()); printf("%d\n", pop()); return (EXIT_SUCCESS); }...

push operation in a stack with scanf

c,struct,stack
I am trying to simulate a stack using a doubly linked list. When I write the following code the output is what it is supposed to be. push_ch(12, "TNT"); push_ch(13, "ABC"); push_ch(14, "ESPN"); display(); OUTPUT 12 TNT 13 ABC 14 ESPN However, I have a problem when the arguments are...

Stack Level Too Deep, Modules and Classes

ruby,class,module,stack
I am new to Stackoverflow and I am having some trouble on a coding challenge. I need to be able to output the president's age, name, citizenship, along with a catchphrase. I keep receiving the error, stack level too deep exercise.rb:12 Can anyone explain, what is wrong? What does the...

why preserve stack space for local variables?

assembly,compilation,stack,compiler-optimization
I'm new to assembly language and I was wondering about local variables, why do we (or the compilers) preserve a space for them on the stack usually by decrement the "ESP" register at the prologue of the procedure and as the procedure ends we assign the "ESP" it's old value...

Mirrorring a queue in python

python,class,stack,queue,reverse
I need to mirror a queue using a function called mirror I have made the code for the queue class, but i dont know how to create a mirror of it. It needs to print out the original queue and then the same queue reversed Any help would be appreciated...

How we could make a stack file from hundreds of img files, in R programming language?

r,image,stack
I have around 184 .img image files per year. Their name is like these: mod11a1_2009-03-30.lst_day_1km.img mod11a1_2009-03-31.lst_day_1km.img mod11a1_2009-04-01.lst_day_1km.img . . . I am going to put all of those .img files, into 1 stack image with the same format: mod11a1_2009_lst_day_1km.img And generate the final stack image as an .img file in...

Creating a generic stack in generic stack class

java,object,generics,stack
I'm trying to teach myself some java and im stuck on a problem that seems kind of easy but i still don't seem to find a solution. What I have so far: Interface: public interface ADTStack<T> { public boolean isEmpty(); public void push(T element); public T top() throws IllegalStateException; public...

Trees in a Stack

java,algorithm,tree,stack
My program is supposed to receive an equation (ex: x^4*(x+3)) and transform it into post order (or reverse polish notation), after that I need to create a tree that needs to be put in a stack. The tricky part is reading through the post order equation. In the example it...

x86 calling convention: should arguments passed by stack be read-only?

c,x86,stack,argument-passing,calling-convention
It seems state-of-art compilers treat arguments passed by stack as read-only. Note that in the x86 calling convention, the caller pushes arguments onto the stack and the callee uses the arguments in the stack. For example, the following C code: extern int goo(int *x); int foo(int x, int y) {...

Deleting excess variables from stack - C++

c++,recursion,stack,heap,stack-overflow
I have a recursive function that declares at least 50KB of local variables in one call and a stack overflow might be likely with the number of recursive steps I'll need. However, by the time the function is called within itself, these variables aren't needed anymore. Can I delete them,...

Android create vertical carousel with stacked views

android,android-viewpager,stack,carousel
I am trying to implement this carousel style thing. It would be basically stacked fragments above each other and I could scroll through them. When I scroll the very front one would move intuitively to back. Does anyone know any library for that or is it easily doable with ViewPager?...

What is the current size of Stack?

algorithm,data-structures,stack
Suppose an initially empty stack S has performed a total of 25 push operations, 12 top operations, and 10 pop operations, 3 of which returned null to indicate an empty stack. What is the current size of S? I'm thinking that S.size =7 because 10 pop operations have 3 out...