Merge branch 'cb/limits'
[plumiferos.git] / intern / guardedalloc / MEM_guardedalloc.h
blobe1eccac784431c6a05fd9cbe90f622f31c7d81c5
1 /**
2 * $Id: MEM_guardedalloc.h 9080 2006-11-27 13:59:55Z ton $
3 * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version. The Blender
9 * Foundation also sells licenses for use in proprietary software under
10 * the Blender License. See http://www.blender.org/BL/ for information
11 * about this.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software Foundation,
20 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
23 * All rights reserved.
25 * The Original Code is: all of this file.
27 * Contributor(s): none yet.
29 * ***** END GPL/BL DUAL LICENSE BLOCK *****
32 /**
34 * $Id: MEM_guardedalloc.h 9080 2006-11-27 13:59:55Z ton $
35 * Copyright (C) 2001 NaN Technologies B.V.
36 * Guarded memory (de)allocation
39 * @mainpage MEM - c-style guarded memory allocation
41 * @section about About the MEM module
43 * MEM provides guarded malloc/calloc calls. All memory is enclosed by
44 * pads, to detect out-of-bound writes. All blocks are placed in a
45 * linked list, so they remain reachable at all times. There is no
46 * back-up in case the linked-list related data is lost.
48 * @section issues Known issues with MEM
50 * There are currently no known issues with MEM. Note that there is a
51 * second intern/ module with MEM_ prefix, for use in c++.
53 * @section dependencies Dependencies
55 * - stdlib
57 * - stdio
59 * */
61 #ifndef MEM_MALLOCN_H
62 #define MEM_MALLOCN_H
64 /* Needed for FILE* */
65 #include "stdio.h"
67 #ifdef __cplusplus
68 extern "C" {
69 #endif
71 /** Returns the lenght of the allocated memory segment pointed at
72 * by vmemh. If the pointer was not previously allocated by this
73 * module, the result is undefined.*/
74 int MEM_allocN_len(void *vmemh);
76 /**
77 * Release memory previously allocatred by this module.
79 short MEM_freeN(void *vmemh);
81 /**
82 * Duplicates a block of memory, and returns a pointer to the
83 * newly allocated block. */
84 void *MEM_dupallocN(void *vmemh);
86 /**
87 * Allocate a block of memory of size len, with tag name str. The
88 * memory is cleared. The name must be static, because only a
89 * pointer to it is stored ! */
90 void *MEM_callocN(unsigned int len, const char * str);
92 /** Allocate a block of memory of size len, with tag name str. The
93 * name must be a static, because only a pointer to it is stored !
94 * */
95 void *MEM_mallocN(unsigned int len, const char * str);
97 /** Same as callocN, clears memory and uses mmap (disk cached) if supported.
98 Can be free'd with MEM_freeN as usual.
99 * */
100 void *MEM_mapallocN(unsigned int len, const char * str);
102 /** Print a list of the names and sizes of all allocated memory
103 * blocks. */
104 void MEM_printmemlist(void);
106 /** Set the callback function for error output. */
107 void MEM_set_error_callback(void (*func)(char *));
110 * Are the start/end block markers still correct ?
112 * @retval 0 for correct memory, 1 for corrupted memory. */
113 int MEM_check_memory_integrity(void);
115 /** Set thread locking functions for safe memory allocation from multiple
116 threads, pass NULL pointers to disable thread locking again. */
117 void MEM_set_lock_callback(void (*lock)(void), void (*unlock)(void));
119 /** Attempt to enforce OSX (or other OS's) to have malloc and stack nonzero */
120 void MEM_set_memory_debug(void);
123 #ifdef __cplusplus
125 #endif
127 #endif