Array Memory Usage Calulator

Everything else that doesn't fall into one of the other PB categories.
Dreglor
Enthusiast
Enthusiast
Posts: 759
Joined: Sat Aug 02, 2003 11:22 pm
Location: OR, USA

Array Memory Usage Calulator

Post 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
Last edited by Dreglor on Mon Sep 22, 2003 5:34 am, edited 1 time in total.
~Dreglor
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post 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).
--Kale

Image
Post Reply