-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathallocmem.cpp
More file actions
107 lines (101 loc) · 2.66 KB
/
Copy pathallocmem.cpp
File metadata and controls
107 lines (101 loc) · 2.66 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include <stdlib.h>
#include <stdio.h>
#include "allocmem.h"
/***************************************************************************/
FILE *OpenFile(char *filename, char *mode)
{
FILE *fp;
/* no user interaction here ! if unable to open , return NULL pointer
announcing error; if successful, seek beginning of opened file
indicating success */
if((fp = fopen(filename,mode))== NULL)
{
printf("%s file could not be opened \n", filename);
return(NULL);
}
/* if successful, position the file pointer at the beginning */
fseek(fp, (long)0, 0);
return(fp);
}
/***************************************************************************/
double *FarAllocateMemory(int size)
{
double *dptr;
dptr = (double *)calloc(size, sizeof(double));
if(dptr == NULL)
{
printf("Not enough memory to allocate buffer. \n");
printf("Aborting......\n");
/* terminate program if out of memory */
exit(1);
}
return(dptr);
}
/*****************************************************************************/
double *AllocateMemory(int size)
{
double *dptr;
dptr = (double *)calloc(size, sizeof(double));
if(dptr == NULL)
{
printf("Not enough memory to allocate buffer. \n");
printf("Aborting......\n");
/* terminate program if out of memory */
exit(1);
}
return(dptr);
}
/*****************************************************************************/
double **FarAllocateMatrixMemory(int m, int n)
{
double **dptr;
int i;
dptr = (double **)calloc(m, sizeof(double*));
if(dptr == NULL)
{
printf("Not enough memory to allocate buffer. \n");
printf("Aborting......\n");
/* terminate program if out of memory */
exit(1);
}
for(i = 0; i < m ; i++)
{
dptr[i] = (double *)calloc(n, sizeof(double));
if(dptr[i] == NULL)
{
printf("Not enough memory to allocate buffer. \n");
printf("Aborting......\n");
/* terminate program if out of memory */
exit(1);
}
}
return(dptr);
}
/*****************************************************************************/
/*****************************************************************************/
double **FarAllocateDMatrixMemory(int m, int n)
{
double **dptr;
int i;
dptr = (double **)calloc(m, sizeof(double*));
if(dptr == NULL)
{
printf("Not enough memory to allocate buffer. \n");
printf("Aborting......\n");
/* terminate program if out of memory */
exit(1);
}
for(i = 0; i < m ; i++)
{
dptr[i] = (double *)calloc(n, sizeof(double));
if(dptr[i] == NULL)
{
printf("Not enough memory to allocate buffer. \n");
printf("Aborting......\n");
/* terminate program if out of memory */
exit(1);
}
}
return(dptr);
}
/*****************************************************************************/