c - What's wrong in this allocation? -
this struct declared :-
struct page_table_entry { struct addrspace* as; vaddr_t va; //page_state_t state; int timestamp; };
now want dynamically allocate memory array of this. implementation here :-
struct page_table_entry **coremap = (struct page_table_entry**) kmalloc(npages*sizeof(struct page_table_entry*)); int i; for(i=0;i<npages;i++) { coremap[i] = (struct page_table_entry*)kmalloc(sizeof(struct page_table_entry)); coremap[i].va=(firstaddress+(i*page_size)); }
its giving me error on last line accesing variable va. error is:-
error: request member `va' in not structure or union
you have array of pointers structs, not array of structs.
in line coremap[i] = (struct page_table_entry*)kmalloc(sizeof(struct page_table_entry)); cast memory allocation page_table_entry*
, coremap[i] pointer.
you access actual struct via
coremap[i]->va=(firstaddress+(i*page_size));
Comments
Post a Comment