Why not make this (and newarray) generic over T, return *mut T, get rid of the size argument and use size_of<T> instead, and cast the result of tc_newarray to *mut T? This would mean that you only need to pass nmem to set_memory, which would be clearer to read.