[go: up one dir, main page]

Menu

[r990]: / mia2 / vistaio / alloc.c  Maximize  Restore  History

Download this file

99 lines (82 with data), 2.3 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
/*
* Copyrigh (C) 2004 Max-Planck-Institute of Cognitive Neurosience
*
* The origional VISTA library is copyrighted of University of British Columbia.
* Copyright © 1993, 1994 University of British Columbia.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/* $Id: alloc.c 51 2004-02-26 12:53:22Z jaenicke $ */
/*! \file alloc.c
* \brief routines for allocating and freeing memory, with error checking
* \author Arthur Pope, UBC Laboratory for Computational Intelligentce
*/
#include "vistaio/vistaio.h"
/*! \brief Perform error checking on malloc() call.
*
* \param size
* \return VPointer
*/
VPointer VMalloc (size_t size)
{
VPointer p;
if (size == 0)
return NULL;
if (!(p = (VPointer) malloc (size)))
VSystemError ("VMalloc: Memory allocation failure");
return p;
}
/*! \brief Perform error checking on realloc() call.
*
* \param p
* \param size
* \return VPointer
*/
VPointer VRealloc (VPointer p, size_t size)
{
if (size == 0) {
VFree (p);
return NULL;
}
if (!p)
return VMalloc (size);
if (!(p = (VPointer) realloc (p, size)))
VSystemError ("VRealloc: Memory allocation failure");
return p;
}
/*! \brief Perform error checking on calloc() call.
*
* \param n
* \param size
* \return VPointer
*/
VPointer VCalloc (size_t n, size_t size)
{
VPointer p;
if (n == 0 || size == 0)
return NULL;
if (!(p = (VPointer) calloc (n, size)))
VSystemError ("VCalloc: Memory allocation failure");
return p;
}
/*! \brief Perform error checking on free() call.
*
* \param p
*/
EXPORT_VISTA void VFree (VPointer p)
{
if (p)
free ((char *)p);
}