gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
MallocUtils.cpp
Go to the documentation of this file.
1 // Gmsh - Copyright (C) 1997-2022 C. Geuzaine, J.-F. Remacle
2 //
3 // See the LICENSE.txt file in the Gmsh root directory for license information.
4 // Please report all issues on https://gitlab.onelab.info/gmsh/gmsh/issues.
5 
6 #include <stdio.h>
7 #include <stdlib.h>
8 
9 #include "MallocUtils.h"
10 #include "GmshMessage.h"
11 
12 void *Malloc(size_t size)
13 {
14  void *ptr;
15 
16  if(!size) return (nullptr);
17  ptr = malloc(size);
18  if(ptr == nullptr) Msg::Error("Out of memory (buy some more RAM!)");
19  return ptr;
20 }
21 
22 void *Calloc(size_t num, size_t size)
23 {
24  void *ptr;
25 
26  if(!size) return (nullptr);
27  ptr = calloc(num, size);
28  if(ptr == nullptr) Msg::Error("Out of memory (buy some more RAM!)");
29  return ptr;
30 }
31 
32 void *Realloc(void *ptr, size_t size)
33 {
34  if(!size) return (nullptr);
35  ptr = realloc(ptr, size);
36  if(ptr == nullptr) Msg::Error("Out of memory (buy some more RAM!)");
37  return ptr;
38 }
39 
40 void Free(void *ptr)
41 {
42  if(ptr == nullptr) return;
43  free(ptr);
44 }
Msg::Error
static void Error(const char *fmt,...)
Definition: GmshMessage.cpp:482
GmshMessage.h
Free
void Free(void *ptr)
Definition: MallocUtils.cpp:40
Calloc
void * Calloc(size_t num, size_t size)
Definition: MallocUtils.cpp:22
Realloc
void * Realloc(void *ptr, size_t size)
Definition: MallocUtils.cpp:32
Malloc
void * Malloc(size_t size)
Definition: MallocUtils.cpp:12
MallocUtils.h