Questions tagged [object-layout]
24 questions
3
votes
1 answer
How to interpret an instance's mark word?
I am trying to make sense of the output of Java object layout on a 64-bit HotSpot VM (v8). I do not understand how the first three bit of the mark word are used which according to the commentary in the linked class file should indicated weather a…

Rafael Winterhalter
- 42,759
- 13
- 108
- 192
3
votes
6 answers
C++ object memory layout
I am trying to understand the object layout for C++ in multiple inheritance.
For this purpose, I have two superclasses A, B and one subclass C.
What I expected to see when trying dumping it was:
vfptr | fields of A | vfptr | fields of B | fields…

ginou
- 73
- 1
- 6
2
votes
1 answer
Heap Object representation for OO language
As part of my masters thesis I am writing a compiler for an object oriented language that was developed at my home university. Currently the compiler outputs assembler that runs on a virtual machine. The virtual machine handles all things like stack…

halfdan
- 33,545
- 8
- 78
- 87
2
votes
1 answer
Layout of an object
I want to understand the layout of an object. So I executed with different orders of member variables. Everything came as expected, expect for following sequence.
#include
using namespace std;
class Test1
{
public:
int m_a;
char…

K.K
- 311
- 1
- 7
- 17
1
vote
4 answers
pointer to object == pointer to first member?
Why does the if condition in the following code yield true?
struct A
{
int firstMember;
} a1;
if (&a1 == static_cast(&a1.firstMember)) std::cout << "equal";
I got a bit confused when reading Stroustrup's FAQ on empty classes,…

Chenna V
- 10,185
- 11
- 77
- 104
1
vote
1 answer
Will a standard_layout class's data member have a fixed offset from the object's address?
If a class is_standard_layout, is that sufficient to guarantee that a given non-static data member will always have the same offset from the object's address (i.e. same across different instances of that class, process-wide)?

Museful
- 6,711
- 5
- 42
- 68
1
vote
1 answer
How member functions' additional syntax/specifiers affect memory layout in classes?
I think I have a clear understanding of class data members and their in-memory representation:
The members of a class define the layout of objects: data members are stored one after another in memory. When inheritance is used, the data members of…

Ziezi
- 6,375
- 3
- 39
- 49
1
vote
2 answers
the value of pointer to data member in C++
Meet a very weird problem, anyone know what is the reason of this? the code is tested under Visual Studio 2012.
#include
struct A {
int a;
};
struct B {
int b;
};
struct C : public A, public B {
int c;
};
int main() {
int C::*p =…

Xiaotian Pei
- 3,210
- 21
- 40
1
vote
2 answers
casting and object layout
I was trying to understand the layout of an object by casting following two unrelated classes:
class A
{
public:
A(int x):_a(x){}
private:
int _a;
};
class B
{
public:
void Show()
{
cout << "&_x = " << &_x << "," << " _x = " << _x <<…

Arun
- 3,138
- 4
- 30
- 41