Menu

#183 Vectors (the informatics flavour, not the mathematics one)

open
nobody
None
8
2023-04-22
2023-04-22
No

C++, like maxima, offers lists: Manipulating lists is easy, They still allow for half-way fast iteration over a list, But creating a new list element requires a (slow) malloc and since lists tend to be scattered throughout the memory accessing them might evade the cache readahead. Additionally if the next list element is in a different RAM row for accessing it one always has to wait an additionally RAS-to-CAS delay of the RAM.

C++ also allows Arrays, like Maxima: Hard to manipulate, but fast.

What maxima doesn't provide is vector of the C++ kind: An array that dynamically grows, if needed. This is done by allocating memory for like 100 entries when the array is created, so adding the first 100 entries at the end of the vector is fast, If the 100 entries are reached the vector is copied to a new place with more space and that vector is used from then on.

Adding entries at the beginning of such a vector requires a longish copy action. But most other actions are faster with vectors than they are with lists and you get a free random access functionality.

Discussion

  • Stavros Macrakis

    Maxima currently has too many array/list-like object types. It would be nice to unify them in some clean and consistent way. For the use case of dynamically growing arrays, Maxima's hasharrays are pretty good, though certainly not perfect.

     
  • Gunter Königsmann

    hashes in Maxima are sloooow. And with wxMaxima I have learned that on modern machines they can be way faster than lists for many use-cases. But the argument that we already have too many array-like things with varying support is valid => will accept a "won't fix" as a solution.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.