BBC BASIC for Windows
« Loss of Array data »

Welcome Guest. Please Login or Register.
Apr 6th, 2018, 12:30am



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

If you require a dump of the post on your message board, please come to the support board and request it.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Loss of Array data  (Read 691 times)
Matt
Developer

member is offline

Avatar




PM

Gender: Male
Posts: 210
xx Re: Loss of Array data
« Reply #2 on: Jul 21st, 2013, 05:21am »

Hi,

Just noticed my last reply to this seems to have been sucked up into the ether.

on Jul 19th, 2013, 8:47pm, Richard Russell wrote:
You mustn't swap a local array with a global array. The BB4W docs call this out:

"LOCAL arrays are stored on the stack and special precautions are required as a result. Firstly, avoid swapping a local array with a global array (i.e. one stored on the heap).... You can safely copy the array, because the data is copied rather than the pointer"

I hadn't realised this as I have only read the main help on it. But that's fine. I only need to copy the ndx%() to Index%() so I'll use the loop.

I assume, by trial and error, that Index%() = ndx%() only copies the pointers as well.

I would still be interested to know why the array was cleared before the DIM and then restored after with no apparent movemement of data or pointers, and in this case only during the second pass.

Matt
User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx Re: Loss of Array data
« Reply #3 on: Jul 21st, 2013, 06:51am »

on Jul 21st, 2013, 05:21am, Matt wrote:
I assume, by trial and error, that Index%() = ndx%() only copies the pointers as well.

Huh? My previous reply (second example) shows that the opposite is the case, and the docs also state explicitly "You can safely copy the array, because the data is copied rather than the pointer". Note the comments in this code taken from the docs:

Code:
      SWAP globalarray(),localarray() : REM Don't do this!
      globalarray() = localarray() : REM This is OK
 

Anyway, think about it. Copying pointers wouldn't copy the array, it would create an alias of the array: modifying the contents of one would cause the contents of the other to change!

Quote:
I would still be interested to know why the array was cleared before the DIM and then restored after with no apparent movemement of data or pointers, and in this case only during the second pass.

Clearly what you describe, taken literally, is impossible. Trying to find out what actually did happen could be difficult and ultimately will only confirm that swapping a local and global array is a very bad idea!

Richard.
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls