Hello could someone please tell me the difference between nonalloc casting like BoxCastNonAlloc() and normal BoxCastAll()
what are the advantages and disadvantages of each and scenarios under which we would like to use either one of them?
Hello could someone please tell me the difference between nonalloc casting like BoxCastNonAlloc() and normal BoxCastAll()
what are the advantages and disadvantages of each and scenarios under which we would like to use either one of them?
Both serve the same purpose in general, but they have some advantages / disadvantages:
Pro:
Con:
Pro:
Con:
Generally the Non Alloc versions are in most situations the better choices. However you have to think about how large you want to allocate the array to ensure you don’t miss anything important. If you cast against a certain group of objects on a certain layer and you know there are only 8 object at max, using an array with 10 elements should cover all cases with some reserve. If the count varies heavily you want to create an array with enough elements (like 30,100, 400 or even 1000).
When to use what highly depends on your target platform, if you can live with the generated garbage, if you can afford a large pre allocated array and on your general usecase (how many possible hits, how often it is used, …)