stack

where is array saved in memory in java?

余生长醉 提交于 2019-12-05 14:30:26
问题 If I have a function that in that function I declare: Object arr[] = new Object[20]; Where are arr and the whole array stored? heap? stack? Does it matter if the declaration is in some function or in main()? and let's say I also have these command lines: arr[0] = new String("abc"); arr[1] = new List(); where are arr[0] and arr[1] stored? 回答1: Memory diagram: Boxes are memory locations (where binary numbers can be stored). Arrows are memory references (i.e. pointers). 回答2: In theory, the stack

Why does GCC subtract the wrong value to the stack pointer when allocating a big array with no subsequent function calls?

浪子不回头ぞ 提交于 2019-12-05 14:03:21
问题 Really bizarre gcc quirk. Check this out: main() { int a[100]; a[0]=1; } produces this assembly: 0: 55 push %rbp 1: 48 89 e5 mov %rsp,%rbp 4: 48 81 ec 18 01 00 00 sub $0x118,%rsp b: c7 85 70 fe ff ff 01 movl $0x1,-0x190(%rbp) 12: 00 00 00 15: c9 leaveq 16: c3 retq The top of the stack is clearly 400, since its a 100 * 4 array. So when it writes to the first entry, it does rbp - 400 (line 'b'). Good. But why does it subtract 280 from the stack (line '4') pointer? Doesn't that point to the

Design a stack that can also dequeue in O(1) amortized time?

微笑、不失礼 提交于 2019-12-05 13:22:51
I have an abstract data type that can be viewed as a list stored left to right, with the following possible operations: Push: add a new item to the left end of the list Pop: remove the item on the left end of the list Pull: remove the item on the right end of the list Implement this using three stacks and constant additional memory, so that the amortized time for any push, pop, or pull operation is constant. The stacks have basic operations, isEmpty, Push, and Pop. Amortized time means "If I spend this amount of time, I can spend another block of it and store it in a bank of time to be used

Stack size on BlackBerry?

◇◆丶佛笑我妖孽 提交于 2019-12-05 12:40:50
I know that on Symbian stack size is equal to 8k. What about BlackBerry? Electro Perhaps this thread on the BlackBerry Forums is helpful: I don't believe there is any way to [ increase stack size for threads ] in the BB environment. Stack Size is initialized by the JVM, and we have no access to JVM parameters in the BB OS, AFAIK. 来源: https://stackoverflow.com/questions/1267075/stack-size-on-blackberry

How to control space between stack bars in ggplot2?

ぃ、小莉子 提交于 2019-12-05 10:36:05
I'm plotting a stack barplot in ggplot2. My dataset is like, var1 var2 var3 value treatment1 group_1 C8.0 0.010056478 treatment2 group_1 C8.0 0.009382918 treatment3 group_2 C8.0 0.003014983 treatment4 group_2 C8.0 0.005349631 treatment5 group_2 C8.0 0.005349631 var1 contains 5 treatments, these five treatments belong to two groups in var2 , and each treatment has 14 measurements in var3 , their value stored in value . I want to make a plot to compare these five treatments, and their measurements. so I plot with stack bar plot like this figure: My code: library(ggplot2) colourCount = length

null character(s) ignored enabled by default

孤者浪人 提交于 2019-12-05 09:44:18
I am trying to implement stack with array! Every time i execute the program runs fine but i am getting warning as null character(s) ignored enabled by default What does this warning mean?.. what am i doing wrong? My code is: #include<stdio.h> #include<stdlib.h> # define MAX 10 int top=-1; int arr[MAX]; void push(int item) { if(top==MAX-1) { printf("OOps stack overflow:\n"); exit(1); } top=top+1; arr[top]=item; }//warning int popStack() { if(top==0) { printf("Stack already empty:\n"); exit(1); } int x=arr[top]; top=top-1; return x; } void display() { int i; for(i=top;i>=0;i--) { printf("%d "

Using a stack to traverse and solve a maze - Java

爱⌒轻易说出口 提交于 2019-12-05 08:47:18
So I am trying to create a maze solver program that would solve a maze of X's and O's. What I would like to do is create a class of Points, so that I can create a 2-Dimensional array of Points which would allow printing to an output page as well as implementing the stack to be relatively simple. The simplest algorithm of the general idea I'd like to implement in the actual program itself I believe should be: 1) Move forward 2) Are you at a wall? 2a) If yes, turn left 3) Are you at the finish? 3a) If no, go to 1 3b) If yes, solved But I'm having trouble coming up with a more in-depth algorithm,

Where does exception object have its space, heap or stack, and how to access it in different class?

别说谁变了你拦得住时间么 提交于 2019-12-05 08:41:08
Recently an interviewer asked me where the exception object in C++ is allocated, heap or stack? I'm not sure but I answered stack since I thought there is no "new" or "malloc". Is it correct? Then he kept asking me that if it's on stack, assuming class A throw a exception object, let's say "e", and class B catch "e". Since "e" is on the stack of A, then how does B can have the access to this "e"? I'm not very clear about the second question. Could anyone can give me some example code showing that "class A throw e and class B catch it"? Also, I guessed B can catch e by copying the value or

ARM: Is “STMDB SP!, {R0-R8}” (aka PUSH {R0-R8}) an atomic operation?

馋奶兔 提交于 2019-12-05 08:29:20
I wonder if STMDB SP!, {R0-R8} is an atomic operation in ARM(v7), because it looks quite complex to me. So is it for example possible, that the CPU is interrupted somewhere "in the middle" and has already stored R5-R8 on the stack and the SP is now SP_old - 16 and after handling the interrupt the processor continues with R0-R4? Thanks. It is atomic, as far as interrupt handling is concerned. If I remember correctly, interrupting the instruction causes it to be aborted and re-executed after interrupt processing has finished, in order to guarantee interrupt latency. To clarify upon the slightly

Why Is GCC Using Mov Instead Of Push In Function Calls?

 ̄綄美尐妖づ 提交于 2019-12-05 08:21:29
So I've got this example C program. int worship(long john) { return 0 * john; } int main() { return worship(666); } The assembly looks (essentially) like this: worship(long): pushq %rbp movq %rsp, %rbp movq %rdi, -8(%rbp) movl $0, %eax popq %rbp ret main: pushq %rbp movq %rsp, %rbp movl $666, %edi call worship(long) popq %rbp ret I ran into this while reading about stack smashing. In the assembly worship(long): section where it says movq %rdi, -8(%rbp) I would expect it to be using pushq based on everything I've read so far. Is this the new way that GCC is pushing arguments onto the stack and