Some info about pointer vs value.
Vector of elements:
+Do not need to free/allocate memory for elements
+Keep it simple
+All elements memory allocated as one memory block - it increases cache hit and reduces memory fragmentation
+STL algorithms friendly
+Do not uses additional memory for pointer
Vector of pointers:
+Polymorphism
+If we don't know how much of memory we will need
+If we will need a lot of large objects
+Small pointers size useful for pointer to elements swaps
No comments:
Post a Comment