stack

Stack overflow with Fibonacci's recursive call

和自甴很熟 提交于 2019-12-12 22:15:14
问题 How exactly is the Java stack set up? For university, I shall determine what the biggest possible Fibonacci number that is calculated by a recursive method and can be handled by the stack. The interesting thing is: Tests showed that it doesn't matter how much -Xmx and -Xms the JVM has. I am able to run up to Fib(4438). But the results aren't consistent. Somtimes it goes down to 4436. Is there formular for the stack? Any increase of the stack via -Xss 4096m doesn't make a difference. 回答1: -Xmx

Reversing an array using a stack

∥☆過路亽.° 提交于 2019-12-12 22:09:02
问题 I am attempting to reverse an array using a stack. However, I get an error on arr[i] = stack.top(); , and the suggestion to resolve it in Eclipse is to change it to arr[i] = stack.pop(); or to add a cast. Is there another way about this or have I made a mistake? I see tutorials and questions asking about how to reverse a string using a stack and I have tried to reverse an array using the same logic, but I'm not entirely sure where I'm going wrong. public static void reverse(String[] arr){

Flutter - changing a Stack Order

北战南征 提交于 2019-12-12 18:28:53
问题 I have a Stack where on a condition (e.g. user click), I want one of the lower order widgets to be pushed to the top of the stack. Using the code below as a simple example - what code do I need in a setState() method to reorder so that the first (bottom) widget becomes the last (top) widget? new Stack( children: <Widget>[ new Icon(Icons.monetization_on, key: GlobalKey(), size: 60.0, color: const Color.fromRGBO(200, 100, 180, 1.0)), new Positioned( left: 20.0, child: new Icon(Icons

c++ while loop condition isn't playing nice with stack.empty() [closed]

强颜欢笑 提交于 2019-12-12 17:21:33
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . So I'm flustered by this bit of code - can't understand why it's misbehaving. The only thing I can think of is that stack.empty() isn't working properly with the while loop, but that seems ridiculous. You'll see

Calling delete on variable allocated on the stack

狂风中的少年 提交于 2019-12-12 16:12:27
问题 Ignoring programming style and design, is it "safe" to call delete on a variable allocated on the stack? For example: int nAmount; delete &nAmount; or class sample { public: sample(); ~sample() { delete &nAmount;} int nAmount; } 回答1: No, it is not safe to call delete on a stack-allocated variable. You should only call delete on things created by new . For each malloc or calloc , there should be exactly one free . For each new there should be exactly one delete . For each new[] there should be

x86-64 Linux NASM. Function parameter passing of type int array declared as a function in C++ file

我怕爱的太早我们不能终老 提交于 2019-12-12 14:23:40
问题 I tried using this advice for this problem For Linux programming arr[], n, &a, &b are passed in RDI, RSI, RDX and RCX. and the output of the program doesn't sum up the integers in the array properly. It outputs a large number that is obviously wrong. The two files found below were modified from the original 32-bit version found here. http://mcs.uwsuper.edu/sb/224/Intro/c_asm.html What I want is to compile an assembly file that calls a function parameter in a C++ file called array.cpp and then

Why is 0x20 subtracted from the stack pointer in the prologue of this function's code?

馋奶兔 提交于 2019-12-12 13:53:12
问题 void main(){ int c; c = function(1, 2); } int function(int a, int b){ char buf[10]; a = a+b; return a; } Assembly code: main: 08048394: push %ebp 08048395: mov %esp,%ebp 08048397: and $0xfffffff0,%esp **0804839a: sub $0x20,%esp <-----------------------???????** 0804839d: movl $0x2,0x4(%esp) 080483a5: movl $0x1,(%esp) 080483ac: call 0x80483b7 <function> 080483b1: mov %eax,0x1c(%esp) 080483b5: leave 080483b6: ret function: 080483b7: push %ebp 080483b8: mov %esp,%ebp 080483ba: sub $0x10,%esp

C function stack layout

一曲冷凌霜 提交于 2019-12-12 12:31:42
问题 I have a function that looks like so: int bof(char *str) { char buffer[12]; strcpy(buffer, str); return 1; } I am attempting to overwrite its return address. I have found that I can do so by using, for instance, memcpy(buffer+24, "\x15\xf1\xff\xbf", 4) . What I do not understand is why I need to access buffer + 24 . My understanding of the C memory model tells me that the stack when this function is executed should look like bottom of top of memory memory buffer(12) sfp(4) ret(4) str(4) <----

What's the right way to make a stack (or other dynamically resizable vector-like thing) in Rust?

允我心安 提交于 2019-12-12 12:25:01
问题 Google turns up many links on old methods that have now been removed from the language, but I can't find a reference on what to do for Rust 0.6. I've just implemented a linked list, which I could easily repurpose into a stack, but I'd rather use some well-tested, robust, existing data structure from the standard library. 回答1: I would try, in order : a deque a list or a dlist a vec a mutable owned vector You can learn more about the containers on the wiki. 来源: https://stackoverflow.com

What is c/c++ data segment and stack size?

谁都会走 提交于 2019-12-12 12:25:00
问题 I read that it depends on the compiler and operating system architecture. How do I find out the data segment and stack max size on a Linux system using GCC as compiler? 回答1: Let me experiment with you: create file ``test.c'' like this: int main (void) { return 0; } Now compile it, specifying max stack size (just to easy lookup this number in map file and determine symbol name, refering to it): gcc test.c -o test.x -Wl,--stack=0x20000 -Wl,-Map=output.map Determining data size is simple: size