IanM,
The range limited versions of the "Find Free()" commands could be very helpful, especially in the case of objects.
As you've mentioned, the performance difference between low and high index id's for images seems to be fairly low, but for objects, the difference is substantial. The test program below shows how long it takes for a group of entities (images/objects) to load.
`Comment/De-comment as needed.
`------------------------------
Sync On
`Any image can be used here...just alter the string accordingly.
strImgName As String = "D:Dark Basic ProfessionalMediaTexturesbrick1_T.BMP"
iStart As Integer = 1 `10000001
iEnd As Integer = 100 `10000100
iTimeStart As Integer
iTimeTaken As Integer
`------------------------------
Text 0, 0, "Loading " + Str$ ( iEnd - iStart + 1 ) + " entities...please stand by." : Sync : Sync
iTimeStart = Timer()
For x = iStart To iEnd
Load Image strImgName, x
`Make Object Cube x, 1
Next
iTimeTaken = Timer() - iTimeStart
`###############################
`MAIN LOOP
`###############################
Do : Cls
Text 0, 0, "Time taken: " + Str$ ( iTimeTaken ) + " ms"
Sync : Loop
On my PC, the results were as follows:
Images: Low index id's = 8695 ms
Images: High index id's = 8782 ms
Images: Time difference = 87 ms ( + 1% )
Objects: Low index id's = 2 ms
Objects: High index id's = 323 ms
Objects: Time difference = 321 ms ( + 16050% )
--------------------------------
For the "Link ArrayPtr()" command, I have realised that it is not possible to use such a command for the purpose I had originally thought for it. However, the command may still be of use to somebody else, so I've presented the idea that I had for this command in the code snippet below:
`-------------------------------
`Make array from file
`This will load a file delimited by carriage returns, and store its contents in a string-based array.
`The external array must be string based as well.
`-------------------------------
Function MakeArrayFromFile( strFilename As String, ptrArrayExternal As Dword )
`Create an array of a size that equals the number of lines in the file
Dim arrTransfer( LinesInFile( strFilename ) - 1 ) As String
`Load the file into the array
Load Array strFilename, arrTransfer()
`Retrieve the arrTransfer() array pointer
Local ptrArrTransfer As Dword : ptrArrTransfer = Get ArrayPtr ( arrTransfer() )
`Link the external array to the local array
Link ArrayPtr ptrArrayExternal, ptrArrTransfer
EndFunction
The code snippet did form a part of one of my projects (before I discovered that the "Link ArrayPtr()" didn't exist). The "LinesInFile()" function comes from a different part of that particular project; it returns the number of lines present in a string-based text file.
--------------------------------
Thanks for the reply on the "Examples" idea. I have a couple of code snippets here that might be useful.
This one demonstrates the "Split String()", "Split Count()" and "Get Split Word$()" commands:
iWordOne As Integer = 1
iWordTwo As Integer = 2
iNumWords As Integer
strString As String = "Widget=Left,Top,Width,Height,IsVisible,IsActive"
strProperty As String
strData As String
`-------------------------------
Split String strString, "="
strProperty = Get Split Word$ ( iWordOne )
strData = Get Split Word$ ( iWordTwo )
Text 0, 0, "strProperty: " + strProperty
Text 0, 10, "strData: " + strData
Text 0, 20, "Split Count: " + Str$ ( Split Count() )
Text 0, 40, "Main string split ( delimiter '=' )"
Text 0, 50, "Press any key to continue"
Sync : Wait Key
`-------------------------------
Cls
Split String strData, ","
iNumWords = Split Count()
Dim arrData( iNumWords - 1 ) As String
For cIndex = 1 To iNumWords
arrData( cIndex - 1 ) = Get Split Word$ ( cIndex )
Text 0, ( cIndex * 10 ) - 10, "Data: " + Str$ ( cIndex ) + ": " + arrData( cIndex - 1 )
Next
Text 0, iNumWords * 10, "Split Count: " + Str$ ( iNumWords )
Text 0, ( iNumWords * 10 ) + 20, "Data string split ( delimiter ',' )"
Text 0, ( iNumWords * 10 ) + 30, "Press any key to continue"
Sync : Wait Key
`-------------------------------
End
This one is a little on the long side, but it helps to demonstrate the "Get Array Item Ptr()", "Get Array Field Offset()" and "Peek/Poke()" commands:
Type udtGeneric
strString As String
iInteger As Integer
EndType
`-------------------------------
`Non-UDT array...Peek String
Dim arrTestA( 0 ) As String : arrTestA( 0 ) = "Hello"
ptrArrayItem = Get Array Item Ptr ( arrTestA(), 0 ) : ptrArrayString = Peek Dword ( ptrArrayItem )
Text 0, 0, Peek String ( ptrArrayString )
Text 0, 10, "Non-UDT array...Peek String"
Text 0, 20, "Press any key to continue"
Sync : Wait Key
`-------------------------------
`Non-UDT array...Poke String
Cls
Poke String ptrArrayString, "World"
Text 0, 0, Peek String ( ptrArrayString )
Text 0, 10, "Non-UDT array...Poke String"
Text 0, 20, "Press any key to continue"
Sync : Wait Key
`-------------------------------
`UDT array...Peek String
Cls
Dim arrTestB( 0 ) As udtGeneric : arrTestB( 0 ).strString = "Hello 2"
ptrArrayItem = Get Array Item Ptr ( arrTestB(), 0 )
iArrayOffset = Get Array Field Offset ( arrTestB(), 1 )
ptrArrayField = ptrArrayItem + iArrayOffset
ptrArrayString = Peek Dword ( ptrArrayField )
Text 0, 0, Peek String ( ptrArrayString )
Text 0, 10, "UDT array...Peek String"
Text 0, 20, "Press any key to continue"
Sync : Wait Key
`-------------------------------
`UDT array...Poke String
Cls
Poke String ptrArrayString, "World 2"
Text 0, 0, Peek String ( ptrArrayString )
Text 0, 10, "UDT array...Poke String"
Text 0, 20, "Press any key to continue"
Sync : Wait Key
`-------------------------------
`UDT array...Peek Integer
Cls
arrTestB( 0 ).iInteger = 54321
ptrArrayItem = Get Array Item Ptr ( arrTestB(), 0 )
iArrayOffset = Get Array Field Offset ( arrTestB(), 2 )
ptrArrayField = ptrArrayItem + iArrayOffset
Text 0, 0, Str$ ( Peek Integer ( ptrArrayField ) )
Text 0, 10, "UDT array...Peek Integer"
Text 0, 20, "Press any key to continue"
Sync : Wait Key
`-------------------------------
`UDT array...Poke Integer
Cls
Poke Integer ptrArrayField, 98760
Text 0, 0, Str$ ( Peek Integer ( ptrArrayField ) )
Text 0, 10, "UDT array...Poke Integer"
Text 0, 20, "Press any key to continue"
Sync : Wait Key
`-------------------------------
End
Hope these will be helpful.