| 1 |
'\" t |
| 2 |
.\" Copyright 2012, Michael Kerrisk <[email protected]> |
| 3 |
.\" Copyright, the authors of the Linux man-pages project |
| 4 |
.\" |
| 5 |
.\" SPDX-License-Identifier: Linux-man-pages-copyleft |
| 6 |
.\" |
| 7 |
.TH malloc_usable_size 3 2026-02-08 "Linux man-pages 6.18" |
| 8 |
.SH NAME |
| 9 |
malloc_usable_size \- obtain size of block of memory allocated from heap |
| 10 |
.SH LIBRARY |
| 11 |
Standard C library |
| 12 |
.RI ( libc ,\~ \-lc ) |
| 13 |
.SH SYNOPSIS |
| 14 |
.nf |
| 15 |
.B #include <malloc.h> |
| 16 |
.P |
| 17 |
.BI "size_t malloc_usable_size(void *_Nullable " ptr ); |
| 18 |
.fi |
| 19 |
.SH DESCRIPTION |
| 20 |
This function can be used for |
| 21 |
diagnostics or statistics about allocations from |
| 22 |
.BR malloc (3) |
| 23 |
or a related function. |
| 24 |
.SH RETURN VALUE |
| 25 |
.BR malloc_usable_size () |
| 26 |
returns a value no less than |
| 27 |
the size of the block of allocated memory pointed to by |
| 28 |
.IR ptr . |
| 29 |
If |
| 30 |
.I ptr |
| 31 |
is NULL, 0 is returned. |
| 32 |
.SH ATTRIBUTES |
| 33 |
For an explanation of the terms used in this section, see |
| 34 |
.BR attributes (7). |
| 35 |
.TS |
| 36 |
allbox; |
| 37 |
lbx lb lb |
| 38 |
l l l. |
| 39 |
Interface Attribute Value |
| 40 |
T{ |
| 41 |
.na |
| 42 |
.nh |
| 43 |
.BR malloc_usable_size () |
| 44 |
T} Thread safety MT-Safe |
| 45 |
.TE |
| 46 |
.SH STANDARDS |
| 47 |
GNU. |
| 48 |
.SH CAVEATS |
| 49 |
The value returned by |
| 50 |
.BR malloc_usable_size () |
| 51 |
may be greater than the requested size of the allocation |
| 52 |
because of various internal implementation details, |
| 53 |
none of which the programmer should rely on. |
| 54 |
This function is intended to only be used |
| 55 |
for diagnostics and statistics; |
| 56 |
writing to the excess memory without first calling |
| 57 |
.BR realloc (3) |
| 58 |
to resize the allocation is not supported. |
| 59 |
The returned value is only valid at the time of the call. |
| 60 |
.SH SEE ALSO |
| 61 |
.BR malloc (3) |