Open MPI logo

Open MPI Development Mailing List Archives

  |   Home   |   Support   |   FAQ   |   all Development mailing list

From: George Bosilca (bosilca_at_[hidden])
Date: 2007-03-06 11:37:51


Bert,

Your previous patch saves some memory while the current one use some
more. I prefer to keep the array, as it's not only out of any
critical path but it's not performance related. An array can do the
job without any problems and use less memory than the linked list.

   Thanks,
     george.

On Mar 5, 2007, at 12:33 PM, Bert Wesarg wrote:

> This replaces the classes array (which holds all ctor/dtor arrays)
> with a
> linked list.
>
> This patch is compile tested only.
>
> Greetings
> Bert Wesarg
> Index: opal/class/opal_object.c
> ===================================================================
> --- opal/class/opal_object.c (revision 13923)
> +++ opal/class/opal_object.c (working copy)
> @@ -51,17 +51,12 @@
> * Local variables
> */
> static opal_atomic_lock_t class_lock = { { OPAL_ATOMIC_UNLOCKED } };
> -static void** classes = NULL;
> -static int num_classes = 0;
> -static int max_classes = 0;
> -static const int increment = 10;
> +static void *classes;
>
> -
> /*
> * Local functions
> */
> static void save_class(opal_class_t *cls);
> -static void expand_array(void);
>
>
> /*
> @@ -72,6 +67,7 @@
> opal_class_t *c;
> opal_construct_t* cls_construct_array;
> opal_destruct_t* cls_destruct_array;
> + void *base_pointer;
> int i;
>
> assert(cls);
> @@ -104,15 +100,18 @@
>
> /*
> * Allocate arrays for hierarchy of constructors and destructors
> + * Plus one void pointer for the classes list
> */
>
> - cls->cls_construct_array =
> - (void (**)(opal_object_t*))malloc((cls->cls_depth + 1)*
> - sizeof(opal_construct_t)
> * 2 );
> - if (NULL == cls->cls_construct_array) {
> + base_pointer = malloc((cls->cls_depth + 1) * sizeof
> (opal_construct_t) * 2 +
> + sizeof(void *));
> + if (NULL == base_pointer) {
> perror("Out of memory");
> exit(-1);
> }
> + /* The arrays begin behind the void pointer */
> + cls->cls_destruct_array =
> + (void (**)(opal_object_t*))((char *)base_pointer + sizeof
> (void *));
> cls->cls_destruct_array = cls->cls_construct_array + cls-
> >cls_depth + 1;
> cls_construct_array = cls->cls_construct_array;
> cls_destruct_array = cls->cls_destruct_array;
> @@ -154,18 +153,10 @@
> */
> int opal_class_finalize(void)
> {
> - int i;
> -
> - if (NULL != classes) {
> - for (i = 0; i < num_classes; ++i) {
> - if (NULL != classes[i]) {
> - free(classes[i]);
> - }
> - }
> + while (NULL != classes) {
> + void *next = *(void **)classes;
> free(classes);
> - classes = NULL;
> - num_classes = 0;
> - max_classes = 0;
> + classes = next;
> }
>
> return OPAL_SUCCESS;
> @@ -174,27 +165,7 @@
>
> static void save_class(opal_class_t *cls)
> {
> - if (num_classes >= max_classes) {
> - expand_array();
> - }
> -
> - classes[num_classes] = cls->cls_construct_array;
> - ++num_classes;
> + void *base_pointer = (char *)cls->cls_construct_array - sizeof
> (void *);
> + *(void **)base_pointer = classes;
> + classes = base_pointer;
> }
> -
> -
> -static void expand_array(void)
> -{
> - int i;
> -
> - max_classes += increment;
> - classes = (void**)realloc(classes, sizeof(void *) * max_classes);
> - if (NULL == classes) {
> - perror("class malloc failed");
> - exit(-1);
> - }
> - for (i = num_classes; i < max_classes; ++i) {
> - classes[i] = NULL;
> - }
> -}
> -
> _______________________________________________
> devel mailing list
> devel_at_[hidden]
> http://www.open-mpi.org/mailman/listinfo.cgi/devel

"Half of what I say is meaningless; but I say it so that the other
half may reach you"
                                   Kahlil Gibran