Dear Sir,

does anybody know why when setting each row of a priorly created matrix with an array, it takes the size of the whole matrix in memory for each row ( array ) being assigned to the same matrix ?

```
for( x = 1; x <= 1000; x++ )
{
VarSet( "testVarMA_" + x, MA( C * x, 7 ) );
}
elapsed_002_end = GetPerformanceCounter( True );
timeConsumption_002 += elapsed_002_end;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
testMatrix = Matrix( 1000, 318490, Null );
testMatrix = MxSetBlock( testMatrix, 1, 1, 0, 318489, VarGet( "testVarMA_" + 1 ));
testMatrix = MxSetBlock( testMatrix, 2, 2, 0, 318489, VarGet( "testVarMA_" + 2 ));
testMatrix = MxSetBlock( testMatrix, 3, 3, 0, 318489, VarGet( "testVarMA_" + 3 ));
elapsed_003_end = GetPerformanceCounter( True );
timeConsumption_003 += elapsed_003_end;
```

In my case I have a matrix of dimension 1000 x 318490, this takes about 1215 MB.

So each row is roughly 1215/1000 = 1.215 MB. This is fine.

But when I assign the 1st row using MxSetBlock and assign the result back to the original created matrix, it takes another 1215 MB and when assigning the 2nd row it takes another 1215 MB etc...

So I am running out of memory after filling only 12 rows.

Should it not use 0 extra memory because all the memory has already been allocated for the entire matrix in the beginning when creating the matrix ?

I know that when using MxSetBlock it creates a new matrix every time, but when I assign the result back to the original matrix it should not use any extra space ?

I am trying to use a lot of matrices, so this is really relevant to me.

Why does it do that ?

Thanks a lot for some help