2 '\" Copyright (c) 1995-1996 Sun Microsystems, Inc.
4 '\" See the file "license.terms" for information on usage and redistribution
5 '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
10 .TH Tcl_Alloc 3 7.5 Tcl "Tcl Library Procedures"
13 Tcl_Alloc, Tcl_Free, Tcl_Realloc, Tcl_AttemptAlloc, Tcl_AttemptRealloc, ckalloc, ckfree, ckrealloc, attemptckalloc, attemptckrealloc \- allocate or free heap memory
16 \fB#include <tcl.h>\fR
19 \fBTcl_Alloc\fR(\fIsize\fR)
22 \fBTcl_Free\fR(\fIptr\fR)
25 \fBTcl_Realloc\fR(\fIptr, size\fR)
28 \fBTcl_AttemptAlloc\fR(\fIsize\fR)
31 \fBTcl_AttemptRealloc\fR(\fIptr, size\fR)
34 \fBckalloc\fR(\fIsize\fR)
37 \fBckfree\fR(\fIptr\fR)
40 \fBckrealloc\fR(\fIptr, size\fR)
43 \fBattemptckalloc\fR(\fIsize\fR)
46 \fBattemptckrealloc\fR(\fIptr, size\fR)
50 Size in bytes of the memory block to allocate.
52 Pointer to memory block to free or realloc.
57 These procedures provide a platform and compiler independent interface
58 for memory allocation. Programs that need to transfer ownership of
59 memory blocks between Tcl and other modules should use these routines
60 rather than the native \fBmalloc()\fR and \fBfree()\fR routines
61 provided by the C run-time library.
63 \fBTcl_Alloc\fR returns a pointer to a block of at least \fIsize\fR
64 bytes suitably aligned for any use.
66 \fBTcl_Free\fR makes the space referred to by \fIptr\fR available for
69 \fBTcl_Realloc\fR changes the size of the block pointed to by
70 \fIptr\fR to \fIsize\fR bytes and returns a pointer to the new block.
71 The contents will be unchanged up to the lesser of the new and old
72 sizes. The returned location may be different from \fIptr\fR.
74 \fBTcl_AttemptAlloc\fR and \fBTcl_AttemptRealloc\fR are identical in
75 function to \fBTcl_Alloc\fR and \fBTcl_Realloc\fR, except that
76 \fBTcl_AttemptAlloc\fR and \fBTcl_AttemptRealloc\fR will not cause the Tcl
77 interpreter to \fBpanic\fR if the memory allocation fails. If the
78 allocation fails, these functions will return NULL. Note that on some
79 platforms, attempting to allocate a block of memory will also cause
80 these functions to return NULL.
82 The procedures \fBckalloc\fR, \fBckfree\fR, \fBckrealloc\fR,
83 \fBattemptckalloc\fR, and \fBattemptckrealloc\fR are implemented
84 as macros. Normally, they are synonyms for the corresponding
85 procedures documented on this page. When Tcl and all modules
86 calling Tcl are compiled with \fBTCL_MEM_DEBUG\fR defined, however,
87 these macros are redefined to be special debugging versions of
88 of these procedures. To support Tcl's memory debugging within a
89 module, use the macros rather than direct calls to \fBTcl_Alloc\fR, etc.
92 alloc, allocation, free, malloc, memory, realloc, TCL_MEM_DEBUG