Is it true that having:
int* p = new int;
and:
int* p1开发者_如何学Python = new int[5]();
in case of p1 there will be extra info stored?
Yes, there might be.
I recommend you read the following to items from C++-faq :
- How does the compiler know there are n objects to be destructed using delete[] ?
- How do compilers use "over-allocation" to remember the number of elements in an allocated array ?
A relevant quote extracted from the first link :
The run-time system stores the number of objects, n, somewhere where it can be retrieved if you only know the pointer, p. There are two popular techniques that do this. [...]
- Over-allocate the array and put n just to the left of the first Fred object.
- Use an associative array with p as the key and n as the value
This C++-FAQ entry should answer your question.
精彩评论