Flexible array problem
Author |
Message |
Raknarg
![](http://compsci.ca/v3/uploads/user_avatars/3745510004d8be6689b92f.jpg)
|
Posted: Sun May 01, 2011 7:46 pm Post subject: Flexible array problem |
|
|
So is it possible to set the upper limit of a flexible array to a pointer value and just change that to change the value? If so, is there an easier way? (don't quite understand pointers) ![Razz Razz](http://compsci.ca/v3/images/smiles/icon_razz.gif) |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Insectoid
![](http://compsci.ca/v3/uploads/user_avatars/13760332514cbd0ce972eaa.jpg)
|
Posted: Sun May 01, 2011 8:05 pm Post subject: RE:Flexible array problem |
|
|
I don't think so. Turing appears to use a very basic array (just a special pointer + a size). This means when you create an array, Turing allocates a block of memory exactly large enough to contain that array. You cannot just increase the size because something else might have taken up the next few blocks of RAM.
A flexible array isn't flexible at all. If you 'resize' an array, Turing just creates a new array, and copies all elements of the old array into the new one (and then deletes the old one).
If you COULD assign the upper limit to a pointer, changing the pointer and trying to access the 'new cells' would likely return an array index out of bounds error. |
|
|
|
|
![](images/spacer.gif) |
Raknarg
![](http://compsci.ca/v3/uploads/user_avatars/3745510004d8be6689b92f.jpg)
|
Posted: Mon May 02, 2011 9:03 am Post subject: RE:Flexible array problem |
|
|
ok thanks
+1 karma |
|
|
|
|
![](images/spacer.gif) |
|
|