Copying a multidimensional array

Discussion of Common Lisp

Re: Copying a multidimensional array

Postby simon » Wed Jun 17, 2009 10:08 am

findinglisp wrote:It won't make a transient copy of the actual data, but it will create a small "displaced array object" ...


This was my initial thought as well, but without consulting the spec I didn't want to commit to "never copying". On reflection, I can't see a way this could run into trouble but I didn't stop to think about it in original comment.

In any case, using a scheme like his you can't avoid the overhead of the transient displaced array, and if you are dealing with very small simple-arrays this may be of similar size to the data, which probably isn't what you want.

This is only one reason why the repeated copying of 4x4 arrays benchmark above is a bit limited and you don't want to take much away from those results. One thing about using a standard function like adjust-array or copy-seq is that if you at least allow for the possibility of an implementation being smart about handling special cases quickly. Typically the overhead for this sort of thing is too high to be of much advantage if you are dealing with tiny matrices or whatever, but it might be a big win on some cases.

This latter is also why in practice if you actually need fast code generation with 4x4 simple-arrays or something of the like, your best bet is usually going to be to expose the copying process, then even a not-to-bright compiler should be able to optimize the array accesses.
simon
 
Posts: 16
Joined: Wed May 13, 2009 9:12 am

Previous

Return to Common Lisp

Who is online

Users browsing this forum: Yahoo [Bot] and 6 guests