Reputation: 573
I'm trying to write a program in C which is a basic simulation of a CPU scheduler.
There will be 10 processes (represented by structs) that will be moved from a CPU queue to the I/O queue and so on.
I initially began to declare the process structs as an array, but it seems cumbersome to me to move the structs straight from an array into the CPU queue. It seems equally bad to intialise and declare 10 separate structs outside an array.
Can someone suggest to me which approach would be better?
Upvotes: 2
Views: 93
Reputation: 12670
An array of struct pointers would work nicely for your purposes. The pointers can be moved in the queue at very little expense and all references will update the same object instead of having to worry about copy semantics.
Upvotes: 4