#include<list>
#include<iostream>
#include<string.h>
#include<string>
#include<stdlib.h>
typedef struct tagTest
{
char name[200];
int year;
}Test;
#define NUM 1
typedef struct tagInfo
{
//int count;
char c; //会对齐到8字节,无论是count或是char ,因为后面跟的std::list<>是以16个字节为单元的
std::list<Test> lTest[NUM];
}Info;
static Info g_info;
int main()
{
//std::list<Test> *lTest;
//g_info.lTest = static_cast<std::list<struct tagTest> *>(malloc(NUM * 4 ));
Test test1 = {0};
strncpy(test1.name, "chenyc", 8);
test1.year = 100;
for (int i=0;i<NUM;++i)
{
for(int j=0; j<200; ++j)
{
g_info.lTest[i].push_back(test1);
}
}
/*
for (int i=0;i<NUM;++i)
{
std::cout << g_info.lTest[i].begin()->name << std::endl;
}
*/
for (int i=0;i<NUM;++i)
{
std::cout << g_info.lTest[i].size() << " " << sizeof(g_info) << std::endl;
}
std::cout << sizeof(int) << " " << sizeof(std::list<int>) <<" " << sizeof(std::list<Test>)<< std::endl;
return 0;
}
输出:[root@vx-230 cyc]./list
200 24
4 16 16
转载请注明原文地址: https://ju.6miu.com/read-1126102.html