stack

What's inside the stack?

寵の児 提交于 2019-12-05 19:16:09
问题 If I run a program, just like #include <stdio.h> int main(int argc, char *argv[], char *env[]) { printf("My references are at %p, %p, %p\n", &argc, &argv, &env); } We can see that those regions are actually in the stack. But what else is there? If we ran a loop through all the values in Linux 3.5.3 (for example, until segfault) we can see some weird numbers, and kind of two regions, separated by a bunch of zeros, maybe to try to prevent overwriting the environment variables accidentally.

Special queue with defined size

≯℡__Kan透↙ 提交于 2019-12-05 19:15:41
I need a collection that is limited in its size. It has to be similar to a circular buffer. I think that the fastest way to describe it would be by making an example. Suppose I have an instance of this "special" queue, of size 4. This is the queue initially: 6 3 9 2 If I push something into it, it has to add it at the beginning, remove the last element and return its value, so, if I add 3 it would become: 3 6 3 9 and returns 2 I hope I've been clear... A general implementation is sufficient, but a C# implementation would be the best :) public class MyQueue<T> { private Queue<T> queue; public

iphone NavigationController clear views stack

喜夏-厌秋 提交于 2019-12-05 19:03:00
I have an iphone application that uses a navigation controller. In that controller I push some views. In some cases I want to "clear" the views stack, leave only the rootViewController of the navigation controller in the stack and push another viewController I have. Can someone give me an example on how to do this? I don't see any method that clears the stack. Answer 1: I have tried to put in button Action the following code: [self.navigationController popToRootViewControllerAnimated:NO]; do some stuff here to prepare for the push. [self.navigationController pushViewController:self

Is it possible to force JVM to create an object in stack other than heap?

天涯浪子 提交于 2019-12-05 18:20:44
I read some where that sometimes JVM will identify some objects and try to create it in stack than heap as the memory allocation on the stack is cheaper than the memory allocation in the heap, deallocation on the stack is free and the stack is efficiently managed by the run-time. So is how this object allocation in stack works and is there any way to force the JVM to do this ? There is no way to force the JVM to allocate objects anywhere. You should not care where Java actually allocates your Object because it is not defined in the specifications. That being said the JVM has gotten a lot

Why does the stack have to be page aligned?

人走茶凉 提交于 2019-12-05 18:16:04
In Linux, I've tried (just for fun) to modify the kernel source in process.c create a stack address that has more entropy, i.e. in particular the line: sp -= get_random_int() % 8192; When I change this too much, the kernel halts or I get some seemingly undefined behavior. I'm guessing that this causes PAGE_ALIGN() to fail in some way? I'm not that interested in why PAGE_ALIGN() in particular fails, or exactly what piece of code in the kernel that fails (although that too would be nice to know); I'm more interested in why the stack must reside in a particular region at all. What is the

Assembly Language 2 Book on Push and Pop

ぃ、小莉子 提交于 2019-12-05 18:05:13
First question Which statement is true about what will happen when the example code runs? 1: main PROC 2: mov eax,30 3: push eax 4: push 40 5: call Ex3Sub 6: INVOKE ExitProcess,0 7: main ENDP 8: 9: Ex3Sub PROC 10: pusha 11: mov eax,80 12: popa 13: ret 14: Ex3Sub ENDP a. EAX will equal 40 on line 6 b. The program will halt with a runtime error on Line 6 c. EAX will equal 30 on line 6 d. The program will halt with a runtime error on Line 13 Second Question Which statement is true about what will happen when the example code runs? 1: main PROC 2: push 10 3: push 20 4: call Ex2Sub 5: pop eax 6:

How does the compiler determine the needed stack size for a function with compiler generated temporaries?

浪尽此生 提交于 2019-12-05 17:38:14
Consider following code: class cFoo { private: int m1; char m2; public: int doSomething1(); int doSomething2(); int doSomething3(); } class cBar { private: cFoo mFoo; public: cFoo getFoo(){ return mFoo; } } void some_function_in_the_callstack_hierarchy(cBar aBar) { int test1 = aBar.getFoo().doSomething1(); int test2 = aBar.getFoo().doSomething2(); ... } In the line where getFoo() is called the compiler will generate a temporary object of cFoo, to be able to call doSomething1(). Does the compiler reuse the stack memory which is used for these temporary objects? How many stack memory will the

Initialization of array on heap

折月煮酒 提交于 2019-12-05 16:52:28
问题 How do i manually initiate values in array on heap? If the array is local variable (in stack), it can be done very elegant and easy way, like this: int myArray[3] = {1,2,3}; Unfortunately, following code int * myArray = new int[3]; myArray = {1,2,3}; outputs an error by compiling error: expected primary-expression before ‘{’ token error: expected `;' before ‘{’ token Do i have to use cycle, or not-so-much-elegant way like this? myArray[0] = 1; myArray[1] = 2; myArray[2] = 3; 回答1: This is

Javascript string stored on stack

心已入冬 提交于 2019-12-05 15:28:57
I'm reading Professional JavaScript for Web Developers 3rd ed. and in the summary of chapter 4 one can read: Two types of values can be stored in JavaScript variables: primitive values and reference values. Primitive values have one of the five primitive data types: Undefined, Null, Boolean, Number, and String. Primitive and reference values have the following characteristics: Primitive values are of a fixed size and so are stored in memory on the stack. But I can have different strings, say: var a = "ABC"; // or var b = "Some very irritatingly long string..." They clearly differ in size, so

declare fixed size character array on stack c++

你。 提交于 2019-12-05 15:02:41
I am attempting to create a character array of a fixed size on the stack (it does need to be stack allocated). the problem I am having is I cannot get the stack to allocate more than 8 bytes to the array: #include <iostream> using namespace std; int main(){ char* str = new char[50]; cout << sizeof(str) << endl; return 0; } prints 8 How do I allocate a fixed size array (in this case 50 bytes. but it may be any number) on the stack? char* str = new char[50]; cout << sizeof(str) << endl; It prints the size of the pointer, which is 8 on your platform. It is same as these: cout << sizeof(void*) <<