Extending the maximum array size

Hello.

I am curious about the maximum array dimension (65535) and I was wondering whether or not there was a way to extend this.

One time I had an array of size 10, and I was using memset() to set 20 positions in this array to some value and this corrupted the object and caused my program to fail when deconstructing until i realised.

So I was wondering whether or not there could be a way to create one array, and then create another array so that it is physically next to the first array in memory so that when you try and put some value in array position 65539 (for example) it will simply be placed in the array next to the first.
There is no limit on array sizes.

So I was wondering whether or not there could be a way to create one array, and then create another array so that it is physically next to the first array in memory so that when you try and put some value in array position 65539 (for example) it will simply be placed in the array next to the first.

No, because you cannot guarantee that there is enough free memory right next to the previous array.
In fact, it is very unlikely if you've made other allocations in the meantime.
When you want to resize an array, you can create a new, larger array, copy the old values to the new array and deallocate the old one.
However, it would be madness to do this manually - that's what std::vector is for.
Thanks for the reply.

This is very strange because I remember getting an annoying error every time I tried to exceed the apparent maximum array size of "65535" however I am no longer getting this message!!! However I just wrote a short program that utilised an array with 70000 spaces in it and it worked fine.

Thanks for the info concerning the rubbish memory idea. It actually seems rather foolish that I even asked after you pointed out those now obvious flaws!

:P

Edit: I just remembered where I was getting this array limit error message. It is on an old version of Debian linux that I run on a different machine to the one I write my code on (which has a new version of Debian). Could this old linux version perhaps explain the limitation of 65535 sized arrays?
Topic archived. No new replies allowed.