Page 1 of 1

[Implemented] GetArraySize and GetArrayElements

Posted: Wed Feb 15, 2006 6:44 pm
by remi_meier
Sorry if I have overlooked this, but I cannot find something equal to
CountList for arrays!
Even if I think CountList should be renamed to ListCount, I wish something
like this for arrays, too! It is very important for arrays as parameters!

Add these macros (or functions) by default:

Code: Select all

Macro GETARRAYSIZE(Array)
	PeekL(arr() - 8) * PeekL(Arr() - 20)
EndMacro

Macro GETARRAYELEMENTS(Array)
	PeekL(arr() - 8)
EndMacro


Procedure test(arr.q(1))
	Protected Dim arr2.q(GETARRAYELEMENTS(arr()) - 1)
	
	CopyMemory(arr(), arr2(), GETARRAYSIZE(arr()))
	For z = 0 To GETARRAYELEMENTS(arr2()) - 1
		Debug arr2(z)
	Next
EndProcedure



Dim array.q(20)

For z = 0 To 20
	array(z) = z
Next

test(array())
Or at least ensure that they are correct :wink:

Posted: Wed Feb 15, 2006 8:51 pm
by blueznl
yeah, i think (but can't remember) i've requested a function like that...

perhaps something like:

n = ArraySize( <arrayname> , <indice> )

where...

indice = -1 --> return size of array in bytes
indice = 0 --> return number of indices (dimensions)
indice = n --> return number of fields of that indice

Posted: Sun Nov 19, 2006 11:49 am
by Froggerprogger
Just want to bring it on top...

Atm i use macros similar to the ones posted by remi, but I cannot see any reason to not implement these functionality native into PB. I think they could be supported on all platforms easily, or do I overlook something ?

Posted: Sun Nov 19, 2006 12:13 pm
by ts-soft
a mistake in the macros?

Code: Select all

Macro GETARRAYSIZE(array)
   PeekL(array - 8) * PeekL(array - 20)
EndMacro

Macro GETARRAYELEMENTS(array)
   PeekL(array - 8)
EndMacro

Posted: Sun Nov 19, 2006 3:07 pm
by remi_meier
ts-soft wrote:a mistake in the macros?
Yes :lol:

Posted: Thu Sep 18, 2008 11:45 pm
by Flype
This one is also added in 4.30. Good.
New features in the Libraries:
- Added: ArraySize()