Integer Memory

BlitzMax Forums/BlitzMax Beginners Area/Integer Memory

Dubious Drewski(Posted 2005) [#1]
So MemAlloced tells me that a 32 bit Int takes up 22 bits in memory.
What's going on here?

Print MemAlloced()
Local a:Int = 34
Print MemAlloced()



FlameDuck(Posted 2005) [#2]
From the manual:
Function MemAlloced() Memory currently allocated by application
Returns: The amount of memory, in bytes, currently allocated by the application
As opposed to say "Ammount of memory used by your variables". You'll notice that your code reports different results depending on whether it's running in debug or not.

Also, MemAlloced and program initialization itself uses memory, try:
FlushMem()
Print MemAlloced()
FlushMem()
Local a:Int = 34
Print MemAlloced()



tonyg(Posted 2005) [#3]
Isn't the memalloced command taking 20 bytes and the int nothing?
Print MemAlloced()
Print MemAlloced()
FlushMem
Local a:Int = 34
Print MemAlloced()

There was some discussion here


Dubious Drewski(Posted 2005) [#4]
I see. So everytime you call MemAlloced, it takes up another
20 bytes.

From that thread, Vanilla said:

The variables are initialised at init time, before your first
command can be executed.


That's interesting. How can the program know what
variables you will use before your program runs? It can't, can it?


tonyg(Posted 2005) [#5]
Memalloced will use 20 bytes which are recovered by flushmem.
Your program is compiled so knows which variables will be used but not what their values will be during runtime.


Who was John Galt?(Posted 2005) [#6]
Integers will be in a block of memory allocated as soon as the program runs - so you won't see any change at the line where they are allocated. Create some types or an integer array which are dynamically allocated and I would expect to see a change.