Integer Memory
BlitzMax Forums/BlitzMax Beginners Area/Integer Memory
| ||
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() |
| ||
From the manual: Function MemAlloced() Memory currently allocated by 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.Returns: The amount of memory, in bytes, currently allocated by the application Also, MemAlloced and program initialization itself uses memory, try: FlushMem() Print MemAlloced() FlushMem() Local a:Int = 34 Print MemAlloced() |
| ||
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 |
| ||
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? |
| ||
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. |
| ||
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. |