Is there heap compaction in C ++?

I have an idea that the C ++ runtime does not perform any heap compaction, which means that the address of the object created on the heap never changes. I want to confirm whether this is true, and if this is true for each platform (Win32, Mac, ...)?

+3
source share
5 answers

The C ++ standard does not say anything about heap, and also about compaction. However, this requires that if you take the address of the object, this address remains unchanged throughout the entire life cycle of the object.

++ - . "", , -, , .

, , , ++ , , .

, . , ( ++ , , -, Flash), , , .

+17

, . . , , , .

+4

, . , Lookaside ( , ) , .

+4

++, . , ( 100%), , - , , , , , :

  • intptr_t
  • - (xor'ed ), ,
  • -
  • intptr_t ,

, .

, , - , - .

+3

, , , .

If instead you do not use the default memory managers, and instead a third-party memory manager, it completely depends on the runtime and memory manager used. Although C ++ objects usually do not move in memory with a memory manager, you can write a memory manager that compresses free space, and you could perhaps write one that would move the selected objects to also increase free space.

+2
source

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


All Articles