What is pointer stability?

3.5k Views Asked by At

The second paragraph in this link on Abseil containers says:

For example, the Abseil containers often do not guarantee pointer stability after insertions or deletions.

What does pointer stability mean in this context?

2

There are 2 best solutions below

0
On BEST ANSWER

Pointer stability” means that a pointer to an element remains valid (is not invalidated) so long as the element is present, allowing code to cache pointers to elements even when the underlying container is mutated. Saying that a container has pointer stability is the same as saying that it doesn’t move elements in memory; their addresses do not change. Pointer stability/invalidation is the same as reference stability/invalidation.

This is explanation from the page you posted: https://abseil.io/docs/cpp/guides/container (Abseil containers).

0
On

Pointer stability means that the pointer is guaranteed to remain stable for the life of the object to which it points(i.e. the address the pointer points to remains constant and does not change), unless you do something to break it.

The virtual memory space the Operating systems presents to your process will keep things at the same addresses. Although the physical memory might change. This is one of the things OS has to take care.

Reference: Are Pointers stable?