memory-layout

Determine the size of object without its virtual table pointers

主宰稳场 提交于 2019-12-13 15:19:26
问题 Is there a generic way (not platform dependent) to get at compile time the size of a class object in the memory, without counting the vtable pointers? 回答1: As you are asking for a portable way: class MyClass { private: struct S { DataMemberType1 dataMember1; ... DataMemberTypeN dataMemberN; } m; public: static const size_t MemberSize = sizeof(S); }; 回答2: Use sizeof on this class , it doesn't include size of the vtable just the pointer. 来源: https://stackoverflow.com/questions/28433973

Does linux provide a guaranteed inaccessible memory area below the lower stack end?

感情迁移 提交于 2019-12-13 12:29:46
问题 Does Linux provide an inaccessible memory area below the lower stack end that has a guaranteed minimum size? And if such a guaranteed minimum size exists, what is it? Or in other words, when should I start to worry about alloca() or so giving me pointers into valid, non-stack memory? 回答1: As the alloca man page says: There is no error indication if the stack frame cannot be extended. (However, after a failed allocation, the program is likely to receive a SIGSEGV signal if it attempts to

Converting DirectX11 ID3D11Texture2D from Shader into OpenCV IplImage

北慕城南 提交于 2019-12-13 05:31:57
问题 Short introduction : I have written an Augmented Reality Application with the Oculus Rift in C++ (DirectX). One of my fragment shaders computes the undistortion for a omnidirectional camera model. The only Problem I have now is to read out the rendered undistortion texture2D and convert it further for 3DPose Tracking/Mapping of the real world using OpenCV. The funny Thing is, I have already done the other way around, which means I have already created shader resource views with my distorted

Are Sub-Arrays Guaranteed to be Allocated Linearly? [duplicate]

China☆狼群 提交于 2019-12-12 19:31:51
问题 This question already has answers here : C / C++ MultiDimensional Array Internals (4 answers) Closed 3 years ago . I know this answer is in violation of the reinterpret_cast rules but it also presumes that sub-arrays will be allocated linearly. I believed this was not guaranteed, but as I search the standard, I find my confidence wavering. If I statically allocate a 2D array, like this: int foo[][4] = { { 5, 7, 8 }, { 6, 6 }, {}, { 5, 6, 8, 9 } }; Am I allowed to assume that all elements will

What's the purpose of layout-compatible types?

我与影子孤独终老i 提交于 2019-12-12 08:02:41
问题 The standard defines when two types are layout-compatible . But, I don't see anywhere in the standard what the consequences are when two types are layout-compatible . It seems that layout-compatible is a definition which is not used anywhere. What is the purpose of layout-compatible ? Note: Supposedly, it could mean that the types have the same layout ( offsetof is the same for each corresponding member), so for example, for trivially copyable types, underlying bytes can be copied between

Fortran reshape - N-dimensional transpose

自闭症网瘾萝莉.ら 提交于 2019-12-10 20:34:39
问题 I'm trying to write some code in Fortran which requires the re-ordering of an n-dimensional array. I thought the reshape intrinsic combined with the order argument should allow this, however I'm running into difficulties. Consider the following minimal example program test implicit none real, dimension(:,:,:,:,:), allocatable :: matA, matB integer, parameter :: n1=3, n2=5, n3=7, n4=11, n5=13 integer :: i1, i2, i3, i4, i5 allocate(matA(n1,n2,n3,n4,n5)) !Source array allocate(matB(n3,n2,n4,n1

What does SEGMENT_START(“text-segment”, 0x400000) represent?

丶灬走出姿态 提交于 2019-12-10 20:18:56
问题 I'm learning about the layout of executable binaries. My end goal is to analyze a specific executable for things that could be refactored (in its source) to reduce the compiled output size. I've been using https://www.embeddedrelated.com/showarticle/900.php and https://www.geeksforgeeks.org/memory-layout-of-c-program/ as references for this initial learning. From what I've learned, a linker script specifies the addresses where sections of compiled binaries are placed. E.g. > ld --verbose |

Why sizeof(Derived4) is 8 byte? I think it should be 5 bytes

一笑奈何 提交于 2019-12-10 20:14:26
问题 This is the output of the given program: sizeof(Empty) 1 sizeof(Derived1) 1 sizeof(Derived2) 4 sizeof(Derived3) 1 sizeof(Derived4) 8 sizeof(Dummy) 1 This is the program: #include <iostream> using namespace std; class Empty {}; class Derived1 : public Empty {}; class Derived2 : virtual public Empty {}; class Derived3 : public Empty { char c; }; class Derived4 : virtual public Empty { char c; }; class Dummy { char c; }; int main() { cout << "sizeof(Empty) " << sizeof(Empty) << endl; cout <<

Virtual class inheritance object size issue

扶醉桌前 提交于 2019-12-10 19:05:41
问题 Here, in this code, the size of ob1 is 16 which is fine(because of the virtual pointer) but I can't understand why the size of ob2 is 24. #include <iostream> using namespace std; class A { int x; }; class B { int y, z; }; class C : virtual public A { int a; }; class D : virtual public B { int b; }; int main() { C ob1; D ob2; cout << sizeof(ob1) << sizeof(ob2) << "\n"; } I expect the size of ob2 as 20, but the output is 24 回答1: One possible layout for objects of type D is: +----------+ | y |

Why does Rust use two bytes to represent this enum when only one is necessary?

强颜欢笑 提交于 2019-12-10 17:35:51
问题 It appears to be smart enough to only use one byte for A, but not smart enough to use one byte for B, even though there are only 8*8=64 possibilities. Is there any way to coax Rust to figure this out or do I have to manually implement a more compact layout? Playground link. #![allow(dead_code)] enum A { L, UL, U, UR, R, DR, D, DL, } enum B { C(A, A), } fn main() { println!("{:?}", std::mem::size_of::<A>()); // prints 1 println!("{:?}", std::mem::size_of::<B>()); // prints 2 } 回答1: Both bytes