例えば、私はこのような構造とコードを有する:このような構造とコード対構造体内の変数にメモリを割り当てる最良の方法は何ですか?
typedef struct
{
long long *number;
} test;
test * test_structure;
test_structure = malloc(sizeof(test));
test_structure->number = malloc(sizeof(long long) * 100);
free(test_structure->number);
free(test_structure);
を:
typedef struct
{
long long number[100];
} test;
test * test_structure;
test_structure = malloc(sizeof(test));
free(test_structure);
iは数値列は、常に100であることがわかっているので、これらの方法のいずれかが完全です受け入れられる、または一方の方法よりも他のより良いです、そしてなぜですか?