Browse Source

alokacja pamieci + drobne pierdoly

master
Piotr Dergun 8 years ago
parent
commit
3be291f00a
1 changed files with 47 additions and 1 deletions
  1. +47
    -1
      DergunPiotr-WaskoDominik/zad1/macierz_omp.cpp

+ 47
- 1
DergunPiotr-WaskoDominik/zad1/macierz_omp.cpp View File

@ -1,15 +1,61 @@
#include <iostream> #include <iostream>
#include <cstdlib> #include <cstdlib>
#include <stdio.h>
using namespace std; using namespace std;
void array_alloc(double **arr, long arrsize)
{
try
{
arr = new double* [arrsize];
arr[0] = new double [arrsize*arrsize];
for(long i = 1; i < arrsize; i++)
arr[i] = arr[i-1] + arrsize;
}
catch (bad_alloc& ex)
{
cerr << "Could not allocate memory for array" << endl;
exit(1);
}
}
void array_destroy(double **arr)
{
delete [] arr[0];
delete [] arr;
}
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
double **A=NULL;//, **B=NULL, **C=NULL;
long rozmiar=0;
char *endptr;
if (argc < 3) if (argc < 3)
{ {
cerr << "Usage: " << argv[0] << " <n> <size>" << endl; cerr << "Usage: " << argv[0] << " <n> <size>" << endl;
exit(1); exit(1);
} }
cout << argv[argc-1];
rozmiar = strtol(argv[2], &endptr, 10);
if (*endptr)
{
cerr << "Invalid array size format" << endl;
exit(1);
}
if (rozmiar <= 0)
{
cerr << "The number of matrix dimension must be positive" << endl;
exit(1);
}
array_alloc(A, rozmiar);
getchar();
//jeszcze czyszczenie pamięci
exit(0); exit(0);
} }

Loading…
Cancel
Save