Function for the distribution of the dynamic memory

int **Matrix_B1;  

Matrix_B1 = (int**)malloc(RowB*(sizeof(int*)));  

for (int p=0; p<RowB; p++)
    Matrix_B1[p] = (int*)malloc(ColumnB*(sizeof(int)));

How do I create a function to perform dynamic memory allocation in c ?

I have lots of matrices like this and I don't want to keep writing the same thing.

int *Matrix_B1;

int matrixSize = Rowb * ColumnB; Matrix_B1 = int(*)malloc(matrixSize*sizeof(int));

// writing values to matrix - Matrix_B1[4] = $Value;

// If there are lot of matrices, den you can store the pointers of every matrix in some array pf pointers. each matrix is implemented as 2D array and its memory is dynamically allocated .you can access data in row or column style.