[glib/document-oom-behavior] mem: Document OOM behavior for allocations
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/document-oom-behavior] mem: Document OOM behavior for allocations
- Date: Fri, 19 Aug 2022 12:31:17 +0000 (UTC)
commit 1df83acb876c8325dfadf96bafc5751e1d9e5447
Author: Matthias Clasen <mclasen redhat com>
Date: Fri Aug 19 08:29:36 2022 -0400
mem: Document OOM behavior for allocations
For all the memory allocator APIS, document
that they terminate the program on failure.
This was so far only mentioned in the long description,
and in the docs for g_try_malloc(). And with gi-docgen
style docs, the long description is going away.
glib/gmem.c | 45 +++++++++++++++++++++++++++++++++------------
1 file changed, 33 insertions(+), 12 deletions(-)
---
diff --git a/glib/gmem.c b/glib/gmem.c
index f6c806552b..abbd4e751b 100644
--- a/glib/gmem.c
+++ b/glib/gmem.c
@@ -111,10 +111,13 @@ static GMemVTable glib_mem_vtable = {
/**
* g_malloc:
* @n_bytes: the number of bytes to allocate
- *
+ *
* Allocates @n_bytes bytes of memory.
* If @n_bytes is 0 it returns %NULL.
- *
+ *
+ * If the allocation fails (because the system is out of memory),
+ * the program is terminated.
+ *
* Returns: a pointer to the allocated memory
*/
gpointer
@@ -141,10 +144,13 @@ g_malloc (gsize n_bytes)
/**
* g_malloc0:
* @n_bytes: the number of bytes to allocate
- *
+ *
* Allocates @n_bytes bytes of memory, initialized to 0's.
* If @n_bytes is 0 it returns %NULL.
- *
+ *
+ * If the allocation fails (because the system is out of memory),
+ * the program is terminated.
+ *
* Returns: a pointer to the allocated memory
*/
gpointer
@@ -172,13 +178,16 @@ g_malloc0 (gsize n_bytes)
* g_realloc:
* @mem: (nullable): the memory to reallocate
* @n_bytes: new size of the memory in bytes
- *
+ *
* Reallocates the memory pointed to by @mem, so that it now has space for
* @n_bytes bytes of memory. It returns the new address of the memory, which may
* have been moved. @mem may be %NULL, in which case it's considered to
* have zero-length. @n_bytes may be 0, in which case %NULL will be returned
* and @mem will be freed unless it is %NULL.
- *
+ *
+ * If the allocation fails (because the system is out of memory),
+ * the program is terminated.
+ *
* Returns: the new address of the allocated memory
*/
gpointer
@@ -345,10 +354,13 @@ g_try_realloc (gpointer mem,
* g_malloc_n:
* @n_blocks: the number of blocks to allocate
* @n_block_bytes: the size of each block in bytes
- *
+ *
* This function is similar to g_malloc(), allocating (@n_blocks * @n_block_bytes) bytes,
* but care is taken to detect possible overflow during multiplication.
- *
+ *
+ * If the allocation fails (because the system is out of memory),
+ * the program is terminated.
+ *
* Since: 2.24
* Returns: a pointer to the allocated memory
*/
@@ -369,10 +381,13 @@ g_malloc_n (gsize n_blocks,
* g_malloc0_n:
* @n_blocks: the number of blocks to allocate
* @n_block_bytes: the size of each block in bytes
- *
+ *
* This function is similar to g_malloc0(), allocating (@n_blocks * @n_block_bytes) bytes,
* but care is taken to detect possible overflow during multiplication.
- *
+ *
+ * If the allocation fails (because the system is out of memory),
+ * the program is terminated.
+ *
* Since: 2.24
* Returns: a pointer to the allocated memory
*/
@@ -394,10 +409,13 @@ g_malloc0_n (gsize n_blocks,
* @mem: (nullable): the memory to reallocate
* @n_blocks: the number of blocks to allocate
* @n_block_bytes: the size of each block in bytes
- *
+ *
* This function is similar to g_realloc(), allocating (@n_blocks * @n_block_bytes) bytes,
* but care is taken to detect possible overflow during multiplication.
- *
+ *
+ * If the allocation fails (because the system is out of memory),
+ * the program is terminated.
+ *
* Since: 2.24
* Returns: the new address of the allocated memory
*/
@@ -556,6 +574,9 @@ g_mem_profile (void)
* alignment value. Additionally, it will detect possible overflow during
* multiplication.
*
+ * If the allocation fails (because the system is out of memory),
+ * the program is terminated.
+ *
* Aligned memory allocations returned by this function can only be
* freed using g_aligned_free().
*
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]