Re: [PATCH] Avoid appending an empty slot to an user data array when user_data is NULL.

江頭幸路 <[email protected]>
Newsgroups gmane.comp.lib.cairo
Message-ID <CABXrqWuP6Z+mZ1s9gWu1cyvEM0J3Yu4HhvxOC_GoSyVhF9zu3g@mail.gmail.com>
This issue probably happens since the commit
http://cgit.freedesktop.org/cairo/commit/?id=9341c254a


test code:

#include <stdio.h>

#include <cairo.h>

#define LOG(...) fprintf(stderr, __VA_ARGS__)

int main(void) {
    cairo_surface_t *surface;
    cairo_t *cr;
    int i;

    surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 1, 1);
    cr = cairo_create(surface);

    for (i = 0; i < 500000; i++) {
        cairo_status_t ret = cairo_set_user_data(cr, (const void *)1, 0, 0);
        if (ret == CAIRO_STATUS_NO_MEMORY) {
            LOG("\ncairo_set_user_data() returned
CAIRO_STATUS_NO_MEMORY.\n");
            break;
        }
        if ((i+1) % 1000 == 0) {
            LOG("\r  iteration %d passed.", i+1);
        }
    }
    LOG("\n");

    cairo_destroy(cr);
    cairo_surface_destroy(surface);
    return 0;
}

Log shows iteration gets slow, meaning that cairo_set_user_data()
takes longer time than it does in the former iteration.
"top" command shows increase of memory consumption.


--
Koji Egashira


2015-04-17 20:59 GMT+09:00 江頭幸路 <[email protected]>:

> Otherwise, calling cairo_set_user_data(cr, key, 0, 0) many times
> causes a long user data array, almost all of whose slots are empty.
> It leads to unnecessarily much memory consumption and long execution time
> of
> cairo_set_user_data(cr, key, 0, 0) and cairo_get_user_data(cr, key) after
> it.
> ---
>  src/cairo-array.c |    3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/src/cairo-array.c b/src/cairo-array.c
> index 4f3c082..58c9a38 100644
> --- a/src/cairo-array.c
> +++ b/src/cairo-array.c
> @@ -485,6 +485,9 @@ _cairo_user_data_array_set_data
> (cairo_user_data_array_t     *array,
>      return CAIRO_STATUS_SUCCESS;
>      }
>
> +    if (user_data == NULL)
> +    return CAIRO_STATUS_SUCCESS;
> +
>      status = _cairo_array_append (array, &new_slot);
>      if (unlikely (status))
>      return status;
> --
> 1.7.9.5
>
>

-- 
.

-- 
cairo mailing list
[email protected]
http://lists.cairographics.org/mailman/listinfo/cairo
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.