Rename FreeArray() to ClearArray()
-
- Addict
- Posts: 4779
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
Rename FreeArray() to ClearArray()
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.
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()
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.
Furthermore it would be consistent, allowing to create a "ClearArray" with -1.
See my discussion here.
sorry for my bad english
Re: Rename FreeArray() to ClearArray()
FreeArray() should really free the array, not only clear it.
-
- Addict
- Posts: 4779
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
Re: Rename FreeArray() to ClearArray()
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).Fred wrote:FreeArray() should really free the array, not only clear it.
For this reason, also the current documentation of FreeArray() IMHO is wrong or at least strongly misleading.
Re: Rename FreeArray() to ClearArray()
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()
Define Array MyArray(0)
Define List MyList()
Define Map MyMap()
instead of:
Define Dim MyArray(0)
Define NewList MyList()
Define NewMap MyMap()
sorry for my bad english
Re: Rename FreeArray() to ClearArray()
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?
FreeArray() releases the memory containing the array elements and the internal array metadata.
Where is the inconsistency?
quidquid Latine dictum sit altum videtur
- Psychophanta
- Always Here
- Posts: 5153
- Joined: Wed Jun 11, 2003 9:33 pm
- Location: Anare
- Contact:
Re: Rename FreeArray() to ClearArray()
I agree with Fred, there is needed real FreeArray(), FreeList()... commands. As the current ones only Redims to 0 elements.Little John wrote: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).Fred wrote:FreeArray() should really free the array, not only clear it.
For this reason, also the current documentation of FreeArray() IMHO is wrong or at least strongly misleading.
Re: Rename FreeArray() to ClearArray()
There:freak wrote:Where is the inconsistency?
Code: Select all
Dim MyArray(0)
NewList MyList()
Debug ArraySize (MyArray())
Debug ListSize (MyList())
FreeArray (MyArray())
FreeList (MyList())
Debug ArraySize (MyArray())
Debug ListSize (MyList())
sorry for my bad english
Re: Rename FreeArray() to ClearArray()
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.
> You can use the freed array also as parameter in procedures.
You can do the same with a list.
quidquid Latine dictum sit altum videtur
-
- Addict
- Posts: 4779
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
Re: Rename FreeArray() to ClearArray()
You asked for an inconsistency, and Josh showed you an inconsistency.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.
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).
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:freak wrote:> You can use the freed array also as parameter in procedures.
You can do the same with a list.
To use this list again later, NewList has to be called for it.
Re: Rename FreeArray() to ClearArray()
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)

What's next?
Clearing or Freeing each Variable?
x.d=1000
Oops this uses 8 Bytes of memory
FreeVariable(x.d)


--------------
Yes, its an Irish Wolfhound.
Height: 107 cm; Weight: 88 kg
Yes, its an Irish Wolfhound.
Height: 107 cm; Weight: 88 kg
-
- Addict
- Posts: 4779
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
Re: Rename FreeArray() to ClearArray()
Another "extremely helpful" contribution by Mr. Thade ...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)
![]()
Re: Rename FreeArray() to ClearArray()
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).Little John wrote:You asked for an inconsistency, and Josh showed you an inconsistency.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.
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).
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:freak wrote:> You can use the freed array also as parameter in procedures.
You can do the same with a list.To use this list again later, NewList has to be called for it.