Page 1 of 1

Rename FreeArray() to ClearArray()

Posted: Tue Mar 26, 2013 5:26 pm
by Little John
For lists there are ClearList() and FreeList().
For maps there are ClearMap() and FreeMap().

FreeArray() does for arrays what ClearList() does for lists, and what ClearMap() does for maps.
This is not consistent, so better rename FreeArray() to ClearArray(). Also ClearArray() tells better what the function actually does.

Re: Rename FreeArray() to ClearArray()

Posted: Tue Mar 26, 2013 5:47 pm
by Josh
If you want this, after ClearArray() the Array hasn't to be initialized new with DIM, the count of elements has to be changed with REDIM.

Furthermore it would be consistent, allowing to create a "ClearArray" with -1.
See my discussion here.

Re: Rename FreeArray() to ClearArray()

Posted: Tue Mar 26, 2013 5:52 pm
by Fred
FreeArray() should really free the array, not only clear it.

Re: Rename FreeArray() to ClearArray()

Posted: Tue Mar 26, 2013 6:03 pm
by Little John
Fred wrote:FreeArray() should really free the array, not only clear it.
But as far as I can see it does not do so. FreeArray() only "redims" the array so to say, so that it is empty (has 0 elements).
For this reason, also the current documentation of FreeArray() IMHO is wrong or at least strongly misleading.

Re: Rename FreeArray() to ClearArray()

Posted: Tue Mar 26, 2013 6:14 pm
by Josh
To make Array, Lists and Maps really consistent, there should also be changes in declaration:

Define Array MyArray(0)
Define List MyList()
Define Map MyMap()

instead of:

Define Dim MyArray(0)
Define NewList MyList()
Define NewMap MyMap()

Re: Rename FreeArray() to ClearArray()

Posted: Tue Mar 26, 2013 6:29 pm
by freak
FreeList() releases the memory of the list elements and the internal list metadata.
FreeArray() releases the memory containing the array elements and the internal array metadata.

Where is the inconsistency?

Re: Rename FreeArray() to ClearArray()

Posted: Tue Mar 26, 2013 6:44 pm
by Psychophanta
Little John wrote:
Fred wrote:FreeArray() should really free the array, not only clear it.
But as far as I can see it does not do so. FreeArray() only "redims" the array so to say, so that it is empty (has 0 elements).
For this reason, also the current documentation of FreeArray() IMHO is wrong or at least strongly misleading.
I agree with Fred, there is needed real FreeArray(), FreeList()... commands. As the current ones only Redims to 0 elements.

Re: Rename FreeArray() to ClearArray()

Posted: Tue Mar 26, 2013 6:48 pm
by Josh
freak wrote:Where is the inconsistency?
There:

Code: Select all

Dim MyArray(0)
NewList MyList()

Debug ArraySize (MyArray())
Debug ListSize (MyList())

FreeArray (MyArray())
FreeList (MyList())

Debug ArraySize (MyArray())
Debug ListSize (MyList())
You can use the freed array also as parameter in procedures. Imho FreeArray is definitely a ClearArray.

Re: Rename FreeArray() to ClearArray()

Posted: Tue Mar 26, 2013 7:34 pm
by freak
So your problem is the difference between ListSize() and ArraySize() and not between FreeList() and FreeArray(). Just because ArraySize() has a return value to indicate a freed array doesn't mean that FreeArray() does not actually free the array.

> You can use the freed array also as parameter in procedures.

You can do the same with a list.

Re: Rename FreeArray() to ClearArray()

Posted: Tue Mar 26, 2013 9:50 pm
by Little John
freak wrote:So your problem is the difference between ListSize() and ArraySize() and not between FreeList() and FreeArray(). Just because ArraySize() has a return value to indicate a freed array doesn't mean that FreeArray() does not actually free the array.
You asked for an inconsistency, and Josh showed you an inconsistency.

He probably thought (and so did I), that the results of ArraySize() and ListSize() are correct and consistent. If so, then there is an inconsistency between FreeArray() and FreeList(). Otherwise there is an inconsistency between ArraySize() and ListSize() (or a bug somewhere).
freak wrote:> You can use the freed array also as parameter in procedures.

You can do the same with a list.
After having tested it now, I see that you are right: After calling FreeList(), the list can still be used without calling NewList. I was misguided by the documentation of FreeList() which is wrong then:
To use this list again later, NewList has to be called for it.

Re: Rename FreeArray() to ClearArray()

Posted: Wed Mar 27, 2013 1:27 am
by Thade
You Guys have Problems ...

What's next?
Clearing or Freeing each Variable?
x.d=1000

Oops this uses 8 Bytes of memory

FreeVariable(x.d)

:?:
:lol:

Re: Rename FreeArray() to ClearArray()

Posted: Wed Mar 27, 2013 5:56 am
by Little John
Thade wrote:You Guys have Problems ...

What's next?
Clearing or Freeing each Variable?
x.d=1000

Oops this uses 8 Bytes of memory

FreeVariable(x.d)

:?:
:lol:
Another "extremely helpful" contribution by Mr. Thade ...

Re: Rename FreeArray() to ClearArray()

Posted: Wed Mar 27, 2013 9:17 am
by Fred
Little John wrote:
freak wrote:So your problem is the difference between ListSize() and ArraySize() and not between FreeList() and FreeArray(). Just because ArraySize() has a return value to indicate a freed array doesn't mean that FreeArray() does not actually free the array.
You asked for an inconsistency, and Josh showed you an inconsistency.

He probably thought (and so did I), that the results of ArraySize() and ListSize() are correct and consistent. If so, then there is an inconsistency between FreeArray() and FreeList(). Otherwise there is an inconsistency between ArraySize() and ListSize() (or a bug somewhere).
freak wrote:> You can use the freed array also as parameter in procedures.

You can do the same with a list.
After having tested it now, I see that you are right: After calling FreeList(), the list can still be used without calling NewList. I was misguided by the documentation of FreeList() which is wrong then:
To use this list again later, NewList has to be called for it.
You can no more call AddElement() on a free'ed list, that's why NewList() is mandatory. It's still known by the compiler, so you can reference it in your code, but any access will fail (same for Map and Array).