What category of Scala do arrays belong to?

I am doing array analysis in Scala. I do this analysis after a book ("The Concepts of Programming Languages" by Robert W. Sebest). According to this book, there are five categories of arrays based on binding to index ranges, binding to storage, and from storage location. Categories:

  • static array : this is one in which index ranges are statically linked and storage distribution is static (performed before launch). The advantage of static arrays is efficiency: no dynamic allocation or freeing is required. The disadvantage is that the storage for the array is fixed for the entire execution time of the program.

  • fixed stack-dynamic array : this is the one in which the ranges of indexes are statically linked, but the distribution is done at the time of declaration execution at run time. The advantage of fixed dynamic arrays over static arrays is space efficiency. A large array in one routine can use the same space as a large array in another routine if both routines are not active at the same time. The same is true if two arrays are in different blocks that are not active at the same time. The disadvantage is the required release and release times.

  • stack-dynamic array : this is one in which index ranges and storage distribution are dynamically linked at design time. However, if index ranges are tied and storage is allocated, they remain fixed during the lifetime of the variable. The advantage of dynamic stack arrays over static and fixed stack dynamic arrays is flexibility. The size of the array does not have to be known until the array is used.

  • fixed heap dynamic array : similar to a fixed stack dynamic array, since index ranges and storage binding are both fixed after storage allocation. The differences are that both index ranges and storage bindings are executed when the user program requests them at run time, and the storage is allocated from the heap, and not from the stack. The advantage of fixed arrays with dynamic memory is flexibility - the size of arrays always corresponds to this problem. The disadvantage is the heap allocation time, which is longer than the stack allocation time.

  • heap-dynamic array : this is one in which the binding of index ranges and storage distribution is dynamic and can change any number of times during the life of the arrays. The advantage of heap-dynamic arrays over others is flexibility: arrays can grow and shrink during program execution, as there is a need to change the space. The disadvantage is that distribution and release take longer and can happen many times during program execution. Examples of five categories are given in the following paragraphs.

Which of these matrix types does Scala use?

+4
source share
1 answer

Scala and Java use fixed heap-dynamic array for primitive arrays. There are classes such as Java Vector and Scala ArrayBuffer that build on the primitive to provide the characteristics of a heap-dynamic array .

+9
source

Source: https://habr.com/ru/post/1436874/


All Articles