I'm trying to decide which I should use.
The pros of pointers to structures that I can think off the top of my head.
Any other pro's/con's for both sides?
There's a few other differences in these approaches:
struct
itself to express this);struct
rather than a copy. Again, this is only an advantage if this situation is semantically reasonable for your application;struct
s close together in the array are also close together in memory, which can be a performance advantage in some situations);An downside of using array of pointers, or pointers in general is:
Pointers would (most likely)involve using dynamic memory allocations and that implies manual management of this dynamic memory.
Dynamic memory allocations are little slower than stack allocations.
Also, using dynamic memory is more usage error prone.
Having said that, which one to choose actually depends on:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With