Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This is a very broad question, and kinda has many parts to it. First off, this is relative to the language you are working in. Lets take Java as an example.</p> <p>When you create an object, it inherits from the main object class. When the object is created, the overhead comes from the fact that the user defined class inherits from <code>Object</code>. The compiler has to virtualize certain method calls in memory so that when you call <code>.equals()</code> or <code>.toString()</code>, the program knows which one to call (that is, your classes' <code>.equals()</code> or <code>Object</code>'s <code>.equals()</code>). This is accomplished with a lookup table and determined at runtime with pointers.</p> <p>This is called virtualization. Now, in java, an array is actually an object, so you really don't gain much from an array of arrays. In fact, you might do better using your own class, since you can limit the metadata associated with it. Arrays in java store information on their length.</p> <p>However, many of the collections DO have overhead associated with them. <code>ArrayList</code> for example will resize itself and stores metadata about itself in memory, that you might not need. <code>LinkedList</code> has references to other nodes, which is overhead to its actual data. </p> <p>Now, what I said is only true about Java. In other OO languages, objects behave differently on the insides, and some may be more/less efficient. </p> <p>In a language such as C++, when you allocate an array, you are really just getting a chunck of memory and it is up to you what you want to do with it. In that sense, it might be better. C++ has similar overhead with its objects if you use overriding (keyword <code>virtual</code>) as it will create these virtual lookups in memory. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload