How to get an array size
Blitz3D Forums/Blitz3D Programming/How to get an array size| 
 | ||
| Do you know how i can get an array size? I tried to make some routine, but as soon as i reach the last value in the array the program stops saying `array index out of bounds`.. | 
| 
 | ||
| The only way to do this is to store the array size in a variable, when you dimension it. Or, you could use a bank, instead. You can then use the BankSize command to get it's size. | 
| 
 | ||
| Is faster using arrays or banks, to store custom types collections? | 
| 
 | ||
| Theoretically, arrays are faster. Plus, you can't use banks for types, unless you use the Handle/Object commands, which will make things a bit slower again. However, array/bank access speed is unlikely to be your main bottleneck. :) | 
| 
 | ||
| i use handles. thanks. | 
| 
 | ||
| how can i get the last unused 4 bytes in a bank? with a for-next? | 
| 
 | ||
| I used this code. Please tell me if you find an error. Global b% = CreateBank(16) PokeInt b, 0, 1111 PokeInt b, 4, 2222 PokeInt b, 8, 3333 Global i% = 0, start%, finish%, bytes% .start If PeekInt(b, i) <> 0 i = i + 4 Goto start Else bytes = i/4 Goto finish EndIf .finish Print bytes WaitKey() End It gives me the first unused int. | 
| 
 | ||
| You mean something like this? 
free_pos = -1
For i = 0 To (BankSize(bank)-1) Step 4
    If PeekInt(bank,i) = 0
        free_pos = i
        Exit
    EndIf
Next
If free_pos = -1
    ; Bank has no free position. Handle that here.
EndIf
 | 
| 
 | ||
| exactly. | 
| 
 | ||
| Look into my Container Classes for an alternative - my Vector Container in specific emulates an Array of Handles to objects using a bank.  It keeps track of the number of elements in the "array" and can preallocate space for more separately.  Maybe you don't have to reinvent the wheel!  ;) |