07-19-2011 11:12 PM
I need a array of clusters to be stored for which the length is not defined. I will update, Add new element to it.
Array or queue can be used to store the clusters. Which one would be better to use in terms of memory usage, fast execution and other performance parameters.
I have some other doubts also.
Consider an array of 8 elements. When an new element is added to the array using 'insert into array',
whether a new copy of 9 elements will be created? or 9th element will be linked after the 8th element (like linked lists)? or something else happens?
If a new copy is created, what happens to old 8 elements in the memory, whether that memory will be freed or kept as such?
The same doubt in case of queue also...
Thanks in advance..
Solved! Go to Solution.
07-20-2011 04:45 AM
In your case, you want to use a queue.
An array is stored in RAM in consecutive memory locations. When increasing the size of the array, the data structure is increased in size and often entirely moved to a place where it can all fit. If you are resizing an array inside a fairly fast loop, the performance hit would be noticeable.
A Queue is able to place individual elements in their own address chunks in RAM and is much more performance-friendly.
07-20-2011 05:41 AM
if you want your array to be a FIFO I think the queue is the better choice, but if you need to insert a element at a particular place in the array then array would be better.
07-20-2011 08:08 AM - edited 07-20-2011 08:11 AM
I also need to search for a particular element and remove it. 'Search 1D array' will be useful here.
In my case, Array may suit my purpose. I think, it is better to predefine the size of the array for memory concern.
Is there any way to update a particular element/delete in a queue?
@Roderic Thanks.
I do not want to insert element at particular place. I need to append to array,update an existing element in the array and remove any element in the array.
07-20-2011 08:11 AM
you can define an index in the replace and delete subset functions
07-20-2011 08:45 AM - edited 07-20-2011 08:45 AM
Well as far as I'm aware, you can't remove an element at a particular place, or you'll have to dequeue element, store them, delete the particular element then enqueue all elements. So IMO you should use an array for your application.