#If I were to allocate an array of objects in heap memory...

10 messages · Page 1 of 1 (latest)

fervent bear
#

If i were to allocate an array of objects in a heap memory, would these objects lie in the memory consequentially, i.e. in a consequential block of memory, not dispersed?

raw harborBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

fleet crypt
#

Depends on your method

#

A linked list wouldn't do that, but stuff like T *t = new T[Size]; would (which is also what e.g. std::vector does)

fervent bear
#

iirc linked list does occupy random parts of memory and just binds elements to each other via pointing to such memory addresses...?

fleet crypt
#

Correct

fervent bear
#

so it means that, let's say, the second element would not be located right after the first

fleet crypt
#

In case of linked lists ? No. (Well, maybe there's a random chance that it could happen, but that's not reliable)

spare tangle
# fleet crypt In case of linked lists ? No. (Well, maybe there's a random chance that it could...

quantum bogo linked list ?

  1. Quantumly randomise the memory, such that there is no way of knowing what order the memory is in until it is observed. This will divide the universe into O(n!) universes; however, the division has no cost, as it happens constantly anyway.
  2. If the linked list does not occupy continuous block of memory, destroy the universe. (This operation is left as an exercise to the reader.)
  3. All remaining universes contain linked lists which are continuous.
fervent bear
#

!solved