Even absent the garbage objects, all those indexing operations aren't
helping performance, and this solution doesn't remedy that at all. Using
(abusing?) Lua as a convenient interface to poke and prod C data structures
is a poor use of both Lua and C. And I think that's why, fundamentally, this
notion of slices is problematic--it's most useful for all the wrong reasons.
(Except, perhaps, for array slices, but your proposal doesn't satisfactorily
solve that.)
So slice is not a good name, let's change a name.
I think one integer can use to present the array slices. We don't need use it for begin and end position of slice, just record the index of slices. The slices of array is also store in userdata. I don't think you will create 2^32 slice of one userdata.