Is the new C ++ operator a guarantee that the returned pointer will not change its value?

In C ++:

const size_t N = 1000;
int* p = new int[N];// time=t0

My program has only one thread, and by allocating memory on p, my program will simply read the memory designated p.

What does the standard say about meaning p?

Will it pkeep the value that it receives at time = t0, until deleteof p?

Or can the OS decide to reallocate the memory specified by itself p?

Does it depend on the value N?

+4
source share
4 answers

, (. 1.7 - ++ - 1.10 - - ( 1)). , . , (- ). , , . undefined, , . , (. 1.10) " " ( , ).

new , , .

, 1.9 ( ) 8 , :

.

, , , , volatile , , . ( , , ). , new , , , , . (.. volatile) , new volatile, , , , . , , , , , , , , . , , , , : , - .

, p new , , , . - , .

(1), N3485 , . >

+1

p . :

3.7.4.1

... , (4.10) p0, p1, p1 delete.

( )


, - p , , , p, . .

+5

p - . . , , . . . () . , , ( ).

0

, . p , , () . N .

0

All Articles