1Tcl_Alloc(3)                Tcl Library Procedures                Tcl_Alloc(3)
2
3
4
5______________________________________________________________________________
6

NAME

8       Tcl_Alloc, Tcl_Free, Tcl_Realloc, Tcl_AttemptAlloc, Tcl_AttemptRealloc,
9       Tcl_GetMemoryInfo,  ckalloc,  ckfree,  ckrealloc,  attemptckalloc,  at‐
10       temptckrealloc - allocate or free heap memory
11

SYNOPSIS

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       void
31       Tcl_GetMemoryInfo(dsPtr)
32
33       char *
34       ckalloc(size)
35
36       void
37       ckfree(ptr)
38
39       char *
40       ckrealloc(ptr, size)
41
42       char *
43       attemptckalloc(size)
44
45       char *
46       attemptckrealloc(ptr, size)
47

ARGUMENTS

49       unsigned int size (in)   Size in bytes of the memory block to allocate.
50
51       char *ptr (in)           Pointer to memory block to free or realloc.
52
53       Tcl_DString *dsPtr (in)  Initialized DString pointer.
54______________________________________________________________________________
55
56

DESCRIPTION

58       These  procedures provide a platform and compiler independent interface
59       for memory allocation.  Programs that need  to  transfer  ownership  of
60       memory  blocks  between Tcl and other modules should use these routines
61       rather than the native malloc() and free() routines provided by  the  C
62       run-time library.
63
64       Tcl_Alloc  returns a pointer to a block of at least size bytes suitably
65       aligned for any use.
66
67       Tcl_Free makes the space referred to by ptr available for further allo‐
68       cation.
69
70       Tcl_Realloc  changes  the  size  of the block pointed to by ptr to size
71       bytes and returns a pointer to the new block.  The contents will be un‐
72       changed  up to the lesser of the new and old sizes.  The returned loca‐
73       tion may be different from ptr.  If ptr is NULL, this is equivalent  to
74       calling Tcl_Alloc with just the size argument.
75
76       Tcl_AttemptAlloc  and  Tcl_AttemptRealloc  are identical in function to
77       Tcl_Alloc and Tcl_Realloc, except  that  Tcl_AttemptAlloc  and  Tcl_At‐
78       temptRealloc  will not cause the Tcl interpreter to panic if the memory
79       allocation fails.  If the allocation fails, these functions will return
80       NULL.  Note that on some platforms, but not all, attempting to allocate
81       a zero-sized block of memory will also cause these functions to  return
82       NULL.
83
84       The  procedures  ckalloc,  ckfree,  ckrealloc,  attemptckalloc, and at‐
85       temptckrealloc are implemented as macros.  Normally, they are  synonyms
86       for the corresponding procedures documented on this page.  When Tcl and
87       all modules calling Tcl are compiled with TCL_MEM_DEBUG  defined,  how‐
88       ever,  these  macros  are redefined to be special debugging versions of
89       these procedures.  To support Tcl's memory debugging within  a  module,
90       use the macros rather than direct calls to Tcl_Alloc, etc.
91
92       Tcl_GetMemoryInfo  appends  a list-of-lists of memory stats to the pro‐
93       vided DString. This function cannot be used in stub-enabled extensions,
94       and  it  is  only available if Tcl is compiled with the threaded memory
95       allocator.
96
97

KEYWORDS

99       alloc, allocation, free, malloc, memory, realloc, TCL_MEM_DEBUG
100
101
102
103Tcl                                   7.5                         Tcl_Alloc(3)
Impressum