-
Notifications
You must be signed in to change notification settings - Fork 0
/
memory.c
84 lines (65 loc) · 1.13 KB
/
memory.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
double **crear_matriu (int nf1, int nf2, int nc1, int nc2)
{
int i;
double **m;
m=(double **)malloc((nf2-nf1+1)*sizeof(double *));
if (m==NULL)
{
printf("Error in allocating matrix\n");
exit(1);
}
m-=nf1;
for (i=nf1; i<=nf2; i++)
{
m[i]=(double *)calloc(nc2-nc1+1, sizeof(double));
if (m[i]==NULL)
{
printf("Error in allocating row %d in matrix\n",i);
exit(1);
}
m[i]-=nc1;
}
return m;
}
void alliberar_matriu (double ** m, int nf1, int nf2, int nc1)
{
int i;
for (i=nf2; i>=nf1; i--)
{
free(m[i]+nc1);
}
free(m+nf1);
}
double *crear_vector (int nc1, int nc2)
{
double *v;
v=(double *)calloc(nc2-nc1+1, sizeof(double));
if (v==NULL)
{
printf("error en alocatar el vector\n");
exit(1);
}
return (v-nc1);
}
void alliberar_vector (double *v, int nc1)
{
free(v+nc1);
}
int *crear_vector_enter (int nc1, int nc2)
{
int *v;
v=(int *)calloc(nc2-nc1+1, sizeof(int));
if (v==NULL)
{
printf("error en alocatar el vector\n");
exit(1);
}
return (v-nc1);
}
void alliberar_vector_enter (int *v, int nc1)
{
free(v+nc1);
}