stack

Thread-safe C++ stack

早过忘川 提交于 2019-12-20 08:29:31
问题 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? EDIT: Hi. Thanks for the initial great answers. I guess one reason I thought this could be built-in was that I was thinking purely in x86 space and thought

C# checking if expression is brackets valid [closed]

混江龙づ霸主 提交于 2019-12-20 07:27:34
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 3 years ago . The expression: "( a[i]+{-1}*(8-9) )" should return true since it is valid to write syntax like this. Every left bracket has a right closer in the correct place and all brackets are at legal positions. I tried to do this via one stack and I know where I'm wrong but I want to know

How safe is recursion in Python?

落爺英雄遲暮 提交于 2019-12-20 05:24:26
问题 I'm working on an AI homework, and despite my professor's suggestions, I have no intention of writing this assignment in lisp. However, I do want to write it recursively, the better to keep it concise and simple. Here is my question: Am I running a major risk of running out of stack space if I perform a search over a large state space? How deep does the Python stack go? 回答1: How deep does the Python stack go? The default recursion limit in python is 1000 frames. You can use sys

Handling Huge Multidimensional Arrays in C++

↘锁芯ラ 提交于 2019-12-20 04:30:32
问题 I'm designing a game in C++ similar to Minecraft that holds an enormous amount of terrain data in memory. In general, I want to store an array in memory that is [5][4][5][50][50][50]. This isn't bad since it amounts to about 100mb of virtual memory since my structure will only be about 8 bytes. However, I'm having trouble figuring out the best way to handle this. I do want this to be in virtual memory, but obviously not on the stack. And I keep making the mistake some how of creating this

Python breadth-first search matrix print path

只愿长相守 提交于 2019-12-20 03:52:31
问题 I have this line of code that tests wether or not there is a path to be found in a labyrinth represented by a matrix. How do I print the path at the end after I've determined wether or not there is a path. I've tried doing a stack but I'm not sure how to proceed. from queue import Queue maze=open(input()) matrix=maze.readlines() matrix=[i.strip() for i in matrix] matrix=[i.split() for i in matrix] numrows, numcols = len(matrix), len(matrix[0]) q=Queue() row=0 col=0 q.put((row,col)) while not

During an x86 software interrupt, when exactly is a context switch made?

ぐ巨炮叔叔 提交于 2019-12-20 03:32:29
问题 I am asking this because I am trying to implement interrupts in my toy kernel. So, I know that when an interrupt occurs, the CPU pushes various bits of information onto the stack. However, everywhere I search online shows different information in different order being pushed. I also know that if the interrupt occurred in user mode (Ring 3), the CPU must switch to kernel mode (Ring 0) before it can execute the ISR. I think it has something to do with the TSS and ss and esp , however I am not

Destructive Stack Iteration

六月ゝ 毕业季﹏ 提交于 2019-12-20 02:39:17
问题 This is my Stack implementation. class Stack: def __init__(self): self.head = None self.size = 0 def push(self, item): node = Node(item) if not self.head: self.head = node else: node.next = self.head self.head = node self.size += 1 def pop(self): if self.size == 0: raise ValueError('Popping off an empty stack!') item = self.head.val self.head = self.head.next return item def peek(self): if self.size == 0: raise ValueError('Peeking into an empty stack!') return self.head.val def __iter__(self)

Increase stack size in OS X Lion

荒凉一梦 提交于 2019-12-20 02:32:40
问题 I need to do it for a C++ program that needs a lot of stack. I use g++ (included in OS X Lion) to compile it. How could I increase it for my program? 回答1: From http://developer.apple.com/library/mac/#qa/qa1419/_index.html Using gcc, pass link flags through to ld with -Wl: gcc -Wl,-stack_size -Wl,1000000 foo.c 回答2: You can use getrlimit / setrlimit - this works on Linux, Mac OS X, and other POSIX-ish operating systems, e.g. #include <sys/resource.h> int main (int argc, char **argv) { const

Will the stack of a C program ever shrink?

為{幸葍}努か 提交于 2019-12-20 01:35:20
问题 I've noticed that every running C program has a private mapping called [stack] that is initially quite small (128k on my machine), but will grow to accomodate any automatic variables (up to the stack size limit). I assume this is where the call stack of my program is located. However, it doesn't seem to ever shrink back to its original size. Is there any way to free up that memory without terminating the process? How is the C stack implemented internally; what increases the size of the [stack

Activities Stack Issue

你。 提交于 2019-12-20 01:11:46
问题 I have two sets of Activities suppose 3 Activities each set, (A1,B1,C1 || A2,B2,C2) I start my App from A1 then -> B1 -> C1 here I want to jump from C1 to -> A2 and at A2 if I press back it should exist the App and not put me back for C1, then from A2 I navigate to -> B2 -> C2. So it is basically I want to change the starting Activity, it is like I have two Apps in one App and when I flip to the second App I have to clear the Activity Stack. Is that possible? Any Ideas? 回答1: Seems to me you