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 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.
69
70 Tcl_AttemptAlloc and Tcl_AttemptRealloc are identical in function to
71 Tcl_Alloc and Tcl_Realloc, except that Tcl_AttemptAlloc and
72 Tcl_AttemptRealloc will not cause the Tcl interpreter to panic if the
73 memory allocation fails. If the allocation fails, these functions will
74 return NULL. Note that on some platforms, attempting to allocate a
75 block of memory will also cause these functions to return NULL.
76
77 The procedures ckalloc, ckfree, ckrealloc, attemptckalloc, and
78 attemptckrealloc are implemented as macros. Normally, they are syn‐
79 onyms for the corresponding procedures documented on this page. When
80 Tcl and all modules calling Tcl are compiled with TCL_MEM_DEBUG
81 defined, however, these macros are redefined to be special debugging
82 versions of of these procedures. To support Tcl's memory debugging
83 within a module, use the macros rather than direct calls to Tcl_Alloc,
84 etc.
85
86
88 alloc, allocation, free, malloc, memory, realloc, TCL_MEM_DEBUG
89
90
91
92Tcl 7.5 Tcl_Alloc(3)