|
Thanks Nasser, just what I wanted to know. I knew that was how it worked on passing arguments to functions, but for some now-forgotten reason I thought that this was specific to the function-passing mechanism.
In reply to the unhelpful questions from another correspondent: what is hard to understand about the fact that processing large arrays (eg, taking up >50% of the available array memory) requires a different mindset from 'ordinary' programming? Comments like "choose another name" just show a complete lack of understanding of the problems. I am using a Win32 system. Win32 has a max of 2G for contiguous memory allocation, and the /3G switch is of little help because the 3G is not contiguous. Windows system allocation methods fragment the Matlab workspace during use in ways which cannot be fixed by packing and clearing memory, only by starting a new session. Therefore max available space for a single array in a session steadily decreases, and typically the size of the largest array which can be created on this platform is substantially < 1G. If you are working with algorithms that require a lot of random access to a single large data array then writing blocking/deblocking methods of handling the array with file i/o is highly inefficient, slow to program and slow to execute. The only sensible path is keep the large array in memory if at all possible. The Immediate problem is that you can't copy it without running out of memory. Since nearly all of my programming eventually gets scaled up to large arrays (in diverse fields: eg, testing high quality PRNGs, stitching together an arbitrary number of large image files, number theory investigations), I find that care in controlling the creation of new arrays is a key programming criterion. The algorithms HAVE to work on the one array without copying it, there just isn't room. Finally, even if there was space, consider how absurd it is NOT to use renaming in many common memory-limited situations. Processing an arbitrary selected array from a set of large arrays can all be done efficiently in the same workspace if the chosen array is simply renamed to a standard name. The alternative is to pass the chosen array to a function BUT you have to pass the (often numerous) state control variables as well, which creates a lot of unnecessary overhead, but worse is the fact that processing the array inside the function is going to create out of memory errors. Renaming the array and continuing the analysis in the same workplace is in contrast fast, efficient and logical. By the way, all of the applications that interest me involve naturally dense arrays, and sparse array storage is not an option.
|