Relative Content

Tag Archive for arrayscarraylistdata-structuresmemory-management

Which one of the following aproaches is the best one to implement a dynamic array in C? Array objects vs array of pointers to objects?

I was trying to implement a dynamic array in C, much like Arraylist of Java. The initial idea was to use an array of the actual objects to avoid side effects(having dangling pointers) whenever a object is delete from outside of the arraylist and have all the object preallocated, that is, instead using array of pointers and having of them living in a fragmented memory locations and having to use a loop to deallocated each one of them one by one, I wanted them to be stored in contiguous manner so that I could delete all of them at once with a single call to free.