Is Array.Copy decent for copying sections of memory?
I'm making a thing which relies pretty heavily on copying (not very large) sections of memory inside an array to other sections of the array. Is
Array.Copy
decent for this or is there some other lower-level alternative that is more performant/efficient?10 Replies
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Well I have to rearrange stuff inside the array, but I guess I could use spans as auxiliary storage.
To clarify, all the copy operations are from/to the same array.
Array.Copy will be your best bet for copying beyond multithreading (which is not even guaranteed to be faster)
Fair
Last time I checked I think it does as many low-level optimizations as possible
I'd say, follow the old saying : don't optimize until it's absolutely necessary
True
I'm writing a runtime for my own language, so some semblance of performance would be nice, although it's really not important that it's very efficient.
Finally, it really depends on what problem you're trying to solve. An array may not even be the best data structure.
hmm, I've considered using linked lists for what I'm doing, but I think I've settled on copying elements inside an array likely being the most efficient.
If you're trying to have copied data exist in multiple parts of an array, and copies and can do to and from, you may get better performance with a graph data structure
Rather than copying an array, you just connect nodes with a new edge.
Hard to say for sure without context though
true
I'll go with this for, can always optimize it later