Debian Codegraph @

doc/Alloc.3

raw
1 '\"
2 '\" Copyright (c) 1995-1996 Sun Microsystems, Inc.
3 '\"
4 '\" See the file "license.terms" for information on usage and redistribution
5 '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
6 '\"
7 .TH Tcl_Alloc 3 7.5 Tcl "Tcl Library Procedures"
8 .so man.macros
9 .BS
10 .SH NAME
11 Tcl_Alloc, Tcl_Free, Tcl_Realloc, Tcl_AttemptAlloc, Tcl_AttemptRealloc, Tcl_GetMemoryInfo, ckalloc, ckfree, ckrealloc, attemptckalloc, attemptckrealloc \- allocate or free heap memory
12 .SH SYNOPSIS
13 .nf
14 \fB#include <tcl.h>\fR
15 .sp
16 char *
17 \fBTcl_Alloc\fR(\fIsize\fR)
18 .sp
19 void
20 \fBTcl_Free\fR(\fIptr\fR)
21 .sp
22 char *
23 \fBTcl_Realloc\fR(\fIptr, size\fR)
24 .sp
25 char *
26 \fBTcl_AttemptAlloc\fR(\fIsize\fR)
27 .sp
28 char *
29 \fBTcl_AttemptRealloc\fR(\fIptr, size\fR)
30 .sp
31 void
32 \fBTcl_GetMemoryInfo\fR(\fIdsPtr\fR)
33 .sp
34 char *
35 \fBckalloc\fR(\fIsize\fR)
36 .sp
37 void
38 \fBckfree\fR(\fIptr\fR)
39 .sp
40 char *
41 \fBckrealloc\fR(\fIptr, size\fR)
42 .sp
43 char *
44 \fBattemptckalloc\fR(\fIsize\fR)
45 .sp
46 char *
47 \fBattemptckrealloc\fR(\fIptr, size\fR)
48 .SH ARGUMENTS
49 .AS char *size
50 .AP "unsigned int" size in
51 Size in bytes of the memory block to allocate.
52 .AP char *ptr in
53 Pointer to memory block to free or realloc.
54 .AP Tcl_DString *dsPtr in
55 Initialized DString pointer.
56 .BE
57
58 .SH DESCRIPTION
59 .PP
60 These procedures provide a platform and compiler independent interface
61 for memory allocation. Programs that need to transfer ownership of
62 memory blocks between Tcl and other modules should use these routines
63 rather than the native \fBmalloc()\fR and \fBfree()\fR routines
64 provided by the C run-time library.
65 .PP
66 \fBTcl_Alloc\fR returns a pointer to a block of at least \fIsize\fR
67 bytes suitably aligned for any use.
68 .PP
69 \fBTcl_Free\fR makes the space referred to by \fIptr\fR available for
70 further allocation.
71 .PP
72 \fBTcl_Realloc\fR changes the size of the block pointed to by
73 \fIptr\fR to \fIsize\fR bytes and returns a pointer to the new block.
74 The contents will be unchanged up to the lesser of the new and old
75 sizes. The returned location may be different from \fIptr\fR. If
76 \fIptr\fR is NULL, this is equivalent to calling \fBTcl_Alloc\fR with
77 just the \fIsize\fR argument.
78 .PP
79 \fBTcl_AttemptAlloc\fR and \fBTcl_AttemptRealloc\fR are identical in
80 function to \fBTcl_Alloc\fR and \fBTcl_Realloc\fR, except that
81 \fBTcl_AttemptAlloc\fR and \fBTcl_AttemptRealloc\fR will not cause the Tcl
82 interpreter to \fBpanic\fR if the memory allocation fails. If the
83 allocation fails, these functions will return NULL. Note that on some
84 platforms, but not all, attempting to allocate a zero-sized block of
85 memory will also cause these functions to return NULL.
86 .PP
87 The procedures \fBckalloc\fR, \fBckfree\fR, \fBckrealloc\fR,
88 \fBattemptckalloc\fR, and \fBattemptckrealloc\fR are implemented
89 as macros. Normally, they are synonyms for the corresponding
90 procedures documented on this page. When Tcl and all modules
91 calling Tcl are compiled with \fBTCL_MEM_DEBUG\fR defined, however,
92 these macros are redefined to be special debugging versions
93 of these procedures. To support Tcl's memory debugging within a
94 module, use the macros rather than direct calls to \fBTcl_Alloc\fR, etc.
95
96 \fBTcl_GetMemoryInfo\fR appends a list-of-lists of memory stats to the
97 provided DString. This function cannot be used in stub-enabled extensions,
98 and it is only available if Tcl is compiled with the threaded memory allocator.
99
100 .SH KEYWORDS
101 alloc, allocation, free, malloc, memory, realloc, TCL_MEM_DEBUG