Questions tagged [arrays]
For questions about the implementation or design of arrays within a programming language, including C++ vectors, Java Lists, or other types of dynamic arrays.
22 questions
3
votes
1
answer
476
views
How are C11 compilers calculating by how much to change the stack pointer before `goto` if the program uses variable-length arrays?
So, obviously, the C compiler, when compiling gotos, before inserting the jump instruction, needs to insert ...
5
votes
1
answer
242
views
Why to choose row-major vs column-major for matrix storage/processing efficiency?
When implementing matrices/two-dimensional arrays, some languages choose to store them row-major, whereas others choose column-major (for example, fortran and C).
This makes equivalent sequential ...
21
votes
5
answers
4k
views
The square bracket dance: declaring an array in Go, Java, C++ makes the bracket [] going from the left to right. What are the underlying motives?
I've learned multiple languages during my developer life. When I'm switching from one to another, I'm falling in plenty of "small things to remember". Some have a reason I'm knowing, but ...
7
votes
2
answers
547
views
Offset+Length vs 2 Offsets
Q what are the advantages and disadvantages of slicing an array using offset+length and start/end offsets?
My Observations
Adoption: Both are used in some languages and libraries. JavaScript had both,...
7
votes
0
answers
340
views
What is the history of using dependent types to avoid array bound checks
Context
For memory safe languages to be fast, array bounds should be checked during compilation. Some language like Java, Rust, Swift, and others eliminate array bounds checks when possible, but the ...
3
votes
0
answers
232
views
Languages in which array types must be declared before usage
Some languages require array types to be declared before an object of that type can be declared. In Ada, for example:
...
2
votes
5
answers
891
views
Is there any way a Java-like language could implement immutable primitive arrays without incurring performance penalties?
I asked: What prevents Java from having immutable primitive arrays? a while back and got an answer: Because immutable primitive arrays would typically require checking some immutable flag every time a ...
2
votes
1
answer
367
views
10
votes
1
answer
3k
views
In Python, why isn't it a syntax error when a list of strings is defined without comma separators?
When coding in Python, I found that defining a list of strings without separating the strings with a comma is not a syntax error. When running this code:
...
6
votes
3
answers
954
views
Why might a language avoid reallocation?
In Java, the size of arrays are immutable. However, to my understanding, they are still allocated on the heap, because Java allocates almost everything on the heap. Even then, Java arrays are still ...
3
votes
5
answers
761
views
To what degree is it practical to let objects be stored packed? [closed]
Let's say I want my compiler to store objects packed (data and collection members aligned to non-word boundaries).
Situation #1: I want to store an array of booleans.
A few languages already let the ...
6
votes
2
answers
622
views
Why would Short String Optimization not apply to dynamic arrays?
Short string optimization is the optimization that sufficiently short strings have their data stored inline rather than an external buffer, so the string type ends up being a union. Swift does this, ...
4
votes
0
answers
233
views
Do any languages provide arrays that are always powers of 2 in length?
In the early 1970s, I had university a co-op job at a place where one of the main languages used was like a glorified calculator.
It provided two stacks, and all variables and operators were a single ...
12
votes
3
answers
388
views
How can a language statically ensure a required index exists in a list?
Suppose a language has a conventional list data structure that contains some dynamic number of values indexed sequentially. Some operations to access a value from the list require that a certain index ...
20
votes
3
answers
5k
views
What are the implications of implementing variable-length arrays?
At first C did not have variable-length arrays; all array sizes must be compile times constants. Then, in C99, variable-length arrays, a controversial addition, were added, permitting runtime-sized ...