]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
astobj2: Reduce memory overhead.
authorCorey Farrell <git@cfware.com>
Thu, 27 Sep 2018 09:51:43 +0000 (05:51 -0400)
committerCorey Farrell <git@cfware.com>
Thu, 27 Sep 2018 23:48:37 +0000 (19:48 -0400)
Reduce options to 2-bit field, magic to 30 bit field.  Move ref_counter
next to options the fields will pack.

This reduces memory overhead for every ao2 object by 8 bytes on x86_64.

Change-Id: Idc1baabb35ec3b3d8de463c4fa3011eaf7fcafb5

main/astobj2.c

index 147df7aedc4a6760e44eb919dd57eaaf141d8651..741bb64650f361f08cc3c3f0f973dca74f7702a1 100644 (file)
@@ -50,20 +50,21 @@ static FILE *ref_log;
  * The magic number is used for consistency check.
  */
 struct __priv_data {
-       int ref_counter;
        ao2_destructor_fn destructor_fn;
 #if defined(AO2_DEBUG)
        /*! User data size for stats */
        size_t data_size;
 #endif
+       /*! Number of references held for this object */
+       int ref_counter;
        /*! The ao2 object option flags */
-       uint32_t options;
+       uint32_t options:2;
        /*! magic number.  This is used to verify that a pointer passed in is a
         *  valid astobj2 */
-       uint32_t magic;
+       uint32_t magic:30;
 };
 
-#define        AO2_MAGIC       0xa570b123
+#define        AO2_MAGIC       0x3a70b123
 
 /*!
  * What an astobj2 object looks like: fixed-size private data
@@ -583,8 +584,8 @@ static void *internal_ao2_alloc(size_t data_size, ao2_destructor_fn destructor_f
        }
 
        /* Initialize common ao2 values. */
-       obj->priv_data.ref_counter = 1;
        obj->priv_data.destructor_fn = destructor_fn;   /* can be NULL */
+       obj->priv_data.ref_counter = 1;
        obj->priv_data.options = options;
        obj->priv_data.magic = AO2_MAGIC;