KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Clearing dynamic arrays on Windows
PRODUCT: 4D | VERSION: 2004 | PLATFORM: Win
Published On: August 7, 2006

You may run into a problem with 4D on Windows related to clearing multiple dynamic arrays (i.e. setting the array size to 0). The term "dynamic" refers to any arrays that are not fixed size, e.g. Text, BLOB, etc.

The problem is that it can take an significant amount of time to clear the arrays. For example, this method takes a significant amount of time to execute on a Windows machine:

`=====
C_LONGINT($size;$i;$start;$end)
$size:=100000
$start:=Milliseconds
ARRAY TEXT($text;$size)
ARRAY TEXT($text2;$size)
For ($i;1;$size)
  $text{$i}:="blahdeblahblah"+String($i)
  $text2{$i}:="blahdeblahblah"+String($i)
End for
ARRAY TEXT($text;0)
ARRAY TEXT($text2;0)
$end:=Milliseconds
`=====

However, if you simply set all of the array elements to the empty string ("") the method executes very quickly (in fact, faster than a method that contains a single array with 100,000 non-empty elements):

`=====
C_LONGINT($size;$i;$start;$end)
$size:=100000
$start:=Milliseconds
ARRAY TEXT($text;$size)
ARRAY TEXT($text2;$size)
For ($i;1;$size)
  $text{$i}:="blahdeblahblah"+String($i)
  $text2{$i}:="blahdeblahblah"+String($i)
End for
For ($i;1;$size)
  $text{$i}:=""
  $text2{$i}:=""
End for
ARRAY TEXT($text;0)
ARRAY TEXT($text2;0)
$end:=Milliseconds
`=====