c++ - delete[] of a pointer to an array, where is the extra 4 byte of array size stored? -


from textbook states when allocate memory using new[], compiler allocate 4 bytes keep track of array size. wonder 4 bytes stored? how explain following core dump?

#include <iostream> using namespace std;  class {     int m; };  int main() {     a* = new a[10];     a* b = + 3;     delete[] b;     delete[] a; } 

i wonder 4 bytes stored?

there 2 common approaches. 1 store right before returned address. other store in separate associative container indexed returned address.

how explain following core dump?

likely on platform stores number of elements prior returned address. second delete[] got garbage size. exact way fails depend on platform, number of horrible things happen.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -