Page 1 of 1

Array Memory Usage Calulator

Posted: Sun Sep 21, 2003 11:41 pm
by Dreglor
thanks to the help of larsG that pointed out there are 8 bits in a byte (DOH!)
i made a little tool to calulate the memoery comsumption of a array (muilt dimentional too)
ok it updated

Code: Select all

;*****************************************
;*Name: Array Memory Usage Calulator     *
;*By: Dreglor                            *
;*last updated: 9-21-03 9:32pm           *
;*****************************************

OpenConsole()
ConsoleTitle("Array Memory Usage Calulator")
start:
Print("Enter the number of dimentions: ")
dimentions=Val(Input())
PrintN("")
Dim dsize(dimentions)
For i=1 To dimentions
  Print("Enter "+Str(i)+"D's size: ")
  dsize(i)=Val(Input())
  PrintN("")
Next i
Print("Enter the data type(use b,w,l,f,s): ")
dtype.s=Input()
PrintN("")
memsize=dsize(1)
For i=2 To dimentions
memsize=memsize*dsize(i)
Next i
If dtype="b" Or dtype="B"
memsize=memsize*1
EndIf
If dtype="w" Or dtype="W"
memsize=memsize*2
EndIf
If dtype="l" Or dtype="f" Or dtype="s" Or dtype="L" Or dtype="F" Or dtype="S"
memsize=memsize*4
EndIf
PrintN("The array will consume: "+Str(memsize)+" of Bytes")
PrintN("OR: "+StrF(memsize/1024)+" of Kilobytes")
PrintN("OR: "+StrF(memsize/1048576)+" of Megabytes")
PrintN("OR: "+StrF(memsize/1073741824)+" of Gigabytes")
Print("want to calulate again?(Y/N) ")
yn.s=Input()
ClearConsole()
If yn="Y" Or yn="y"
  Goto start
ElseIf yn="N" Or "n" 
  End
Else
  End
EndIf

Posted: Mon Sep 22, 2003 12:24 am
by Kale
the only thing it does not surrport is strings datatype it becasue how the datatype is used...
IIRC String vars are not really vars just pointers to the actual string, so they are longs (4 bytes).