Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CLEAR
#1
How do I clean an ARRAY?

I would like to use the function CLEAR.

Code:
VAR A(3) TYPE INTEGER

PROCEDURE CLEAR (v)
FOR i = ADDRESS(v) TO ADDRESS(v)+SIZE(v)-1
  POKE i,0
NEXT i
END PROCEDURE

PROCEDURE Clean
CLEAR A
END PROCEDURE

PROCEDURE Test
LET A(1) = 1
PRINT A(1)
Clean
PRINT A(1)
END PROCEDURE
Reply
#2
There is a faster way, use memset:

Code:
#include <memcopy.bas>

PROCEDURE CLEAR (v)
    MEMCOPY(ADDRESS(v), 0, SIZE(v))
END PROCEDURE

Please, try this and tell me if it works.

Also, I'm curious: How did you implement ADDRESS(v) and SIZE(v), they can be useful and included in the compiler.
(The next version will have changes and will update the standard library).
Reply
#3
I have not implemented these functions.
I was hoping you had already implemented them.
Reply
#4
No. To get the address of an element, you normally use the @ operator.
I.e. @a returns the memory address (uInteger) of the [a] variable. For arrays, @arr won't work as expected as it will return the address of the array's metadata. To get the address of the 1st element you will use @arr(0, 0).

I will come back with a solution on the size, but it might be not that strightforward.
Reply
#5
CLEAR an array would be very useful.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)