Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Clearing an array
#3
(01-20-2021, 11:30 AM)Ljg701 Wrote:
(01-19-2021, 10:47 PM)patters Wrote: What is the recommended way to reset an array's contents? Do we have to run a FOR loop from 0 TO UBOUND and clear it element by element, or is there a neater way?
I see that the following doesn't work:

Code:
arrayName={}

You could get the address of the start of the array and then use the MemSet method in the memcopy library to clear it quickly?

That's it. Exclamation

A proposal (I think even commented in this forum):
Code:
CLEAR array
or
Code:
CLEAR array, <new value>
but it's not implemented.

Instead you should perhaps use memset:
Code:
#include <memcopy.bas>

DIM myArray(10, 20) as UByte => 11 rows x 21 cols if using array_base 0
..
memset(@myArray(0, 0), 0, 11 * 21)

When dynamics array are implemented you could also ReDIM them... meanwhile...
Finally, remember you can assign (copy) entire arrays (myArray1 = myArray2) provided they are of the same shape and type.
Reply


Messages In This Thread
Clearing an array - by patters - 01-19-2021, 10:47 PM
RE: Clearing an array - by Ljg701 - 01-20-2021, 11:30 AM
RE: Clearing an array - by boriel - 01-20-2021, 02:15 PM
RE: Clearing an array - by patters - 01-26-2021, 01:04 AM
RE: Clearing an array - by worcestersource - 04-15-2021, 08:27 PM
RE: Clearing an array - by boriel - 04-16-2021, 10:43 AM
RE: Clearing an array - by worcestersource - 04-16-2021, 08:00 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)