source: trunk/drmaa_utils/drmaa_utils/xmalloc.h @ 1

Revision 1, 2.6 KB checked in by mmamonski, 13 years ago (diff)

Torque/PBS DRMAA initial commit

Line 
1/* $Id: xmalloc.h 2 2009-10-12 09:51:22Z mamonski $ */
2/*
3 *  FedStage DRMAA utilities library
4 *  Copyright (C) 2006-2008  FedStage Systems
5 *
6 *  This program is free software: you can redistribute it and/or modify
7 *  it under the terms of the GNU General Public License as published by
8 *  the Free Software Foundation, either version 3 of the License, or
9 *  (at your option) any later version.
10 *
11 *  This program is distributed in the hope that it will be useful,
12 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 *  GNU General Public License for more details.
15 *
16 *  You should have received a copy of the GNU General Public License
17 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20/**
21 * @file xmalloc.h
22 * Memory allocation/deallocation routines.
23 */
24
25#ifndef __DRMAA_UTILS__XMALLOC_H
26#define __DRMAA_UTILS__XMALLOC_H
27
28#ifdef HAVE_CONFIG_H
29#       include <config.h>
30#endif
31
32#include <drmaa_utils/compat.h>
33
34/**
35 * @defgroup xmalloc  Memory allocation/deallocation routines.
36 */
37/* @{ */
38
39
40/**
41 * Allocates <code> sizeof(type) </code> bytes.  Address of block is stored
42 * in @a p.  Upon failure FSD_ERRNO_NO_MEMORY is raised and @a p is NULL.
43 */
44#define fsd_malloc( p, type ) \
45        fsd_malloc_( (void**)(void*)&(p), sizeof(type) )
46
47/**
48 * Allocates <code> n * sizeof(type) </code> bytes of memory and stores
49 * address in \a p.  Allocated block is filled with zeros.  Upon failure
50 * error FSD_ERRNO_NO_MEMORY is raised.
51 * \c NULL is assigned to \a p on error or when <code> n == 0 </code>.
52 */
53#define fsd_calloc( p, n, type ) \
54        fsd_calloc_( (void**)(void*)&(p), (n), sizeof(type) )
55
56#define fsd_realloc( p, n, type ) \
57        fsd_realloc_( (void**)(void*)&(p), (n)*sizeof(type) )
58
59/**
60 * Fress previously allocated memory pointed by @a p.
61 * When <code> p == NULL </code> it does nothing.
62 */
63void fsd_free( void *p );
64
65void *fsd_malloc_( void **p, size_t size );
66void *fsd_calloc_( void **p, size_t n, size_t size );
67void *fsd_realloc_( void **p, size_t size );
68
69
70#define fsd_malloc_noraise( p, type ) \
71        fsd_malloc_noraise_( (void**)(void*)&(p), sizeof(type) )
72
73#define fsd_calloc_noraise( p, n, type ) \
74        fsd_calloc_noraise_( (void**)(void*)&(p), (n), sizeof(type) )
75
76#define fsd_realloc_noraise( p, n, type ) \
77        fsd_realloc_noraise_( (void**)(void*)&(p), (n)*sizeof(type) )
78
79#define fsd_free_noraise( p )  (fsd_free(p), 0)
80
81int fsd_malloc_noraise_( void **p, size_t size );
82int fsd_calloc_noraise_( void **p, size_t n, size_t size );
83int fsd_realloc_noraise_( void **p, size_t size );
84
85/* @} */
86
87#endif /* __DRMAA_UTILS__XMALLOC_H */
88
Note: See TracBrowser for help on using the repository browser.