Early tests have shown memcopy() to be faster than slice when downsizing an array.
In the test code I create an array large enough to hold the max # of elements of a list. Then I loop through the list and add objects that meet a pre-defined condition (in this case it's a hash table and only objects with the given entry name are inserted into the array). Given that there may be empty elements at the end of the array (if one or more of the condition tests failed), I keep track of the actual insertions into the array and then downsize the array to that number.
These are the two approaches I tested to handle resizing the array.
retarray is an array of objects. It is initialized to a size >= objectcount.
objectcount tracks the # of actual, filled elements in the array.
In my code there's no way to know beforehand how many elements will actually get filled. So the array might be initialized as "new object[500]", but then only get filled with 300 entries.
The test shows that the MemCopy() approach is indeed faster. Not significantly faster, mind you. I'm getting approx 100-200 ms difference per 10,000 iterations of the above code.
As I mentioned, this example was tested with a hash table, and in my MUD server code I'll be accessing hash tables often enough that, despite the speed difference being small, it'll make a difference in the long run.
Just thought you might like to know.
(if anyone wants some code to run/test I can supply it.)
In the test code I create an array large enough to hold the max # of elements of a list. Then I loop through the list and add objects that meet a pre-defined condition (in this case it's a hash table and only objects with the given entry name are inserted into the array). Given that there may be empty elements at the end of the array (if one or more of the condition tests failed), I keep track of the actual insertions into the array and then downsize the array to that number.
These are the two approaches I tested to handle resizing the array.
'approach 1 MemCopy( retarray, retarray, SizeOf(retarray[0]) * objectcount) 'approach 2 retarray = retarray[..objectcount]
retarray is an array of objects. It is initialized to a size >= objectcount.
objectcount tracks the # of actual, filled elements in the array.
In my code there's no way to know beforehand how many elements will actually get filled. So the array might be initialized as "new object[500]", but then only get filled with 300 entries.
The test shows that the MemCopy() approach is indeed faster. Not significantly faster, mind you. I'm getting approx 100-200 ms difference per 10,000 iterations of the above code.
As I mentioned, this example was tested with a hash table, and in my MUD server code I'll be accessing hash tables often enough that, despite the speed difference being small, it'll make a difference in the long run.
Just thought you might like to know.
(if anyone wants some code to run/test I can supply it.)