Use variable-length arrays instead of alloca.

This commit is contained in:
Nicolas Tsiftes 2012-01-10 11:38:33 +01:00
parent c6abd58340
commit 343b2376c0
2 changed files with 9 additions and 15 deletions

View file

@ -32,8 +32,8 @@
* A binary search index for attributes that are constrained to be
* monotonically increasing, which is a rather common pattern for
* time series or keys. Since this index has no storage overhead,
* it does not wear out the flash memory nor does it occupy scarce
* scarce space. Furthermore, unlike B+-trees, it has a O(1) memory
* it does not wear out the flash memory nor does it occupy any
* space. Furthermore, unlike B+-trees, it has a O(1) memory
* footprint in relation to the number of data items.
* \author
* Nicolas Tsiftes <nvt@sics.se>
@ -85,14 +85,9 @@ index_api_t index_inline = {
static attribute_value_t *
get_value(tuple_id_t *index, relation_t *rel, attribute_t *attr)
{
unsigned char *row;
unsigned char row[rel->row_length];
static attribute_value_t value;
row = alloca(rel->row_length);
if(row == NULL) {
return NULL;
}
if(DB_ERROR(storage_get_row(rel, index, row))) {
return NULL;
}
@ -142,7 +137,8 @@ binary_search(index_iterator_t *index_iterator,
} else {
max = center - 1;
}
} while(min <= max && db_value_to_long(target_value) != db_value_to_long(cmp_value));
} while(min <= max &&
db_value_to_long(target_value) != db_value_to_long(cmp_value));
if(exact_match &&
db_value_to_long(target_value) != db_value_to_long(cmp_value)) {

View file

@ -475,19 +475,17 @@ relation_remove(char *name, int remove_tuples)
db_result_t
relation_insert(relation_t *rel, attribute_value_t *values)
{
size_t size;
attribute_t *attr;
storage_row_t record;
unsigned char record[rel->row_length];
unsigned char *ptr;
attribute_value_t *value;
db_result_t result;
value = values;
size = rel->row_length;
PRINTF("DB: Relation %s has a record size of %d bytes\n",
rel->name, (int)size);
ptr = record = alloca(size);
PRINTF("DB: Relation %s has a record size of %u bytes\n",
rel->name, (unsigned)rel->row_length);
ptr = record;
PRINTF("DB: Insert (");