2015年8月6日 星期四

Visual Studio C++ Struct Sizeof


Intel Core i7-3770 @ 3.40Ghz
Windows 7 Professional 64-bit
Visual Studio 2010 Version 10.0.40219.1 SP1Rel

#include <iostream>
#include <vector>
#include <stdint.h>
#include "SortedPointerVector.h"
using namespace std;

typedef uint32_t PartPosition;
typedef uint32_t PartDataLength;
typedef uint16_t PartNumber;
typedef uint32_t PartSize;

typedef uint16_t FieldPosition;
typedef uint16_t FieldDataLength;
typedef uint32_t FieldListLength;
typedef uint32_t FieldListPosition;

typedef int16_t Fid;
typedef uint8_t FieldType;

struct Struct1 // 8
{
 double d; // 8
};
struct Struct2 // 4
{
 int i; // 4
};
struct Struct3 // 2
{
 short s; // 2
};
struct Struct4 // 1
{
 bool b; // 1
};
struct Struct5 // 8
{
 char * c; // 8
};

struct Struct11 // 16
{
 bool b; // 1
 short s; // 2
 int i; // 4
 double d; // 8
};
struct Struct12 // 16
{
 double d; // 8
 int i; // 4
 short s; // 2
 bool b; // 1
};
struct Struct13 // 24
{
 int i; // 4
 double d; // 8
 short s; // 2
 bool b; // 1
};
struct Struct14 // 24
{
 bool b; // 1
 double d; // 8
 short s; // 2
 int i; // 4
};

struct Struct21 // 8
{
 char c[8]; // 8
};
struct Struct22 // 9
{
 char c[9]; // 9
};
struct Struct23 // 17
{
 char c1[9];
 char c2[8];
};
struct Struct24 // 24, because 8,1,8
{
 char c1[9];
 double d;
};
struct Struct25 // 16, because 8,2
{
 double d; // 8
 char c[2]; // 2
};
struct Struct26 // 16, because 8,2
{
 char c[2]; // 2
 double d; // 8
};
struct Struct27 // 8
{
 int i; // 4
 char c[2]; // 2
};
struct Struct28 // 8
{
 char c[2]; // 2
 int i; // 4
};

struct Struct31 // 34, because 17+17
{
 Struct23 s1; // 17
 Struct23 s2; // 17
};
struct Struct33  // 48
{
 Struct24 s1; // 24 (8,1,8)
 Struct24 s2; // 24 (8,1,8)
};
struct Struct34  // 24, because 8,2,2,8
{
 Struct25 s1; // 16 (8,2)
 Struct26 s2; // 16 (2,8)
};
struct Struct35 // 24, because (16,1),4, align 4
{
 Struct23 s1; // 17
 int i; // 4
};
struct Struct36 // 28, because (16,1),4,1+1+1, align 4
{
 Struct23 s1; // 17
 int i; // 4
 bool b1; // 1
 bool b2; // 1
 bool b3; // 1
};
struct Struct37 // 28, because (16,1),4,1+1+1+1, align 4
{
 Struct23 s1; // 17
 int i; // 4
 bool b1; // 1
 bool b2; // 1
 bool b3; // 1
 bool b4; // 1
};
struct Struct38 // 32, because (16,1),4,1+1+1+1,1, align 4
{
 Struct23 s1; // 17
 int i; // 4
 bool b1; // 1
 bool b2; // 1
 bool b3; // 1
 bool b4; // 1
 bool b5; // 1
};
struct Struct39 // 40, because (8,8,1),8,1+1+1+1+1, align 8
{
 Struct23 s1; // 17
 double d; // 8
 bool b1; // 1
 bool b2; // 1
 bool b3; // 1
 bool b4; // 1
 bool b5; // 1
};
struct Struct40 // 16, because 4,2,2,4, align 4
{
 Struct27 s1; // 4,2
 Struct28 s2; // 2,4
};

struct InstrumentName // 65
{
 char name[64]; // 64
 uint8_t size; // 1
};

struct InstrumentNameWrapper1 // 65
{
 InstrumentName n; // 65
};

struct InstrumentNameWrapper2 // 66
{
 InstrumentName n; // 65
 bool b; // 1
};
struct InstrumentNameWrapper3 // 72, because 64,1+4
{
 InstrumentName n; // 65
 int i; // 4
};

struct InstrumentKey // 72, because 64,1,2,2,1+1, align 2
{
 InstrumentName name; // 65 (64+1)
 uint16_t domain; // 2
 uint16_t serviceID; // 2
 uint8_t nameType; // 1
 uint8_t qos; // 1
};

struct ConstituentKey // 1
{
 uint8_t constituentNumber;
};

struct PartSizes // 32
{
 std::vector<std::pair<PartNumber, PartSize>> contents;
};

struct PartDatas // 48, because 8,4,32, align 8
{
 char * data; // 8
 PartDataLength dataLength; // 4
    PartSizes partSizes; // 32
};

struct ConstituentData // 72, because 48,4+4,1+2+2+1+1+1,1+1, align 8
{
 PartDatas partDatas; // 48, align 8
 uint32_t pe; // 4
 uint32_t mask; // 4
 ConstituentKey key; // 1
 PartNumber lastPartNumber; // 2
 int16_t fieldListNumber; // 2
 uint8_t instrumentType; // 1
 bool isLastPartNumberKnown; // 1
 bool hasMultipleParts; // 1
 bool hasPE; // 1
 bool isContainShellMetaData; // 1
};

typedef SortedPointerVector<ConstituentKey, ConstituentData> ConstituentDataList; // 40

struct InstrumentContentData // 72, because 1+1+4,8,8,40,8
{
 uint8_t ll2Type; // 1
 bool isEverInstrumentAvailable; // 1
 uint32_t instrumentId; // 4
 int64_t lastUpdateTickCountInNanosec; // 8
 InstrumentKey * underlyingKey; // 8
 ConstituentDataList constituentDataList; // 40
 uint32_t mcLabel; // 4
};

struct InstrumentContentData2 // 64, because 40,8,8,4+2+1+1
{
 ConstituentDataList constituentDataList; // 40
 int64_t lastUpdateTickCountInNanosec; // 8
 InstrumentKey * underlyingKey; // 8
 uint32_t instrumentId; // 4
 uint16_t mcLabel; // 2
 uint8_t ll2Type; // 1
 bool isEverInstrumentAvailable; // 1
};

int main()
{
 cout << "primitive 1" << endl;
 cout << sizeof(Struct1) << endl;
 cout << sizeof(Struct2) << endl;
 cout << sizeof(Struct3) << endl;
 cout << sizeof(Struct4) << endl;
 cout << sizeof(Struct5) << endl;

 cout << "struct 11" << endl;
 cout << sizeof(Struct11) << endl;
 cout << sizeof(Struct12) << endl;
 cout << sizeof(Struct13) << endl;
 cout << sizeof(Struct14) << endl;

 cout << "array 21" << endl;
 cout << sizeof(Struct21) << endl;
 cout << sizeof(Struct22) << endl;
 cout << sizeof(Struct23) << endl;
 cout << sizeof(Struct24) << endl;
 cout << sizeof(Struct25) << endl;
 cout << sizeof(Struct26) << endl;
 cout << sizeof(Struct27) << endl;
 cout << sizeof(Struct28) << endl;

 cout << "compund 31" << endl;
 cout << sizeof(Struct31) << endl;
 cout << sizeof(Struct33) << endl;
 cout << sizeof(Struct34) << endl;
 cout << sizeof(Struct35) << endl;
 cout << sizeof(Struct36) << endl;
 cout << sizeof(Struct37) << endl;
 cout << sizeof(Struct38) << endl;
 cout << sizeof(Struct39) << endl;
 cout << sizeof(Struct40) << endl;

 cout << "real" << endl;
 cout << sizeof(InstrumentName) << endl;
 cout << sizeof(InstrumentKey) << endl;
 cout << sizeof(ConstituentDataList) << endl;
 cout << sizeof(InstrumentContentData) << endl;

 cout << "real 2" << endl;
 cout << sizeof(ConstituentData) << endl;
 cout << sizeof(PartDatas) << endl;
 cout << sizeof(PartSizes) << endl;


 cout << "real modified" << endl;
 cout << sizeof(InstrumentNameWrapper1) << endl;
 cout << sizeof(InstrumentNameWrapper2) << endl;
 cout << sizeof(InstrumentNameWrapper3) << endl;
 cout << sizeof(InstrumentContentData2) << endl;

 system("PAUSE");
}

沒有留言:

張貼留言

2023 Promox on Morefine N6000 16GB 512GB

2023 Promox on Morefine N6000 16GB 512GB Software Etcher 100MB (not but can be rufus-4.3.exe 1.4MB) Proxmox VE 7.4 ISO Installer (1st ISO re...