1Tcl_Alloc(3) Tcl Library Procedures Tcl_Alloc(3)
2
3
4
5______________________________________________________________________________
6
8 Tcl_Alloc, Tcl_Free, Tcl_Realloc, Tcl_AttemptAlloc, Tcl_AttemptRealloc,
9 ckalloc, ckfree, ckrealloc, attemptckalloc, attemptckrealloc - allocate
10 or free heap memory
11
13 #include <tcl.h>
14
15 char *
16 Tcl_Alloc(size)
17
18 void
19 Tcl_Free(ptr)
20
21 char *
22 Tcl_Realloc(ptr, size)
23
24 char *
25 Tcl_AttemptAlloc(size)
26
27 char *
28 Tcl_AttemptRealloc(ptr, size)
29
30 char *
31 ckalloc(size)
32
33 void
34 ckfree(ptr)
35
36 char *
37 ckrealloc(ptr, size)
38
39 char *
40 attemptckalloc(size)
41
42 char *
43 attemptckrealloc(ptr, size)
44
46 unsigned int size (in) Size in bytes of the memory block to allocate.
47
48 char *ptr (in) Pointer to memory block to free or realloc.
49______________________________________________________________________________
50
51
53 These procedures provide a platform and compiler independent interface
54 for memory allocation. Programs that need to transfer ownership of
55 memory blocks between Tcl and other modules should use these routines
56 rather than the native malloc() and free() routines provided by the C
57 run-time library.
58
59 Tcl_Alloc returns a pointer to a block of at least size bytes suitably
60 aligned for any use.
61
62 Tcl_Free makes the space referred to by ptr available for further allo‐
63 cation.
64
65 Tcl_Realloc changes the size of the block pointed to by ptr to size
66 bytes and returns a pointer to the new block. The contents will be
67 unchanged up to the lesser of the new and old sizes. The returned
68 location may be different from ptr. If ptr is NULL, this is equivalent
69 to calling Tcl_Alloc with just the size argument.
70
71 Tcl_AttemptAlloc and Tcl_AttemptRealloc are identical in function to
72 Tcl_Alloc and Tcl_Realloc, except that Tcl_AttemptAlloc and
73 Tcl_AttemptRealloc will not cause the Tcl interpreter to panic if the
74 memory allocation fails. If the allocation fails, these functions will
75 return NULL. Note that on some platforms, but not all, attempting to
76 allocate a zero-sized block of memory will also cause these functions
77 to return NULL.
78
79 The procedures ckalloc, ckfree, ckrealloc, attemptckalloc, and
80 attemptckrealloc are implemented as macros. Normally, they are syn‐
81 onyms for the corresponding procedures documented on this page. When
82 Tcl and all modules calling Tcl are compiled with TCL_MEM_DEBUG
83 defined, however, these macros are redefined to be special debugging
84 versions of these procedures. To support Tcl's memory debugging within
85 a module, use the macros rather than direct calls to Tcl_Alloc, etc.
86
87
89 alloc, allocation, free, malloc, memory, realloc, TCL_MEM_DEBUG
90
91
92
93Tcl 7.5 Tcl_Alloc(3)