The data size in bytes is now stored in the header of a column.
This commit is contained in:
@ -547,11 +547,11 @@ size_t obi_get_platform_header_size()
|
||||
}
|
||||
|
||||
|
||||
OBIDMS_column_p obi_create_column(OBIDMS_p dms,
|
||||
OBIDMS_column_p obi_create_column(OBIDMS_p dms,
|
||||
const char* column_name,
|
||||
OBIType_t data_type,
|
||||
index_t nb_lines,
|
||||
index_t nb_elements_per_line,
|
||||
OBIType_t data_type,
|
||||
index_t nb_lines,
|
||||
index_t nb_elements_per_line,
|
||||
const char* elements_names,
|
||||
const char* array_name)
|
||||
{
|
||||
@ -733,6 +733,7 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
|
||||
header = new_column->header;
|
||||
header->little_endian = obi_is_little_endian();
|
||||
header->header_size = header_size;
|
||||
header->data_size = data_size;
|
||||
header->line_count = nb_lines;
|
||||
header->lines_used = 0;
|
||||
header->nb_elements_per_line = nb_elements_per_line;
|
||||
@ -781,7 +782,6 @@ OBIDMS_column_p obi_open_column(OBIDMS_p dms,
|
||||
char* column_file_name;
|
||||
int column_file_descriptor;
|
||||
size_t header_size;
|
||||
size_t data_size;
|
||||
|
||||
column = NULL;
|
||||
|
||||
@ -856,12 +856,9 @@ OBIDMS_column_p obi_open_column(OBIDMS_p dms,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Compute data size from the informations in the header
|
||||
data_size = obi_array_sizeof((column->header)->data_type, (column->header)->line_count, (column->header)->nb_elements_per_line);
|
||||
|
||||
// Map the data
|
||||
column->data = mmap(NULL,
|
||||
data_size,
|
||||
(column->header)->data_size,
|
||||
PROT_READ,
|
||||
MAP_PRIVATE,
|
||||
column_file_descriptor,
|
||||
@ -901,16 +898,15 @@ OBIDMS_column_p obi_open_column(OBIDMS_p dms,
|
||||
}
|
||||
|
||||
|
||||
OBIDMS_column_p obi_clone_column(OBIDMS_p dms,
|
||||
const char* column_name,
|
||||
OBIDMS_column_p obi_clone_column(OBIDMS_p dms,
|
||||
const char* column_name,
|
||||
obiversion_t version_number,
|
||||
bool clone_data)
|
||||
bool clone_data)
|
||||
{
|
||||
OBIDMS_column_p column_to_clone;
|
||||
OBIDMS_column_p new_column;
|
||||
index_t nb_lines;
|
||||
index_t nb_elements_per_line;
|
||||
size_t data_size;
|
||||
OBIType_t data_type;
|
||||
|
||||
column_to_clone = obi_open_column(dms, column_name, version_number);
|
||||
@ -953,8 +949,7 @@ OBIDMS_column_p obi_clone_column(OBIDMS_p dms,
|
||||
|
||||
if (clone_data)
|
||||
{
|
||||
data_size = obi_array_sizeof(data_type, nb_lines, nb_elements_per_line);
|
||||
memcpy(new_column->data, column_to_clone->data, data_size);
|
||||
memcpy(new_column->data, column_to_clone->data, (column_to_clone->header)->data_size);
|
||||
(new_column->header)->lines_used = (column_to_clone->header)->lines_used;
|
||||
}
|
||||
|
||||
@ -971,11 +966,8 @@ OBIDMS_column_p obi_clone_column(OBIDMS_p dms,
|
||||
|
||||
int obi_close_column(OBIDMS_column_p column)
|
||||
{
|
||||
size_t data_size;
|
||||
|
||||
// Munmap data
|
||||
data_size = obi_array_sizeof((column->header)->data_type, (column->header)->line_count, (column->header)->nb_elements_per_line);
|
||||
if (munmap(column->data, data_size) < 0)
|
||||
if (munmap(column->data, (column->header)->data_size) < 0)
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError munmapping column data");
|
||||
@ -1035,8 +1027,7 @@ int obi_truncate_column_to_lines_used(OBIDMS_column_p column) // TODO is it nece
|
||||
free(column_file_name);
|
||||
|
||||
// Unmap the data before truncating the file
|
||||
data_size = obi_array_sizeof((column->header)->data_type, (column->header)->line_count, (column->header)->nb_elements_per_line);
|
||||
if (munmap(column->data, data_size) < 0)
|
||||
if (munmap(column->data, (column->header)->data_size) < 0)
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError munmapping the data of a column before truncating");
|
||||
@ -1072,8 +1063,9 @@ int obi_truncate_column_to_lines_used(OBIDMS_column_p column) // TODO is it nece
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Set line_count to the new line count
|
||||
// Set new line_count and new data size
|
||||
(column->header)->line_count = new_line_count;
|
||||
(column->header)->data_size = data_size;
|
||||
|
||||
close(column_file_descriptor);
|
||||
|
||||
@ -1123,7 +1115,7 @@ int obi_enlarge_column(OBIDMS_column_p column)
|
||||
close(column_file_descriptor);
|
||||
return -1;
|
||||
}
|
||||
old_data_size = obi_array_sizeof((column->header)->data_type, old_line_count, (column->header)->nb_elements_per_line);
|
||||
old_data_size = (column->header)->data_size;
|
||||
new_data_size = old_data_size * COLUMN_GROWTH_FACTOR;
|
||||
header_size = (column->header)->header_size;
|
||||
file_size = header_size + new_data_size;
|
||||
@ -1185,8 +1177,9 @@ int obi_enlarge_column(OBIDMS_column_p column)
|
||||
}
|
||||
}
|
||||
|
||||
// Set new line count
|
||||
// Set new line count and new data size
|
||||
(column->header)->line_count = new_line_count;
|
||||
(column->header)->data_size = new_data_size;
|
||||
|
||||
// Initialize new data lines to NA
|
||||
obi_ini_to_NA_values(column, old_line_count, new_line_count - old_line_count);
|
||||
|
@ -55,6 +55,8 @@ typedef struct OBIDMS_column_header {
|
||||
*/
|
||||
size_t header_size; /**< Size of the header in bytes.
|
||||
*/
|
||||
size_t data_size; /**< Size of the data in bytes.
|
||||
*/
|
||||
index_t line_count; /**< Number of lines of data allocated.
|
||||
*/
|
||||
index_t lines_used; /**< Number of lines of data used.
|
||||
|
Reference in New Issue
Block a user