the amount of dynamic allocated memory a pointer would take in c++ -
i have program:
#include <iostream> using namespace std; int main(){ const int size = 1000; typedef int* intpointer; intpointer ip; { ip = new int[ size ]; cout << "memory allocated " << endl << flush; } while (ip != nullptr); }
this code suppose test amount of memory used ip every time loops. tried print out value of ip, memory address in hex believe, can see everytime loops once, address increase 4000 in dec. so, correct every ip take 4000 bytes memory? wondering if there function value of memory used every ip? if not, how size of cumulative memory use within loop? appreciate answer. thank you!
i don't know why have allocate memory know this.
to size of 1 pointer use below,
cout << "memory allocated 1 intpointer :"<<sizeof(intpointer);
to size of 1000 int* objects use below,
cout << "memory allocated "<< size <<" intpointers :"<<sizeof(intpointer*size );
you getting 4000 allocate memory 1000 int* i.e 4*1000 = 4000.
Comments
Post a Comment