stack

why can temporary objects be bound to const reference?

最后都变了- 提交于 2020-01-05 07:18:37
问题 Source of question: The only failing case is passing parameters by non-const reference, since temporary variable couldn't be bound to it. void DrawLine(const Vector& v1, const Vector& v2); If the object is temporary, why would making the reference const have any effect on the lifetime of the temporary object? I guess I also don't fully understand the scope of existence for temporary objects created in an argument. 回答1: If the object is temporary, why would making the reference const have any

Get the size of heap and stack per process in Linux

巧了我就是萌 提交于 2020-01-05 05:43:05
问题 I wanted to know the size of heap and stack per process in linux. Is there any way to find it? I found out that sbrk(0) will give me the end of heap. But how can I find the start of heap to get the heap size? Also on stack size is there any way to find the start of stack and current stack pointer address per process through any library calls or system calls? 回答1: On Linux, you can read /proc/[PID]/maps and find [heap] and [stack] entries. But for the GLIBC heap implementations usually used on

Stack - unchecked/unsafe operations

痴心易碎 提交于 2020-01-05 04:17:07
问题 So I'm trying to run this simple program here: import java.util.*; class StackDemo { public static void main(String[] args) { Stack s = new Stack(); s.push(5); s.push("dog"); System.out.print(s); } } StackDemo.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. Process completed. It displays the expected result, which is "[5, dog]" but I don't understand that message on the Build Output window. What could possibly be wrong here? 回答1: Stack is a generic

How can i use two stacks(LIFO) so that it can work like a queue(FIFO)?

醉酒当歌 提交于 2020-01-05 03:04:08
问题 I have two stacks(which follows LIFO). I would like to know if i can write a C program to use these two stacks work like a queue(FIFO). 回答1: One stack is used to insert new elements into the queue. The other stack is used to remove elements. When the output stack is empty, the input stack is reversed and becomes the new output stack. In pseudo-C: typedef struct { stack in, stack out } queue. void insert(queue *q, void *data) { push(q->in, data); } void* remove(queue *q) { if (empty(q->out)) {

Why do subsequent Rust variables increment the stack pointer instead of decrementing it?

这一生的挚爱 提交于 2020-01-04 15:53:49
问题 I find it odd how when you create statically-allocated variables in Rust that it seems as the stack pointer increases. I know this is not the case since the stack pointer decreases as memory is allocated. If I were to do the same thing in C, I would see the stack pointer decrease as I created more variables. Why is it this way? Does the Rust compiler allocate these from bottom to top instead on top to bottom? fn main() { let i1 = 1; let i2 = 1; let i3 = 1; println!("i1 : {:?}", &i1 as *const

Why does my program that creates a stack using std::vector crash?

落爺英雄遲暮 提交于 2020-01-04 11:07:19
问题 I am creating my own stack for my data structures class. For our assignment we are using the assignment to convert a real-time infix equation into a postfix equation. I thought my program: took input determines if it was digit or number(operand) prints it out determines if input is operator (+,-,/,*) adds to stack or prints out, depending on stack precedence Instead it prints out the operands as expect, but I get this error when I enter an operator >.../dorun.sh line 33: 4136 Segmentation

Why does my program that creates a stack using std::vector crash?

青春壹個敷衍的年華 提交于 2020-01-04 11:04:48
问题 I am creating my own stack for my data structures class. For our assignment we are using the assignment to convert a real-time infix equation into a postfix equation. I thought my program: took input determines if it was digit or number(operand) prints it out determines if input is operator (+,-,/,*) adds to stack or prints out, depending on stack precedence Instead it prints out the operands as expect, but I get this error when I enter an operator >.../dorun.sh line 33: 4136 Segmentation

C++ call stack not in standard?

≯℡__Kan透↙ 提交于 2020-01-04 06:04:29
问题 Does the C++ standard talk about the call stack? It's common knowledge how stack and heap are used in C++, but I was reading through the standard and found no mention of it. http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1905.pdf Is this something that's left up to the compiler implementation, but everyone agrees on, or did I miss something while browsing the doc? 回答1: It isn't mentioned in the standard. Neither the stack nor the heap are. The standard describes the syntax and the

C++ call stack not in standard?

孤者浪人 提交于 2020-01-04 06:04:20
问题 Does the C++ standard talk about the call stack? It's common knowledge how stack and heap are used in C++, but I was reading through the standard and found no mention of it. http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1905.pdf Is this something that's left up to the compiler implementation, but everyone agrees on, or did I miss something while browsing the doc? 回答1: It isn't mentioned in the standard. Neither the stack nor the heap are. The standard describes the syntax and the

Identifying if an address belongs to heap or stack or registers

雨燕双飞 提交于 2020-01-03 09:08:12
问题 I have a pointer available with me to a C/C++ variable. Is it possible to exactly make out which segment of the memory this variable belongs to ? If yes, how ? Note: I just have the address of this variable, no further information if the variable is local/global etc. 回答1: Find out whether your architecture has pointers to your heap or stack region. Usually there are some stackpointers or framepointers.. Then compare your actual address to those addresses and decide where they belong. 回答2: If