구조체를 malloc 할때 멤버의 메모리 주소가 겹칩니다

heartthief의 이미지

구조체 2개를 만들어서 할당하는데 malloc 하면 멤버의 메모리 주소가 겹치네요. 구조체 하나는 안에 다른 구조체를 포함하고 있고

또 다른 하나는 이중 포인터로 배열생성해서 malloc 했습니다.

typedef struct ListCoreHeader
{
	int length;
	struct ListCore *head;
	struct ListCore *tail;
}ListCoreHeader;
 
typedef struct Solution_List	
{	
	ListCoreHeader Gene[8];		
} Solution_List;
 
typedef struct Solution_Matrix
{
	int tasknum;
	int core;
	int order;
} Matrix;
 
List = (Solution_List*)malloc(sizeof(Solution_List)*300);
 
Matrix = (Solution_Matrix**)malloc(sizeof(Solution_Matrix*)*300);
for ( i=0 ; i<300 ; i++ ) {
	Matrix[i] = (Solution_Matrix*)malloc(sizeof(Solution_Matrix)*1000);			
}

제가 메모리 크기를 잘못 할당한건가요?

heartthief의 이미지

확인해보니 다른 부분에서 오류가 나서 메모리 크기가 잘못 할당되었네요;

익명 사용자의 이미지

Matrix 구조체에 메모리할당을 왜 하는지 잘 저는 이해가 안되네요. Matrix 구조체가 메모리변수도 아니고..

뭔가 순서대로 할당해야 할꺼 같은데 중간 코드만 보여주신 건지 잘 모르겠네요.

저런식으로 코딩하면 나중에 저 구조체 안의 메모리할당까지 모두 기억해야 하는데, 깜박할 경우가 발생할 수도 있을 듯 합니다.