Dynamic Arrays and DAM

Sep 29, 2012 at 12:55pm
Hey I need a way to check if a Dynamic Array is full. I am writing a check program for class saying once an array is full I have a function that creates a new array (doubled in size) and moves all the elements into it. I was able to create it, but I want to create an if/else statement that tells the program when to call the doubleArray function. Any ideas?
Sep 29, 2012 at 1:05pm
You need to keep the size of the array around, along with how many elements are actually occupied. Then you just compare the two numbers.
Sep 29, 2012 at 1:13pm
so I can say something like, when i = size (where size is the amount of elements in the array) call the doubleArray function? Is it really that simple? haha thanks!
Sep 29, 2012 at 2:03pm
Turn your array into a container? Put it inside a class, alongside a size_t variable that stores its size, and write overloaded operators that let you treat it as a normal array, but automatically check and re-allocate memory if needed (or just use an existing container).
Sep 29, 2012 at 2:52pm
I have no idea what that is... thats why, its only my second semester of programming and it just started.
Sep 29, 2012 at 2:55pm
In that case, never mind. Just stick to the manual size check whenever you use the array.
Topic archived. No new replies allowed.