forked from freudenreichan/info2Praktikum-NeuronalesNetz
(create und clear Matrix hinzugefügt)
This commit is contained in:
1 parent
e4c7ec1a59
commit
c99205afc2
1 file changed
+25
@@ -6,11 +6,36 @@
|
|||||||
|
|
||||||
Matrix createMatrix(unsigned int rows, unsigned int cols)
|
Matrix createMatrix(unsigned int rows, unsigned int cols)
|
||||||
{
|
{
|
||||||
|
Matrix m;
|
||||||
|
m.rows = rows;
|
||||||
|
m.cols = cols;
|
||||||
|
|
||||||
|
// Speicher reservieren und mit 0 initialisieren
|
||||||
|
m.buffer = (MatrixType *)calloc((size_t)rows * cols, sizeof(MatrixType));
|
||||||
|
|
||||||
|
// Falls Arbeitsspeicher voll ist
|
||||||
|
if (m.buffer == NULL) {
|
||||||
|
m.rows = 0;
|
||||||
|
m.cols = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return m;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void clearMatrix(Matrix *matrix)
|
void clearMatrix(Matrix *matrix)
|
||||||
{
|
{
|
||||||
|
//prüfen ob pointer exisitert und ob es einen buffer gibt
|
||||||
|
if (matrix != NULL && matrix->buffer != NULL)
|
||||||
|
{
|
||||||
|
// Speicher freigeben
|
||||||
|
free(matrix->buffer);
|
||||||
|
|
||||||
|
// Werte zurücksetzen
|
||||||
|
matrix->buffer = NULL;
|
||||||
|
matrix->rows = 0;
|
||||||
|
matrix->cols = 0;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user