hydrocode_Radial_Lag 0.3
This is an implementation of fully explict forward Euler scheme for multi-D radially symmetric compressible flows on Lagrangian coordinate
mem.c
浏览该文件的文档.
1
6#include <stdlib.h>
7#include <stddef.h>
8#include <assert.h>
9#include "../include_cii/except.h"
10#include "../include_cii/mem.h"
11const Except_T Mem_Failed = { (char*)"Allocation Failed" };
12void *Mem_alloc(long nbytes, const char *file, int line){
13 void *ptr;
14 assert(nbytes > 0);
15 ptr = malloc(nbytes);
16 if (ptr == NULL)
17 {
18 if (file == NULL)
20 else
21 Except_raise(&Mem_Failed, file, line);
22 }
23 return ptr;
24}
25void *Mem_calloc(long count, long nbytes,
26 const char *file, int line) {
27 void *ptr;
28 assert(count > 0);
29 assert(nbytes > 0);
30 ptr = calloc(count, nbytes);
31 if (ptr == NULL)
32 {
33 if (file == NULL)
35 else
36 Except_raise(&Mem_Failed, file, line);
37 }
38 return ptr;
39}
40void Mem_free(void *ptr, const char *file, int line) {
41 if (ptr)
42 free(ptr);
43}
44void *Mem_resize(void *ptr, long nbytes,
45 const char *file, int line) {
46 assert(ptr);
47 assert(nbytes > 0);
48 ptr = realloc(ptr, nbytes);
49 if (ptr == NULL)
50 {
51 if (file == NULL)
53 else
54 Except_raise(&Mem_Failed, file, line);
55 }
56 return ptr;
57}
#define RAISE(e)
Definition: except.h:30
void Except_raise(const T *e, const char *file, int line)
Definition: except.c:15
void * Mem_calloc(long count, long nbytes, const char *file, int line)
Definition: mem.c:25
const Except_T Mem_Failed
Definition: mem.c:11
void * Mem_alloc(long nbytes, const char *file, int line)
Definition: mem.c:12
void Mem_free(void *ptr, const char *file, int line)
Definition: mem.c:40
void * Mem_resize(void *ptr, long nbytes, const char *file, int line)
Definition: mem.c:44