-
Notifications
You must be signed in to change notification settings - Fork 0
/
AS_UTL_alloc.H
71 lines (60 loc) · 2.38 KB
/
AS_UTL_alloc.H
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
/**************************************************************************
* This file is part of Celera Assembler, a software program that
* assembles whole-genome shotgun reads into contigs and scaffolds.
* Copyright (C) 1999-2004, Applera Corporation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General 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 General Public License for more details.
*
* You should have received (LICENSE.txt) 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
*************************************************************************/
#ifndef AS_UTL_ALLOC_H
#define AS_UTL_ALLOC_H
static const char *rcsid_AS_UTL_ALLOC_H = "$Id: AS_UTL_alloc.H 4371 2013-08-01 17:19:47Z brianwalenz $";
//
// The safe_*alloc routines are the same as the normal routines,
// except they print a standard message and assert if memory cannot
// be allocated.
//
// safe_free is somewhat useless. It frees the memory, then sets the
// pointer to NULL. It's useless because many times the pointer we
// set to NULL is a local copy, e.g.:
//
// void freeSomeStructure(SomeStructure *p) {
// safe_free(p->data);
// safe_free(p);
// }
//
void *safe_calloc(size_t num, size_t len);
void *safe_malloc(size_t len);
void *safe_realloc(void *q, size_t len);
void safe_free2(void *);
#define safe_free(Q) { safe_free2(Q); Q = NULL; }
// And, thanks, GNU. strdup() (and, sigh, probably lots others) are
// implemented as a macro that calls free(), which then gets expanded
// into our bogus function.
//
#ifndef X86_GCC_LINUX
#define malloc(X) use_safe_malloc_instead(X)
#define calloc(X,Y) use_safe_calloc_instead(X,Y)
#define realloc(X,Y) use_safe_realloc_instead(X,Y)
#define free(X) use_safe_free_instead(X)
#endif
template<class T>
inline void zero(T* ptr, size_t num)
{
for (size_t a = 0; a < num; a++)
{
ptr[a] = NULL;
}
}
#endif // AS_UTL_ALLOC_H