Skip to main content

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.

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 ...
FlatAssembler's user avatar
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 ...
warren's user avatar
  • 169
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 ...
Marc Le Bihan's user avatar
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,...
DannyNiu's user avatar
  • 467
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 ...
Thomas Mueller's user avatar
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: ...
QF0's user avatar
  • 131
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 ...
CPlus's user avatar
  • 10.5k
2 votes
1 answer
367 views

Implementing a Array programming language in C. What is the best and most efficient struct for the arrays? [closed]

...
rapasite's user avatar
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: ...
Redz's user avatar
  • 1,096
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 ...
CPlus's user avatar
  • 10.5k
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 ...
Dannyu NDos's user avatar
  • 1,485
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, ...
Bbrk24's user avatar
  • 9,672
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 ...
Ray Butterworth's user avatar
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 ...
Michael Homer's user avatar
  • 15.3k
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 ...
CPlus's user avatar
  • 10.5k

15 30 50 per page