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.

Filter by
Sorted by
Tagged with
1 vote
3 answers
309 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 ...
user16217248's user avatar
  • 7,535
2 votes
1 answer
235 views

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

...
rapasite's user avatar
9 votes
1 answer
1k 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
  • 900
6 votes
3 answers
797 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 ...
user16217248's user avatar
  • 7,535
3 votes
5 answers
729 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
5 votes
2 answers
252 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
  • 8,857
4 votes
0 answers
162 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
11 votes
3 answers
289 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
  • 11.7k
16 votes
3 answers
965 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 ...
user16217248's user avatar
  • 7,535
4 votes
1 answer
147 views

What are some good syntaxes for tensor initialisation?

Inspired by this question - What are the disadvantages of being able to define a matrix without typing any words? There is a more general question of what are some syntaxes for initialising tensors ...
Bruce Adams's user avatar
  • 2,793
7 votes
10 answers
326 views

What are some syntax options for iterating over arrays?

What are some different syntax choices for loops that iterate over arrays? Of course, there is the common for loop: ...
cocomac's user avatar
  • 575
12 votes
6 answers
387 views

What are the disadvantages of this far-fetched idea: All integers can be treated as boolean arrays?

I do not know of any languages that support this idea but I just thought that since numbers are just bits, why should we not be able to access those bits directly? In most languages such as C or C++, ...
user16217248's user avatar
  • 7,535
-5 votes
1 answer
444 views

What are the pros and cons of implementing indexed for loops? [duplicate]

When iterating over an array you can use an indexed for loop, like so: ...
Redz's user avatar
  • 900
1 vote
2 answers
155 views

What should a variable-size contiguous collection be called?

Different languages have different names for the same thing. Off the top of my head, there's: C++ vector and Rust Vec Java <...
Bbrk24's user avatar
  • 8,857
6 votes
3 answers
168 views

How could C implement first class arrays?

C does not have first class arrays that can be assigned (copied) or returned from functions directly. In such a low level language where arrays are essentially pointers to the first value. This way, ...
user16217248's user avatar
  • 7,535
13 votes
10 answers
958 views

What are the advantages of strings and character arrays being different?

In many languages such as Java, strings and character arrays are distinct types. In Java one must use toCharArray() in order to use array semantics on strings. In C,...
user16217248's user avatar
  • 7,535