a********e 发帖数: 508 | 1 这个题啥意思?难道在内存中不是class member按先后顺序存在的?
哪位能解释一下吗?谢谢
How to find out the memory layout of a class without initiate the class |
P*****s 发帖数: 758 | |
c****o 发帖数: 1280 | 3 答案是俺也不确定,他就说set up a class pointer and point it to 0, and then
you
will know it. Never tried it myself though。。。。。。。。。。我当时就想问知
道了又
怎样???????????
【在 P*****s 的大作中提到】 : 坐等chimbo大牛来解答。。。
|
a********e 发帖数: 508 | 4 依然困惑中,得到一个null pointer然后怎么就知道了呢。。。
【在 c****o 的大作中提到】 : 答案是俺也不确定,他就说set up a class pointer and point it to 0, and then : you : will know it. Never tried it myself though。。。。。。。。。。我当时就想问知 : 道了又 : 怎样???????????
|
j********t 发帖数: 97 | 5 可能因为某些memory layout是compiler dependent的。比如virtual function的实现
standard C++没有明确规定,不同compiler实现可能有不同。多重继承也类似,另外编译器本身的一些优化,像alignment,也是depends。某些诡异的场合,才需要了解这些内部结构。
一般在debuger里看或者用特殊编译选项导出。这个NULL pointer也是在debugger里看的吗? |
a********e 发帖数: 508 | 6 这个意思啊。试了一下,定义成null pointer确实可以看到
挺诡异的问题
编译器本身的一些优化,像alignment,也是depends。某些诡异的场合,才需要了解这
些内部结构。
看的吗?
【在 j********t 的大作中提到】 : 可能因为某些memory layout是compiler dependent的。比如virtual function的实现 : standard C++没有明确规定,不同compiler实现可能有不同。多重继承也类似,另外编译器本身的一些优化,像alignment,也是depends。某些诡异的场合,才需要了解这些内部结构。 : 一般在debuger里看或者用特殊编译选项导出。这个NULL pointer也是在debugger里看的吗?
|
y****e 发帖数: 28 | 7 So the answer of the original question is to first define a null pointer of
the class and then read the memory layout in the debugger.
I don't like the second part. Is it ever possible to get the memory layout
without using the debugger?
A very strange interview question.
【在 a********e 的大作中提到】 : 这个意思啊。试了一下,定义成null pointer确实可以看到 : 挺诡异的问题 : : 编译器本身的一些优化,像alignment,也是depends。某些诡异的场合,才需要了解这 : 些内部结构。 : 看的吗?
|
j********t 发帖数: 97 | 8 Use -fdump-class-hierarchy flag for g++ to dump memory layout without
debugger.
http://cplusplus.co.il/2010/10/31/thunksgiving/
Or use /d1reportAllClassLayout for VC++.
http://thetweaker.wordpress.com/2010/11/07/d1reportallclasslayo
of
【在 y****e 的大作中提到】 : So the answer of the original question is to first define a null pointer of : the class and then read the memory layout in the debugger. : I don't like the second part. Is it ever possible to get the memory layout : without using the debugger? : A very strange interview question.
|
a********e 发帖数: 508 | 9 这个也太technical了吧。。。
【在 j********t 的大作中提到】 : Use -fdump-class-hierarchy flag for g++ to dump memory layout without : debugger. : http://cplusplus.co.il/2010/10/31/thunksgiving/ : Or use /d1reportAllClassLayout for VC++. : http://thetweaker.wordpress.com/2010/11/07/d1reportallclasslayo : : of
|