Hello all,

Attached is a patch to optimize wlbc in current branch. Only one allocation of memroy, not two.

  Best regards,

                    FWX.

=== modified file 'src/common/wlsb.c'
--- src/common/wlsb.c   2012-05-23 19:54:18 +0000
+++ src/common/wlsb.c   2012-05-24 10:01:15 +0000
@@ -40,10 +40,10 @@
  */
 struct c_window
 {
+       uint16_t is_used;    /**< Whether the window entry is used or not */
        uint16_t sn;     /**< The Sequence Number (SN) associated with the entry
                              (used to acknowledge the entry) */
        uint32_t value;  /**< The value stored in the window entry */
-       bool is_used;    /**< Whether the window entry is used or not */
 };
 
 
@@ -52,9 +52,6 @@
  */
 struct c_wlsb
 {
-       /// @brief The window in which numerous previous values of the encoded 
value
-       ///        are stored to help recreate the value
-       struct c_window *window;
        /// The width of the window
        size_t window_width;
 
@@ -67,6 +64,10 @@
        size_t bits;
        /// Shift parameter (see 4.5.2 in the RFC 3095)
        rohc_lsb_shift_t p;
+
+       /// @brief The window in which numerous previous values of the encoded 
value
+       ///        are stored to help recreate the value
+       struct c_window window[1];
 };
 
 
@@ -110,25 +111,17 @@
        assert(bits > 0);
        assert(window_width > 0);
 
-       wlsb = malloc(sizeof(struct c_wlsb));
+       wlsb = malloc(sizeof(struct c_wlsb)+(sizeof(struct 
c_window)*(window_width-1)));
        if(wlsb == NULL)
        {
                rohc_debugf(0, "cannot allocate memory for the W-LSB object\n");
                goto error;
        }
-       bzero(wlsb, sizeof(struct c_wlsb));
 
        wlsb->oldest = 0;
        wlsb->next = 0;
        wlsb->window_width = window_width;
 
-       wlsb->window = (struct c_window *) calloc(window_width, sizeof(struct 
c_window));
-       if(wlsb->window == NULL)
-       {
-               rohc_debugf(0, "cannot allocate memory for the W-LSB window\n");
-               goto clean;
-       }
-
        wlsb->bits = bits;
        wlsb->p = p;
        for(entry = 0; entry < window_width; entry++)
@@ -138,8 +131,6 @@
 
        return wlsb;
 
-clean:
-       zfree(wlsb);
 error:
        return NULL;
 }
@@ -153,8 +144,6 @@
 void c_destroy_wlsb(struct c_wlsb *const wlsb)
 {
        assert(wlsb != NULL);
-       assert(wlsb->window != NULL);
-       free(wlsb->window);
        free(wlsb);
 }
 

_______________________________________________
Mailing list: https://launchpad.net/~rohc
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~rohc
More help   : https://help.launchpad.net/ListHelp

Reply via email to