struct {
unsigned char b;
unsigned char g;
unsigned char r;
}pRBG[1024][1024];
如上,我需要创建一个1024*1024的结构体二位数组,但是超过了内存上限,得动态分配内存,我想用malloc来实现,但不知道具体代码怎么写,求大佬帮忙解惑
struct {
unsigned char b;
unsigned char g;
unsigned char r;
}pRBG[1024][1024];
如上,我需要创建一个1024*1024的结构体二位数组,但是超过了内存上限,得动态分配内存,我想用malloc来实现,但不知道具体代码怎么写,求大佬帮忙解惑
#define DEFAULT_ROW_COUNT 1024
#define DEFAULT_COLUMN_COUNT 1024
struct RBG {
unsigned char b;
unsigned char g;
unsigned char r;
};
RBG** pData = (RBG**)malloc(sizeof(RBG*) * DEFAULT_ROW_COUNT);
for (size_t i = 0; i != DEFAULT_ROW_COUNT; ++i)
{
pData[i] = (RBG*)malloc(sizeof(RBG) * DEFAULT_COLUMN_COUNT);
}
// Delete
for (size_t i = 0; i != DEFAULT_ROW_COUNT; ++i)
{
free(pData[i]);
}
free(pData);