[Implemented] GetArraySize and GetArrayElements

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
remi_meier
Enthusiast
Enthusiast
Posts: 468
Joined: Sat Dec 20, 2003 6:19 pm
Location: Switzerland

[Implemented] GetArraySize and GetArrayElements

Post 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:
Athlon64 3700+, 1024MB Ram, Radeon X1600
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post 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
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Froggerprogger
Enthusiast
Enthusiast
Posts: 423
Joined: Fri Apr 25, 2003 5:22 pm
Contact:

Post 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 ?
%1>>1+1*1/1-1!1|1&1<<$1=1
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post 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
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
remi_meier
Enthusiast
Enthusiast
Posts: 468
Joined: Sat Dec 20, 2003 6:19 pm
Location: Switzerland

Post by remi_meier »

ts-soft wrote:a mistake in the macros?
Yes :lol:
Athlon64 3700+, 1024MB Ram, Radeon X1600
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

This one is also added in 4.30. Good.
New features in the Libraries:
- Added: ArraySize()
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
Post Reply