root/opal/class/opal_value_array.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. opal_value_array_construct
  2. opal_value_array_destruct
  3. opal_value_array_set_size

   1 /*
   2  * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
   3  *                         University Research and Technology
   4  *                         Corporation.  All rights reserved.
   5  * Copyright (c) 2004-2005 The University of Tennessee and The University
   6  *                         of Tennessee Research Foundation.  All rights
   7  *                         reserved.
   8  * Copyright (c) 2004-2007 High Performance Computing Center Stuttgart,
   9  *                         University of Stuttgart.  All rights reserved.
  10  * Copyright (c) 2004-2005 The Regents of the University of California.
  11  *                         All rights reserved.
  12  * $COPYRIGHT$
  13  *
  14  * Additional copyrights may follow
  15  *
  16  * $HEADER$
  17  */
  18 
  19 #include "opal_config.h"
  20 
  21 #include "opal/class/opal_value_array.h"
  22 
  23 
  24 static void opal_value_array_construct(opal_value_array_t* array)
  25 {
  26     array->array_items = NULL;
  27     array->array_size = 0;
  28     array->array_item_sizeof = 0;
  29     array->array_alloc_size = 0;
  30 }
  31 
  32 static void opal_value_array_destruct(opal_value_array_t* array)
  33 {
  34     if (NULL != array->array_items)
  35         free(array->array_items);
  36 }
  37 
  38 OBJ_CLASS_INSTANCE(
  39     opal_value_array_t,
  40     opal_object_t,
  41     opal_value_array_construct,
  42     opal_value_array_destruct
  43 );
  44 
  45 
  46 int opal_value_array_set_size(opal_value_array_t* array, size_t size)
  47 {
  48 #if OPAL_ENABLE_DEBUG
  49     if(array->array_item_sizeof == 0) {
  50         opal_output(0, "opal_value_array_set_size: item size must be initialized");
  51         return OPAL_ERR_BAD_PARAM;
  52     }
  53 #endif
  54 
  55     if(size > array->array_alloc_size) {
  56         while(array->array_alloc_size < size)
  57             array->array_alloc_size <<= 1;
  58         array->array_items = (unsigned char *)realloc(array->array_items,
  59             array->array_alloc_size * array->array_item_sizeof);
  60         if (NULL == array->array_items)
  61             return OPAL_ERR_OUT_OF_RESOURCE;
  62     }
  63     array->array_size = size;
  64     return OPAL_SUCCESS;
  65 }
  66 

/* [<][>][^][v][top][bottom][index][help] */