stack

How to convert a recursive function to use a stack?

依然范特西╮ 提交于 2019-12-17 15:51:41
问题 Suppose that I have a tree to traverse using a Depth First Search, and that my algorithm for traversing it looks something like this: algorithm search(NODE): doSomethingWith(NODE) for each node CHILD connected to NODE: search(CHILD) Now in many languages there is a maximum depth to recursion, for example if the depth of recursion is over a certain limit, then the procedure will crash with a stack overflow. How can this function be implemented without the recursion, and instead with a stack?

iOS how to detect programmatically when top view controller is popped?

倖福魔咒の 提交于 2019-12-17 15:34:49
问题 Suppose I have a nav controller stack with 2 view controllers: VC2 is on top and VC1 is underneath. Is there code I can include in VC1 that will detect that VC2 has just been popped off the stack? Since I'm trying to detect the popping of VC2 from within the code for VC1 it seems that something like viewWillAppear or viewDidAppear won't work, because those methods fire every time VC1 is displayed, including when it is first pushed on the stack. EDIT: it seems I was not very clear with my

Stack corruption in C++

蓝咒 提交于 2019-12-17 15:33:34
问题 In C++, in which way the stack may get corrupted. One way I guess is to overwriting the stack variables by accessing an array beyond its boundaries. Is there any other way that it can get corrupted? 回答1: You could have a random/undefined pointer that ends up pointing to the stack, and write though that. An assembly function could incorrectly setup/modify/restore the stack Cosmic waves could flips bits in the stack. Radioactive elements in the chip's casing could flip bits. Anything in the

How to get the caller class name inside a function of another class in python?

为君一笑 提交于 2019-12-17 10:38:13
问题 My objective is to stimulate a sequence diagram of an application for this I need the information about a caller and callee class names at runtime. I can successfully retrieve the caller function but not able to get a caller class name? #Scenario caller.py: import inspect class A: def Apple(self): print "Hello" b=B() b.Bad() class B: def Bad(self): print"dude" print inspect.stack() a=A() a.Apple() When I printed the stack there was no information about the caller class. So is it possible to

What does “ulimit -s unlimited” do?

余生颓废 提交于 2019-12-17 10:32:40
问题 There are understandably many related questions on stack allocation What and where are the stack and heap? Why is there a limit on the stack size? Size of stack and heap memory However on various *nix machines I can issue the bash command ulimit -s unlimited or the csh command set stacksize unlimited How does this change how programs are executed? Are there any impacts on program or system performance (e.g., why wouldn't this be the default)? In case more system details are relevant, I'm

Does this type of memory get allocated on the heap or the stack?

邮差的信 提交于 2019-12-17 07:53:44
问题 In the context of C++ (not that it matters): class Foo{ private: int x[100]; public: Foo(); } What I've learnt tells me that if you create an instance of Foo like so: Foo bar = new Foo(); Then the array x is allocated on the heap, but if you created an instance of Foo like so: Foo bar; Then it's created on the stack. I can't find resources online to confirm this. 回答1: Given a slight modification of your example: class Foo{ private: int x[100]; int *y; public: Foo() { y = new int[100]; } ~Foo(

Are there stackless or heapless implementation of C++?

筅森魡賤 提交于 2019-12-17 07:33:07
问题 C++ standard does not mention anything about the stack or the heap, they are implementation specific , which is true. Even though they are not part of the C++ standard, we end up using them anyway, so much that it's like they are part of the language itself and have to be taken into consideration for memory or performance purpose. Hence my question are there implementations of C++ that doesn't use stacks and heaps? 回答1: Others have already given good answers about the heap, so I'll leave that

Linux kernel ARM exception stack init

倖福魔咒の 提交于 2019-12-17 06:51:48
问题 I am using Linux kernel 3.0.35 on Freescale i.MX6 (ARM Cortex-A9). After running into a kernel OOPS I tried to understand the exception stack initialization. Here is what I have uncovered so far. In cpu_init() in arch/arm/kernel/setup.c , I see the exception stack getting initialized: struct stack { u32 irq[3]; u32 abt[3]; u32 und[3]; } ____cacheline_aligned; static struct stack stacks[NR_CPUS]; void cpu_init(void) { struct stack *stk = &stacks[cpu]; ...<snip> /* * setup stacks for re-entrant

Android Application Class Lifecycle

吃可爱长大的小学妹 提交于 2019-12-17 06:28:07
问题 The android app I am working on overrides the Application class to store lightweight state (username, gps location, etc) in static vars. Most of this state is set in OnCreate of the launch activity (username retrieved from prefs, location listener runs). Is it safe to rely on the launch activity to initialize the Application class? Are there any cases where the Application class might be re-created without the Launch activity also being created? The question comes up because I ran into a null

Stack-buffer based STL allocator?

寵の児 提交于 2019-12-17 06:27:28
问题 I was wondering if it practicable to have an C++ standard library compliant allocator that uses a (fixed sized) buffer that lives on the stack. Somehow, it seems this question has not been ask this way yet on SO, although it may have been implicitly answered elsewhere. So basically, it seems , as far as my searches go, that it should be possible to create an allocator that uses a fixed size buffer. Now, on first glance, this should mean that it should also be possible to have an allocator