struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / util / newalloc.h
blob4da6932ab516d918aeeeac3279519b3d940a2b47
1 /*-------------------------------------------------------------------------
2 newalloc.h - SDCC Memory allocation functions
4 These functions are wrappers for the standard malloc, realloc and free
5 functions.
7 This program is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 2, or (at your option) any
10 later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 -------------------------------------------------------------------------*/
22 #if !defined(_NewAlloc_H)
24 #define _NewAlloc_H
26 #include <memory.h>
28 typedef struct _allocTrace
30 int num;
31 int max;
32 void **palloced;
33 } allocTrace;
36 -------------------------------------------------------------------------------
37 Clear_realloc - Reallocate a memory block and clear any memory added with
38 out of memory error detection
40 -------------------------------------------------------------------------------
43 void *Clear_realloc (void *OldPtr, size_t OldSize, size_t NewSize);
46 -------------------------------------------------------------------------------
47 Safe_realloc - Reallocate a memory block with out of memory error detection
49 -------------------------------------------------------------------------------
52 void *Safe_realloc (void *OldPtr, size_t NewSize);
55 -------------------------------------------------------------------------------
56 Safe_calloc - Allocate a block of memory from the application heap, clearing
57 all data to zero and checking for out or memory errors.
59 -------------------------------------------------------------------------------
62 void *Safe_calloc (size_t Elements, size_t Size);
65 -------------------------------------------------------------------------------
66 Safe_malloc - Allocate a block of memory from the application heap
67 and checking for out or memory errors.
69 -------------------------------------------------------------------------------
72 void *Safe_malloc (size_t Size);
74 /** Replacement for Safe_malloc that also zeros memory. To make it interchangable.
76 void *Safe_alloc (size_t Size);
78 /** Function to make the replacements complete.
80 void Safe_free (void *p);
82 /** Creates a copy of a string with specified length in a safe way.
84 char *Safe_strndup (const char *sz, size_t len);
86 /** Creates a copy of a string in a safe way.
88 char *Safe_strdup (const char *sz);
90 /** Logs the allocated memory 'p' in the given trace for batch freeing
91 later using freeTrace.
93 void *traceAlloc (allocTrace * ptrace, void *p);
95 /** Frees all the memory logged in the trace and resets the trace.
97 void freeTrace (allocTrace * ptrace);
99 #endif