'SizeOf' array in PureBasic?
Posted: Thu Jun 04, 2009 10:27 pm
Is there a way to return the size of an array in bytes in PureBasic similar to how SizeOf works in C?
http://www.purebasic.com
https://www.purebasic.fr/english/
Code: Select all
Macro SizeOfArray(_Array)
PeekI(@_Array-SizeOf(Quad))
EndMacro
Dim MyArray(10,10)
Debug SizeOfArray(MyArray())Code: Select all
2338038273043070997Code: 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())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)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*4Fluid Byte is correct. I'm interested in the size of the array in bytes.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
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.Mistrel wrote:Fluid Byte is correct. I'm interested in the size of the array in bytes.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