什麼是最好的/最快的方式?結構或指針的結構?
結構結構的:
struct Sheet{
u8 status; // to check if empty ?
u8 reserve0;
u8 reserve1;
u8 reserve2;
struct words words[1024];
};
struct Book {
int id;
struct Sheet sheet[64];
};
在這種情況下,如何檢查sheet
表是空的或不?我需要爲每張表添加status
?
或
結構
struct Sheet{
u8 reserve0;
u8 reserve1;
u8 reserve2;
struct words words[1024];
};
struct Book {
int id;
struct Sheet* sheet[64];
};
的指針表,我不需要使用malloc
,因爲它們是固定的表。
在結構結構的,我可以通過設置status
但指針初始化結構,我可以bookinstance.sheet[] = NULL
或類似這樣的東西初始化。
我很迷茫與pointers
,struct
和malloc
。我來自Ruby
...
要明確:
我想不會超過64 sheet
我book
實例。也許只有3將被使用或64 ...但我希望能夠添加它們,並檢查它們從0到63的數字。
我也很迷茫......你想讓每本書精確地包含64頁,其中一些可能是空的(無效)?在這種情況下 - 是的,你可以維護一個64頁的指針數組,如果它們中的任何一個都是空的(無效的),那麼將它設置爲NULL。 –
然後我會用指針列表去。更好的初始化。 –