stack

Delphi: function Result not emptied during for loop

对着背影说爱祢 提交于 2019-12-03 20:16:06
问题 is this normal? for a := 1 to 10 do x.test; x.test; x.test; x.test; function test: string; begin {$IFDEF DEBUG} DebugMessage('result check = '+Result,3); {$ENDIF} result := result + 'a'; end; 10:39:59: result check = 10:39:59: result check = a 10:39:59: result check = aa 10:39:59: result check = aaa 10:39:59: result check = aaaa 10:39:59: result check = aaaaa 10:39:59: result check = aaaaaa 10:39:59: result check = aaaaaaa 10:39:59: result check = aaaaaaaa 10:39:59: result check = aaaaaaaaa

Infix to Postfix using Stacks Java

倖福魔咒の 提交于 2019-12-03 20:14:45
I am trying to write a program to convert an infix expression to a postfix expression. The algorithm that I am using is as follows : 1. Create a stack 2. For each character t in the expression - If t is an operand, append it to the output - Else if t is ')',then pop from the stack till '(' is encountered and append it to the output. do not append '(' to the output. - If t is an operator or '(' -- If t has higher precedence than the top of the stack, then push t on to the stack. -- If t has lower precedence than top of the stack, then keep popping from the stack and appending to the output

Why is there a limit on the stack size? [duplicate]

不问归期 提交于 2019-12-03 20:05:01
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: What and where are the stack and heap My installation of Ubuntu has a default stack size limit of 8 MB. But I am curious as to why we need to restrict a user program's stack size. The same program can use all of its 4 GB (for a 32 bit program) addressable space via malloc/mmap etc. So why do we need a stack size limit? Why can't the stack grow till it almost meets the heap? 回答1: In fact the stack does grow more

Is there any way to determine the available stack space at run time?

懵懂的女人 提交于 2019-12-03 19:30:40
问题 I know that stack size is fixed. So we can not store large objects on stack and we shift to dynamic allocations (e.g. malloc). Also, stack gets used when there is nesting of function calls so we avoid recursive functions as well for this reason. Is there any way at runtime to determine how much stack memory is used so far and how much is left ? Here, I am assuming linux environment (gcc compiler) with x86 architecture. 回答1: Just read %esp, and remember its value goes down. You already know

Push/Pop segmentation fault at Assembly x86

限于喜欢 提交于 2019-12-03 18:18:41
问题 I'm using elf64 to compile my assembly x86 code: I've this sub-routine: printNumber: mov EAX, EDX ; EDX contain some value like "35" mov ESI, 10 ; to divide by 10 MOV ECX,0 ; counter whileDiv: cmp EAX, 0 je endWhileDiv xor rdx, rdx ; clean RDX idiv ESI ; EAX=EAX/10 and EDX = EAX%10 push rdx ; this line generate a segmentation fault add ECX, 1; count how many items i has added into stack jmp whileDiv endWhileDiv: ret I'm trying to push all digits of a number into my stack using push, but i'm

c++ return reference / stack memory [duplicate]

旧街凉风 提交于 2019-12-03 18:01:54
问题 This question already has answers here : Can a local variable's memory be accessed outside its scope? (20 answers) Closed 6 years ago . A basic question that I'm not sure of the answer. Is the follow function valid? std::vector<int> & test_function() { std::vector<int> x; // do whatever return x; } If so, why? Shouldn't the program delete x from the stack after the function returns? Thanks. 回答1: The behavior is undefined. You shouldn't return references to local variables. 回答2: The function

Is there a programmatic way to check stack corruption

跟風遠走 提交于 2019-12-03 17:37:03
问题 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 registered a timer for 10 mS, and this timer will check for stack corruption. Stack corruption checking method, 1. Initialize the stack memory with some unique pattern (I use 0x5A5A5A5A) 2. Check from the

x86_64 calling conventions and stack frames

跟風遠走 提交于 2019-12-03 17:31:03
问题 I am trying to make sense out of the executable code that GCC (4.4.3) is generating for an x86_64 machine running under Ubuntu Linux. In particular, I don't understand how the code keeps track of stack frames. In the old days, in 32-bit code, I was accustomed to seeing this "prologue" in just about every function: push %ebp movl %esp, %ebp Then, at the end of the function, there would come an "epilogue," either sub $xx, %esp # Where xx is a number based on GCC's accounting. pop %ebp ret or

Stack overflow - static memory vs. dynamic memory

本小妞迷上赌 提交于 2019-12-03 16:18:46
If you write int m[1000000]; inside the main function of C/C++, it will get a runtime error for stack overflow. Instead if you write vector<int> m; and then push_back 1000000 elements there, it will run fine. I am very curious about why this is happening. They both are local memory, aren't they? Thanks in advance. Yes, the vector itself is an automatic (stack) object. But the vector holds a pointer to its contents (an internal dynamic array), and that will be allocated on the heap (by default). To simplify a little, you can think of vector as doing malloc / realloc or new[] calls internally

how to use gdb to explore the stack/heap?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-03 15:37:34
问题 Could anyone please give me a quick overview/point me to documentation of a way to inspect the stack (and heap?) of a C program? I thought this should be done with GDB, but if there are other more straighforward alternatives, then that should be fine as well. Thanks. 回答1: My first approach to using GDB for debugging is to setup breakpoints. This is done like so: prompt> gdb ./x_bstree.c (gdb) #prompt (gdb) b 123 #break at line 123 (gdb) r #start program Now your program halts at line 123 of