Page 1 of 2

'SizeOf' array in PureBasic?

Posted: Thu Jun 04, 2009 10:27 pm
by Mistrel
Is there a way to return the size of an array in bytes in PureBasic similar to how SizeOf works in C?

Posted: Thu Jun 04, 2009 10:40 pm
by cxAlex

Code: Select all

Macro SizeOfArray(_Array)
  PeekI(@_Array-SizeOf(Quad))
EndMacro

Dim MyArray(10,10)

Debug SizeOfArray(MyArray())

Posted: Thu Jun 04, 2009 11:01 pm
by Mistrel
In PB x64 the output is:

Code: Select all

2338038273043070997

Posted: Thu Jun 04, 2009 11:12 pm
by srod
ArraySize() will give you the upper bound for an individual dimension if this helps? My apologies if you are already aware of this function.

Posted: Thu Jun 04, 2009 11:12 pm
by ts-soft

Code: Select all

CompilerIf #PB_Compiler_Processor = #PB_Processor_x64
Macro SizeOfArray(_Array)
  PeekI(@_Array-SizeOf(Quad) * 2)
EndMacro
CompilerElse
Macro SizeOfArray(_Array)
  PeekI(@_Array-SizeOf(Quad))
EndMacro
CompilerEndIf

Dim MyArray(10,10)

Debug SizeOfArray(MyArray())

Posted: Fri Jun 05, 2009 2:53 am
by Demivec
Here's my attempt:

Code: Select all

Macro SizeOfArray(_Array, type, dimension = 1)
  (ArraySize(_Array,dimension) + 1) * SizeOf(type)
EndMacro

Dim MyArray(10,10)

Debug SizeOfArray(MyArray(), Integer, 1) * SizeOfArray(MyArray(), Integer, 2)


Dim Another.BITMAP(15)

Debug SizeOfArray(Another(), BITMAP)

Posted: Fri Jun 05, 2009 5:19 am
by thearr
My way:

Code: Select all

Procedure SizeOfArray(*Array)
  ProcedureReturn PeekL(*Array-8)*PeekL(*Array-20)
EndProcedure

Dim MyArray.l(10,10)
Debug SizeOfArray(MyArray())
Debug 11*11*4

Posted: Fri Jun 05, 2009 11:17 am
by freak
Funny that you guys still prefer peeking around undocumented memory locations even after we added the ArraySize() command. :roll:

Posted: Sat Jun 06, 2009 5:55 pm
by netmaestro
Yes, a very unexpected topic to be sure :?

Posted: Sat Jun 06, 2009 7:01 pm
by Fluid Byte
Am I missing something? I thought they wanted to obtain the size in bytes. That is something that can't be done with ArraySize() since it only returns the number of elements. Sure you could multiply with that value but there is no ArrayType() command. Not yet :wink:

Posted: Sat Jun 06, 2009 10:33 pm
by Mistrel
Fluid Byte wrote:Am I missing something? I thought they wanted to obtain the size in bytes. That is something that can't be done with ArraySize() since it only returns the number of elements. Sure you could multiply with that value but there is no ArrayType() command. Not yet :wink:
Fluid Byte is correct. I'm interested in the size of the array in bytes.

Posted: Sat Jun 06, 2009 11:24 pm
by fsw
Mistrel wrote:
Fluid Byte wrote:Am I missing something? I thought they wanted to obtain the size in bytes. That is something that can't be done with ArraySize() since it only returns the number of elements. Sure you could multiply with that value but there is no ArrayType() command. Not yet :wink:
Fluid Byte is correct. I'm interested in the size of the array in bytes.
Actually the ArraySize() command is misleading because, as was pointed out, it's not the size of the Array you are getting, but the number of elements.

IMHO it would have been better to name this command ArrayElements() (or something similar). This way ArraySize() would have been free to use as command to get the real size in bytes.

BTW: The same goes for ListSize...

bye
fsw

Posted: Sat Jun 06, 2009 11:40 pm
by netmaestro
With the current commands it's as simple as x*y now, imho adding a command such as TotalArrayBytes or such is analagous to sending your remote control out to get hydraulic-assisted buttons installed. Just my 2 cents, no offense meant to anyone.

Posted: Sun Jun 07, 2009 1:52 am
by PB
> IMHO it would have been better to name this command ArrayElements()

This has all been debated before in another heated thread, and the result
was to keep it named as ArraySize(). No need to go over it again.

Posted: Sun Jun 07, 2009 9:43 am
by blueznl
So, all that is needed is a feature requst called: ArrayByteSize :-)