~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/dynamic_array.cc

  • Committer: Mark Atwood
  • Date: 2011-06-16 06:04:05 UTC
  • mfrom: (2318.4.8 refactor7)
  • Revision ID: me@mark.atwood.name-20110616060405-jqxvti75k6bpq741
mergeĀ lp:~olafvdspek/drizzle/refactor9

Show diffs side-by-side

added added

removed removed

Lines of Context:
46
46
    false       Ok
47
47
*/
48
48
 
49
 
bool init_dynamic_array2(DYNAMIC_ARRAY *array, uint32_t element_size,
 
49
void init_dynamic_array2(DYNAMIC_ARRAY *array, uint32_t element_size,
50
50
                            void *init_buffer, uint32_t init_alloc,
51
51
                            uint32_t alloc_increment)
52
52
{
67
67
  array->alloc_increment=alloc_increment;
68
68
  array->size_of_element=element_size;
69
69
  if ((array->buffer= (unsigned char*) init_buffer))
70
 
    return(false);
71
 
  if (!(array->buffer=(unsigned char*) malloc(element_size*init_alloc)))
72
 
  {
73
 
    array->max_element=0;
74
 
    return(true);
75
 
  }
76
 
  return(false);
 
70
    return;
 
71
  array->buffer= (unsigned char*) malloc(element_size*init_alloc);
77
72
}
78
73
 
79
74
/*
136
131
        In this senerio, the buffer is statically preallocated,
137
132
        so we have to create an all-new malloc since we overflowed
138
133
      */
139
 
      if (!(new_ptr= (char *) malloc((array->max_element+
140
 
                                     array->alloc_increment) *
141
 
                                     array->size_of_element)))
142
 
        return 0;
143
 
      memcpy(new_ptr, array->buffer,
144
 
             array->size() * array->size_of_element);
 
134
      new_ptr= (char*) malloc((array->max_element + array->alloc_increment) * array->size_of_element);
 
135
      memcpy(new_ptr, array->buffer, array->size() * array->size_of_element);
145
136
    }
146
 
    else if (!(new_ptr= (char*) realloc(array->buffer,
147
 
                                        (array->max_element+
148
 
                                         array->alloc_increment)*
149
 
                                        array->size_of_element)))
150
 
      return 0;
 
137
    else 
 
138
      new_ptr= (char*) realloc(array->buffer, (array->max_element + array->alloc_increment) * array->size_of_element);
151
139
    array->buffer= (unsigned char*) new_ptr;
152
140
    array->max_element+=array->alloc_increment;
153
141
  }