memory-layout

Why difference between two pointers is not equals to size of type?

ε祈祈猫儿з 提交于 2020-01-24 01:18:08
问题 I have the simple program: #include <iostream> using namespace std; int main() { int a = 5; int b = 6; int* p1 = &a; int* p2 = &b; std::cout << p1 << " " << p2 << " ,sizeof(int)=" << sizeof(int) << std::endl; system("pause"); return 0; } It produces the following output: 00DBF9B8 00DBF9AC ,sizeof(int)=4 but, 00DBF9B8 - 00DBF9AC == С . I cannot understand this result. If I modify the program like this: #include <iostream> using namespace std; int main() { static int a = 5; static int b = 6;

C++ Can constant class data be optimized out of class by compiler?

回眸只為那壹抹淺笑 提交于 2020-01-14 14:23:13
问题 I know that constant variables outside classes can be optimized directly into function calls by the compiler, but is it legal for the compiler to do the same for constant class variables? If there is a class declared like this: class A { public: const int constVar; //other, modifiable variables A(int val): constVar(val) { //code to initialize modifiable variables } }; and I create an instance of A and call a function like this: A obj(-2); int absoluteVal = std::abs(A.constVar); is the

Is Method area still present in Java 8?

孤街醉人 提交于 2020-01-12 09:16:56
问题 Prior to Java 8 we had 5 major runtime data areas: Method Area Heap JVM Stacks PC registers Native method stacks With Java 8, there is no Perm Gen, that means there is no more “java.lang.OutOfMemoryError: PermGen” which is great but I also read Method Area is part of space in the Perm Gen but I can't seem to find anything which explicitly says Method area is no more in Java 8. So is Perm Gen along with Method area got removed or only Perm Gen got removed and Method area is still present in

Is Method area still present in Java 8?

荒凉一梦 提交于 2020-01-12 09:15:30
问题 Prior to Java 8 we had 5 major runtime data areas: Method Area Heap JVM Stacks PC registers Native method stacks With Java 8, there is no Perm Gen, that means there is no more “java.lang.OutOfMemoryError: PermGen” which is great but I also read Method Area is part of space in the Perm Gen but I can't seem to find anything which explicitly says Method area is no more in Java 8. So is Perm Gen along with Method area got removed or only Perm Gen got removed and Method area is still present in

Incrementing function pointers

你说的曾经没有我的故事 提交于 2020-01-11 08:12:37
问题 I just learned about function pointers (pointers pointing at the adress where where the machine code of a function is stored). This made me think about machine code and how it is stored in memory. Is the machine code stored consecutively in memory, so that it is possible to "manually" increase the pointer until it points to the following/previous function? Is this, what a debugger does? He lets me "see" where the program counter is pointing in the machine code? Conclusion: one can program

Incrementing function pointers

天涯浪子 提交于 2020-01-11 08:12:25
问题 I just learned about function pointers (pointers pointing at the adress where where the machine code of a function is stored). This made me think about machine code and how it is stored in memory. Is the machine code stored consecutively in memory, so that it is possible to "manually" increase the pointer until it points to the following/previous function? Is this, what a debugger does? He lets me "see" where the program counter is pointing in the machine code? Conclusion: one can program

Address of a Global Variable in the Heap Address Range

假装没事ソ 提交于 2020-01-02 10:22:21
问题 I was debugging the MPlayer-1.3.0 source code, and I saw a global variable whose address (returned by GDB or even simple printing) was in the range for the heap allocations, instead of the data section. I checked the heap range using procfs . 555555554000-555555834000 r-xp 00000000 08:12 798876 /usr/bin/mplayer 555555a33000-555555b25000 r--p 002df000 08:12 798876 /usr/bin/mplayer 555555b25000-555555b2b000 rw-p 003d1000 08:12 798876 /usr/bin/mplayer 555555b2b000-555556479000 rw-p 00000000 00

Type trait to identify primary base class

烂漫一生 提交于 2019-12-30 08:23:10
问题 If I have a class Base, with at least one virtual function, and a class Derived which inherits singly from this then (uintptr_t)derived - (uintptr_t)static_cast<Base*>(derived) is guaranteed (by the Itanium ABI) to be zero, even though Derived is not standard layout. However in the general case this is not necessarily true (eg. multiple inheritance). Is it possible to write a trait which can be used to detect if one class is the primary base class of another? Useful sections from the Itanium

How does pointer comparison work in C? Is it ok to compare pointers that don't point to the same array?

倾然丶 夕夏残阳落幕 提交于 2019-12-30 08:05:42
问题 In K&R (The C Programming Language 2nd Edition) chapter 5 I read the following: First, pointers may be compared under certain circumstances. If p and q point to members of the same array, then relations like == , != , < , >= , etc. work properly. Which seems to imply that only pointers pointing to the same array can be compared. However when I tried this code char t = 't'; char *pt = &t; char x = 'x'; char *px = &x; printf("%d\n", pt > px); 1 is printed to the screen. First of all, I thought

Print layout of C++ object with g++ compiler

风流意气都作罢 提交于 2019-12-29 06:45:32
问题 Is there a way to print the layout of a C++ object using the g++ compiler or any other means. A simplified example (assuming int takes 4 bytes) class A{ int a; }; class B:public A{ int b; } so the output would be A- 0 4 + a + B- 0 4 8 + A.a + b + It would be useful to understand the layout of objects (in my case virtual machine code). Thanks in advance. Regards, Zaheer 回答1: Looking at the man pages, -fdump-class-hierarchy maybe? 回答2: The information you seek is needed by debuggers and is