Are arrays stored in all languages?

I recently read a blog in which much attention was paid to storing the array (in particular, in Go), but I realized that, by definition, the data in the array is stored contiguously. At least that’s all that my algorithms and data structures study, made me believe.

So my question is, is massive data stored in all programming languages? And, in particular, I want to talk about primitives such as integers (or in the case of Java, where can I have an array of objects, references to objects stored in memory in memory? I know that the objects themselves can be anywhere) .

+6
source share
2 answers

It depends on what you define as an β€œarray” in the language, although the traditional meaning of the array has to do with adjacent placement of elements.

For example, in JavaScript arrays are actually hash tables, which means that the data is not stored contiguously, but hashed based on its index keys (using the hash function) to store values ​​at different addresses (polled here ), and this is only an example (in fact, I think that in dynamic languages ​​a common occurrence is the presence of arrays in the form of hash tables).

I believe this question answers your question no.

+3
source

this is usually below the level of language abstraction, so there is no explicit requirement for this. but any real implementation probably does this (with rounding to the size of the word) due to performance. of course, this applies to virtual memory, because the kernel can provide non-contiguous space, which the program itself sees as continuous

0
source

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


All Articles