stack-memory

How does a struct instance's virtual method get located using its type object in heap?

◇◆丶佛笑我妖孽 提交于 2021-02-02 09:14:34
问题 below is a code example from a book to show when a value type will be boxed: internal struct Point { private readonly Int32 m_x, m_y; public Point(Int32 x, Int32 y) { m_x = x; m_y = y; } //Override ToString method inherited from System.ValueType public override string ToString() { return String.Format("({0}, {1})", m_x.ToString(), m_y.ToString()); } } class Program { static void Main(string[] args) { Point p1 = new Point(10, 10); p1.ToString(); } } and the author says: In the call to ToString

How does a struct instance's virtual method get located using its type object in heap?

偶尔善良 提交于 2021-02-02 09:13:14
问题 below is a code example from a book to show when a value type will be boxed: internal struct Point { private readonly Int32 m_x, m_y; public Point(Int32 x, Int32 y) { m_x = x; m_y = y; } //Override ToString method inherited from System.ValueType public override string ToString() { return String.Format("({0}, {1})", m_x.ToString(), m_y.ToString()); } } class Program { static void Main(string[] args) { Point p1 = new Point(10, 10); p1.ToString(); } } and the author says: In the call to ToString

How does a struct instance's virtual method get located using its type object in heap?

北城以北 提交于 2021-02-02 09:13:03
问题 below is a code example from a book to show when a value type will be boxed: internal struct Point { private readonly Int32 m_x, m_y; public Point(Int32 x, Int32 y) { m_x = x; m_y = y; } //Override ToString method inherited from System.ValueType public override string ToString() { return String.Format("({0}, {1})", m_x.ToString(), m_y.ToString()); } } class Program { static void Main(string[] args) { Point p1 = new Point(10, 10); p1.ToString(); } } and the author says: In the call to ToString

How does the heap and stack work for instances and members of struct in C#?

我是研究僧i 提交于 2021-02-02 08:38:01
问题 I'm reading a book which says: The variable representing an struct instance doesn’t contain a pointer to an instance; the variable contains the fields of the instance itself. Because the variable contains the instance’s fields, a pointer doesn’t have to be dereferenced to manipulate the instance’s fields. The following code demonstrates how reference types and value types differ class SomeRef { public Int32 x; } struct SomeVal { public Int32 x; } static void ValueTypeDemo() { SomeRef r1 = new

Assembly x86-64 get function parameters from stack

99封情书 提交于 2021-01-19 08:38:12
问题 Lately I've been learning x86 Assembly from the book Programming from the Ground Up, but I have an x86-64 computer, so things start to go wrong at one point (pretty early in the book). I got to the part where I'm dealing with functions, specifically the power example. In this example he pushes the parameters onto the stack and then copies them into registers later in the function. Here's what his code looks like: pushl $3 # second argument pushl $2 # first argument call power # call function

Assembly x86-64 get function parameters from stack

主宰稳场 提交于 2021-01-19 08:38:07
问题 Lately I've been learning x86 Assembly from the book Programming from the Ground Up, but I have an x86-64 computer, so things start to go wrong at one point (pretty early in the book). I got to the part where I'm dealing with functions, specifically the power example. In this example he pushes the parameters onto the stack and then copies them into registers later in the function. Here's what his code looks like: pushl $3 # second argument pushl $2 # first argument call power # call function

Does the Code Block of a method live in the stack or heap at the moment of execution?

限于喜欢 提交于 2020-02-25 02:16:05
问题 I'm relatively new to learning programming languages, and I feel I have 20 to 25% of understanding of Object Oriented Programming Language, more specifically C# language. So I really state this question without knowing the actual significance of its answer, if any, to my process of learning the language, but I really felt I need to ask it. When a method is called for execution, I know that all its local variables and its parameters and return value are actually present in the stack memory.

Arrays memory allocation on stack

拜拜、爱过 提交于 2020-01-15 09:37:08
问题 I have 2 functions in C: void func1(unsigned char x) { unsigned char a[10][5]; a[0][0] = 1; a[9][4] = 2; } void func2(unsigned char x) { unsigned char a[10][5]; a[0][0] = 1; a[9][4] = 2; unsigned char b[10]; b[0] = 4; b[9] = 5; } Compiling with: gcc 7.3 x86-64 -O0 -g OS: 16.04.1-Ubuntu x86-64 Produced intel assembly of functions: func1(unsigned char): pushq %rbp movq %rsp, %rbp movl %edi, %eax movb %al, -68(%rbp) movb $1, -64(%rbp) movb $2, -15(%rbp) nop popq %rbp ret func2(unsigned char):

memory allocation in Stack and Heap

℡╲_俬逩灬. 提交于 2020-01-10 07:58:14
问题 This may seem like a very basic question, but its been in my head so: When we allocate a local variable, it goes into stack. Similarly dynamic allocation cause the variable to go on heap. Now, my question is, is this variable actually lie on stack or heap or we will just a reference in the stack and Heap. For example, Suppose I declare a variable int i . Now this i is allocated on the stack. So, when I print the address of i , this will be one of the location on stack? Same question for heap

Why each slot of the local variable array in a stack frame is of 4 bytes, and not 1 byte in the JVM?

时光毁灭记忆、已成空白 提交于 2020-01-04 11:03:53
问题 Each slot of local variable array is of 4-bytes. So to store a character, short or byte variables one slot is used. Means all smaller data-types internally gets converted into int data type. My doubt is: 1). Is it not making smaller data types useless, if internally they are of 4-bytes?, If yes, Why not remove such data-types from the language? 2). If each slot is of 1-byte then there will be no wastage of memory. Why not each slot is of 1-byte? 回答1: 1). Is it not making smaller data types