STRING ARRAY size in bytes?
Posted: Thu Jun 02, 2005 11:47 pm
How to calculate size (in bytes) of allocated memory by string array?
http://www.purebasic.com
https://www.purebasic.fr/english/
assuming that your string consists of single byte character values, the above pretty much describes what you want to know.When you define a new array, please note that it will have one more element than you used as parameter, because the numbering of the elements in PureBasic (like in other BASIC's) starts at element 0. For example when you define Dim(10) the array will have 11 elements, elements 0 to 10.
dell_jockey wrote:from the manual:
assuming that your string consists of single byte character values, the above pretty much describes what you want to know.When you define a new array, please note that it will have one more element than you used as parameter, because the numbering of the elements in PureBasic (like in other BASIC's) starts at element 0. For example when you define Dim(10) the array will have 11 elements, elements 0 to 10.
Code: Select all
Dim a.l(6)
a(6)=7
a(10000)=10
MessageRequester("test",Str(a(10000)), #PB_MessageRequester_Ok)
Code: Select all
Dim test$(1)
test$(0)="ABC"
test$(1)="DEFG"
Code: Select all
; Dim test$(1)
PUSH dword 8
PUSH dword a_test$
PUSH dword s_s
MOV ebx,4
MOV edx,dword [a_test$]
CALL SYS_FreeStringStructuredArray
MOV eax,2
MOV ebx,4
CALL SYS_AllocateArray
; test$(0)="ABC"
MOV ebp,dword [a_test$]
MOV edx,_S1
LEA ecx,[ebp]
CALL SYS_FastAllocateStringFree
; test$(1)="DEFG"
MOV edx,_S2
LEA ecx,[ebp+4]
CALL SYS_FastAllocateStringFree
Code: Select all
#NumElements=6
SizeOfArray = 0
Dim test$(#NumElements-1); Indexes start at zero remember!
;Initialise some data, leaving 3 elements uninitialised, just for the hell of it!
test$(0)="ABC"
test$(1)="DEFG"
test$(2)="Hello"
base_addr = test$();This is the base address of the array.
For i=0 To #NumElements-1
addr=PeekL(base_addr+i*4);This is the address of the ith element in memory.
If addr;Ignore unititialised elements.
SizeOfArray + Len(PeekS((addr)))+1;Add the length of the string to the count. Add 1 for the terminating zero.
EndIf
Next i
;Now add the amount of memory given over to the memory pointers.
SizeOfArray + 4*#NumElements
MessageRequester("Byte count", "The number of bytes used is: "+Str(SizeOfArray), #PB_MessageRequester_Ok)
End