mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-26 15:36:14 +01:00
Add size accessor to RcBox and ArcBox
It may be useful to know how big a reference counted allocation is outside of internal checks.
This commit is contained in:
parent
00a723f597
commit
43b7a8f158
@ -3477,6 +3477,7 @@ g_rc_box_dup
|
|||||||
g_rc_box_acquire
|
g_rc_box_acquire
|
||||||
g_rc_box_release
|
g_rc_box_release
|
||||||
g_rc_box_release_full
|
g_rc_box_release_full
|
||||||
|
g_rc_box_get_size
|
||||||
</SECTION>
|
</SECTION>
|
||||||
|
|
||||||
<SECTION>
|
<SECTION>
|
||||||
@ -3489,6 +3490,7 @@ g_arc_box_dup
|
|||||||
g_arc_box_acquire
|
g_arc_box_acquire
|
||||||
g_arc_box_release
|
g_arc_box_release
|
||||||
g_arc_box_release_full
|
g_arc_box_release_full
|
||||||
|
g_arc_box_get_size
|
||||||
</SECTION>
|
</SECTION>
|
||||||
|
|
||||||
<SECTION>
|
<SECTION>
|
||||||
|
@ -354,3 +354,26 @@ g_arc_box_release_full (gpointer mem_block,
|
|||||||
g_free (real_box);
|
g_free (real_box);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* g_arc_box_get_size:
|
||||||
|
* @mem_block: (not nullable): a pointer to reference counted data
|
||||||
|
*
|
||||||
|
* Retrieves the size of the reference counted data pointed by @mem_block.
|
||||||
|
*
|
||||||
|
* Returns: the size of the data
|
||||||
|
*
|
||||||
|
* Since: 2.58
|
||||||
|
*/
|
||||||
|
gsize
|
||||||
|
g_arc_box_get_size (gpointer mem_block)
|
||||||
|
{
|
||||||
|
GArcBox *real_box = G_ARC_BOX (mem_block);
|
||||||
|
|
||||||
|
g_return_val_if_fail (mem_block != NULL, 0);
|
||||||
|
#ifndef G_DISABLE_ASSERT
|
||||||
|
g_return_val_if_fail (real_box->magic == G_BOX_MAGIC, 0);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return real_box->mem_size;
|
||||||
|
}
|
||||||
|
@ -424,3 +424,26 @@ g_rc_box_release_full (gpointer mem_block,
|
|||||||
g_free (real_box);
|
g_free (real_box);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* g_rc_box_get_size:
|
||||||
|
* @mem_block: (not nullable): a pointer to reference counted data
|
||||||
|
*
|
||||||
|
* Retrieves the size of the reference counted data pointed by @mem_block.
|
||||||
|
*
|
||||||
|
* Returns: the size of the data
|
||||||
|
*
|
||||||
|
* Since: 2.58
|
||||||
|
*/
|
||||||
|
gsize
|
||||||
|
g_rc_box_get_size (gpointer mem_block)
|
||||||
|
{
|
||||||
|
GRcBox *real_box = G_RC_BOX (mem_block);
|
||||||
|
|
||||||
|
g_return_val_if_fail (mem_block != NULL, 0);
|
||||||
|
#ifndef G_DISABLE_ASSERT
|
||||||
|
g_return_val_if_fail (real_box->magic == G_BOX_MAGIC, 0);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return real_box->mem_size;
|
||||||
|
}
|
||||||
|
@ -41,6 +41,9 @@ GLIB_AVAILABLE_IN_2_58
|
|||||||
void g_rc_box_release_full (gpointer mem_block,
|
void g_rc_box_release_full (gpointer mem_block,
|
||||||
GDestroyNotify clear_func);
|
GDestroyNotify clear_func);
|
||||||
|
|
||||||
|
GLIB_AVAILABLE_IN_2_58
|
||||||
|
gsize g_rc_box_get_size (gpointer mem_block);
|
||||||
|
|
||||||
GLIB_AVAILABLE_IN_2_58
|
GLIB_AVAILABLE_IN_2_58
|
||||||
gpointer g_arc_box_alloc (gsize block_size) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(1);
|
gpointer g_arc_box_alloc (gsize block_size) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(1);
|
||||||
GLIB_AVAILABLE_IN_2_58
|
GLIB_AVAILABLE_IN_2_58
|
||||||
@ -56,6 +59,9 @@ GLIB_AVAILABLE_IN_2_58
|
|||||||
void g_arc_box_release_full (gpointer mem_block,
|
void g_arc_box_release_full (gpointer mem_block,
|
||||||
GDestroyNotify clear_func);
|
GDestroyNotify clear_func);
|
||||||
|
|
||||||
|
GLIB_AVAILABLE_IN_2_58
|
||||||
|
gsize g_arc_box_get_size (gpointer mem_block);
|
||||||
|
|
||||||
#define g_rc_box_new(type) \
|
#define g_rc_box_new(type) \
|
||||||
((type *) g_rc_box_alloc (sizeof (type)))
|
((type *) g_rc_box_alloc (sizeof (type)))
|
||||||
#define g_rc_box_new0(type) \
|
#define g_rc_box_new0(type) \
|
||||||
|
@ -31,6 +31,7 @@ test_rcbox_new (void)
|
|||||||
Point *a = g_rc_box_new (Point);
|
Point *a = g_rc_box_new (Point);
|
||||||
|
|
||||||
g_assert_nonnull (a);
|
g_assert_nonnull (a);
|
||||||
|
g_assert_cmpuint (g_rc_box_get_size (a), ==, sizeof (Point));
|
||||||
|
|
||||||
g_rc_box_release (a);
|
g_rc_box_release (a);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user