-3

I am getting the same value on using the sizeOf operator for a matrix of size 100*100 and 1*1 respectively.

mat A(100,100),B(1,1);
A.randu();
B.randu();
cout<<"Memory requested for A:"<<sizeOf(A);
cout<<"Memory requested for B:"<<sizeOf(B);

Output:
Memory requested for A:160
Memory requested for B:160

Well how do I get the actual memory required by the code for each variable A,B.

backcoder
  • 57
  • 7
  • 2
    What is `sizeOf`? Is it some function in the Armadillo library? The type `mat` only stores pointers to the memory that it allocates. There's probably some member function that returns the number of elements in the matrix being managed by a `mat` instance. Multiply the number returned by that with the size of each matrix element. – Praetorian Apr 19 '15 at 01:21
  • @Raw N : It returns only 160 , whenever I use sizeOf(). For both variable A and B – backcoder Apr 19 '15 at 01:25
  • possible duplicate of [sizeof() a vector](http://stackoverflow.com/questions/2373189/sizeof-a-vector) – Dirk Eddelbuettel Apr 20 '15 at 11:45

1 Answers1

2

The mat type stores an array of doubles, so to get the size of the array as bytes:

A.n_elem * sizeof(double)

The total amount of memory used by A is sizeof(A) + (A.n_elem * sizeof(double)).

mtall
  • 3,574
  • 15
  • 23