这篇教程C++ util_calloc函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中util_calloc函数的典型用法代码示例。如果您正苦于以下问题:C++ util_calloc函数的具体用法?C++ util_calloc怎么用?C++ util_calloc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了util_calloc函数的29个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: ecl_grid_cache_allocecl_grid_cache_type * ecl_grid_cache_alloc( const ecl_grid_type * grid ) { ecl_grid_cache_type * grid_cache = util_malloc( sizeof * grid_cache ); grid_cache->grid = grid; grid_cache->volume = NULL; grid_cache->size = ecl_grid_get_active_size( grid ); grid_cache->xpos = util_calloc( grid_cache->size , sizeof * grid_cache->xpos ); grid_cache->ypos = util_calloc( grid_cache->size , sizeof * grid_cache->ypos ); grid_cache->zpos = util_calloc( grid_cache->size , sizeof * grid_cache->zpos ); grid_cache->global_index = util_calloc( grid_cache->size , sizeof * grid_cache->global_index ); { int active_index; /* Go trough all the active cells and extract the cell center position and store it in xpos/ypos/zpos. */ for (active_index = 0; active_index < grid_cache->size; active_index++) { int global_index = ecl_grid_get_global_index1A( grid , active_index ); grid_cache->global_index[ active_index ] = global_index; ecl_grid_get_xyz1( grid , global_index , &grid_cache->xpos[ active_index ] , &grid_cache->ypos[ active_index ] , &grid_cache->zpos[ active_index ]); } } return grid_cache;}
开发者ID:Ensembles,项目名称:ert,代码行数:29,
示例2: __conf_util_fscanf_alloc_token_buffer/* This function creates a string buffer from a file. Furthermore, if the strings in pad_keys are found in the buffer, they are padded with a space before and after. I.e., if the file contains key=value and "=" is in pad_keys, then the buffer will read key = value*/staticchar * __conf_util_fscanf_alloc_token_buffer( const char * file, const char * comment, int num_pad_keys, const char ** pad_keys){ char * buffer_wrk = basic_parser_fread_alloc_file_content( file , NULL /* quote_set */ , NULL /* delete_set */ , "--" /* Comment start*/ , "/n" /* Comment end */); char ** padded_keys = util_calloc(num_pad_keys , sizeof * padded_keys); for(int key_nr = 0; key_nr < num_pad_keys; key_nr++) { assert(pad_keys[key_nr] != NULL); int key_len = strlen(pad_keys[key_nr]); padded_keys[key_nr] = util_calloc((key_len + 3) , sizeof * padded_keys[key_nr]); padded_keys[key_nr][0] = ' '; for(int i=0; i<key_len; i++) { padded_keys[key_nr][1+i] = pad_keys[key_nr][i]; } padded_keys[key_nr][key_len + 1] = ' '; padded_keys[key_nr][key_len + 2] = '/0'; } char * buffer = util_string_replacen_alloc(buffer_wrk, num_pad_keys, pad_keys, (const char **) padded_keys); free(buffer_wrk); util_free_stringlist(padded_keys, num_pad_keys); return buffer;}
开发者ID:Ensembles,项目名称:ert,代码行数:42,
示例3: alloc_quoted_tokenstaticchar * alloc_quoted_token( const char * buffer, int length, bool strip_quote_marks){ char * token; if(!strip_quote_marks) { token = util_calloc( (length + 1) , sizeof * token ); memmove(token, &buffer[0], length * sizeof * token ); token[length] = '/0'; } else { token = util_calloc( (length - 1) , sizeof * token); memmove(token, &buffer[1], (length -1) * sizeof * token); token[length-2] = '/0'; /** Removed escape char before any escaped quotation starts. */ { char expr[3]; char subs[2]; expr[0] = PARSER_ESCAPE_CHAR; expr[1] = buffer[0]; expr[2] = '/0'; subs[0] = buffer[0]; subs[1] = '/0'; util_string_replace_inplace(&token, expr, subs); } } return token;}
开发者ID:akva2,项目名称:ResInsight,代码行数:34,
示例4: ecl_subsidence_survey_alloc_emptystatic ecl_subsidence_survey_type * ecl_subsidence_survey_alloc_empty(const ecl_subsidence_type * sub, const char * name) { ecl_subsidence_survey_type * survey = util_malloc( sizeof * survey ); UTIL_TYPE_ID_INIT( survey , ECL_SUBSIDENCE_SURVEY_ID ); survey->grid_cache = sub->grid_cache; survey->aquifer_cell = sub->aquifer_cell; survey->name = util_alloc_string_copy( name ); survey->porv = util_calloc( ecl_grid_cache_get_size( sub->grid_cache ) , sizeof * survey->porv ); survey->pressure = util_calloc( ecl_grid_cache_get_size( sub->grid_cache ) , sizeof * survey->pressure ); return survey;}
开发者ID:arielalmendral,项目名称:ert,代码行数:13,
示例5: plplot_plot_histvoid plplot_plot_hist( plot_driver_type * driver, const char * label , double_vector_type * x , line_attribute_type line_attr) { int size = double_vector_size( x ); plplot_setup_linestyle( line_attr ); { int bins = (int) sqrt( size ); double xmin = double_vector_get_min( x ); double xmax = double_vector_get_max( x ); { /* Could for some fuxxxing reason not get the plhist() function to work, and had to resort to the low level plbin function. */ double * limits = util_calloc(bins + 1 , sizeof * limits ); double * x_ = util_calloc(bins , sizeof * x_ ); double * y_ = util_calloc(bins , sizeof * y_ ); int i; double delta = (xmax - xmin) / bins; for (i= 0; i <= bins; i++) limits[i] = xmin + i*delta; for (i=0; i < bins; i++) { y_[i] = 0; x_[i] = 0.50 * (limits[i] + limits[i + 1]); } for (i=0; i < size; i++) { double value = double_vector_iget(x , i); int j; for (j = 1; j <= bins; j++) if (value < limits[j]) { y_[j-1]++; break; } } /* for (i = 0; i < bins; i++) printf("x[%d] = %g y[%d] = %g/n",i,x_[i],i,y_[i]); */ plbin(bins , x_ , y_ , PL_BIN_CENTRED + PL_BIN_NOEXPAND); free(x_); free(y_); free(limits); } //plhist(size , double_vector_get_ptr(d->x) , xmin , xmax , bins , 0 /* PL_HIST_DEFAULT */); }}
开发者ID:YingfangZhou,项目名称:ert,代码行数:50,
示例6: ecl_subsidence_survey_eval_geertsmastatic double ecl_subsidence_survey_eval_geertsma( const ecl_subsidence_survey_type * base_survey , const ecl_subsidence_survey_type * monitor_survey, ecl_region_type * region , double utm_x , double utm_y , double depth, double youngs_modulus, double poisson_ratio) { const ecl_grid_cache_type * grid_cache = base_survey->grid_cache; const double * cell_volume = ecl_grid_cache_get_volume( grid_cache ); const int size = ecl_grid_cache_get_size( grid_cache ); double scale_factor = 1e4 *(1 + poisson_ratio) * ( 1 - 2*poisson_ratio) / ( 4*M_PI*( 1 - poisson_ratio) * youngs_modulus ); double * weight = util_calloc( size , sizeof * weight ); double deltaz; for (int index = 0; index < size; index++) { if (monitor_survey) { weight[index] = - scale_factor * cell_volume[index] * (monitor_survey->pressure[index] - base_survey->pressure[index]); } else { weight[index] = - scale_factor * cell_volume[index] * (base_survey->pressure[index] ); } } deltaz = ecl_grav_common_eval_geertsma( grid_cache , region , base_survey->aquifer_cell , weight , utm_x , utm_y , depth , poisson_ratio); free( weight ); return deltaz;}
开发者ID:arielalmendral,项目名称:ert,代码行数:26,
示例7: ecl_subsidence_survey_evalstatic double ecl_subsidence_survey_eval( const ecl_subsidence_survey_type * base_survey , const ecl_subsidence_survey_type * monitor_survey, ecl_region_type * region , double utm_x , double utm_y , double depth, double compressibility, double poisson_ratio) { const ecl_grid_cache_type * grid_cache = base_survey->grid_cache; const int size = ecl_grid_cache_get_size( grid_cache ); double * weight = util_calloc( size , sizeof * weight ); double deltaz; int index; if (monitor_survey != NULL) { for (index = 0; index < size; index++) weight[index] = base_survey->porv[index] * (base_survey->pressure[index] - monitor_survey->pressure[index]); } else { for (index = 0; index < size; index++) weight[index] = base_survey->porv[index] * base_survey->pressure[index]; } deltaz = compressibility * 31.83099*(1-poisson_ratio) * ecl_grav_common_eval_biot_savart( grid_cache , region , base_survey->aquifer_cell , weight , utm_x , utm_y , depth ); free( weight ); return deltaz;}
开发者ID:arielalmendral,项目名称:ert,代码行数:26,
示例8: enkf_main_initialize_from_scratch_with_bool_vectorvoid enkf_main_initialize_from_scratch_with_bool_vector(enkf_main_type * enkf_main , const stringlist_type * param_list ,const bool_vector_type * iens_mask , init_mode_type init_mode) { int num_cpu = 4; int ens_size = enkf_main_get_ensemble_size( enkf_main ); thread_pool_type * tp = thread_pool_alloc( num_cpu , true ); arg_pack_type ** arg_list = util_calloc( ens_size , sizeof * arg_list ); int i; int iens; for (iens = 0; iens < ens_size; iens++) { arg_list[iens] = arg_pack_alloc(); if (bool_vector_safe_iget(iens_mask , iens)) { arg_pack_append_ptr( arg_list[iens] , enkf_main ); arg_pack_append_const_ptr( arg_list[iens] , param_list ); arg_pack_append_int( arg_list[iens] , iens ); arg_pack_append_int( arg_list[iens] , init_mode ); thread_pool_add_job( tp , enkf_main_initialize_from_scratch_mt , arg_list[iens]); } } thread_pool_join( tp ); for (i = 0; i < ens_size; i++) { arg_pack_free( arg_list[i] ); } free( arg_list ); thread_pool_free( tp );}
开发者ID:eoia,项目名称:ert,代码行数:27,
示例9: util_alloc_filenamechar * util_alloc_filename(const char * path , const char * basename , const char * extension) { char * file; int length = strlen(basename) + 1; if (path != NULL) length += strlen(path) + 1; if (extension != NULL) length += strlen(extension) + 1; file = util_calloc(length , sizeof * file ); if (path == NULL) { if (extension == NULL) memcpy(file , basename , strlen(basename) + 1); else sprintf(file , "%s.%s" , basename , extension); } else { if (extension == NULL) sprintf(file , "%s%c%s" , path , UTIL_PATH_SEP_CHAR , basename); else sprintf(file , "%s%c%s.%s" , path , UTIL_PATH_SEP_CHAR , basename , extension); } return file;}
开发者ID:PETECLAM,项目名称:ResInsight,代码行数:26,
示例10: util_alloc_tmp_filechar * util_alloc_tmp_file(const char * path, const char * prefix , bool include_pid ) { // Should be reimplemented to use mkstemp() const int pid_digits = 6; const int random_digits = 6; const int random_max = 1000000;#ifdef HAVE_PID_T const int pid_max = 1000000; pid_t pid = getpid() % pid_max;#else int pid = 0;#endif char * file = util_calloc(strlen(path) + 1 + strlen(prefix) + 1 + pid_digits + 1 + random_digits + 1 , sizeof * file ); char * tmp_prefix = util_alloc_string_copy( prefix ); if (!util_is_directory(path)) util_make_path(path); util_string_tr( tmp_prefix , UTIL_PATH_SEP_CHAR , '_'); /* removing path seps. */ do { long int rand_int = rand() % random_max; if (include_pid) sprintf(file , "%s%c%s-%d-%ld" , path , UTIL_PATH_SEP_CHAR , tmp_prefix , pid , rand_int); else sprintf(file , "%s%c%s-%ld" , path , UTIL_PATH_SEP_CHAR , tmp_prefix , rand_int); } while (util_file_exists(file)); free( tmp_prefix ); return file;}
开发者ID:PETECLAM,项目名称:ResInsight,代码行数:31,
示例11: _themeParseTextureEntrystatic int _themeParseTextureEntry(const char *json, jsmntok_t *tokens, const char *name, void *context) { flubGuiTheme_t *theme = (flubGuiTheme_t *)context; _jsonTextureEntry_t entry; flubGuiThemeTexture_t *texture; int red = 0; int green = 0; int blue = 0; memset(&entry, 0, sizeof(_jsonTextureEntry_t)); if(!jsonParseToStruct(json, tokens, _themeTextureParseMap, "Theme texture entry", &entry, _jsonTextureCleanup)) { return 0; } texture = util_calloc(sizeof(flubGuiThemeTexture_t), 0, NULL); texture->type = eFlubGuiThemeTexture; texture->id = entry.id; if(entry.colorkey != NULL) { parseColor(entry.colorkey, &red, &green, &blue, NULL); } if((texture->texture = texmgrLoad(entry.filename, NULL, entry.minfilter, entry.magfilter, ((entry.colorkey != NULL) ? 1 : 0), red, green, blue)) == NULL) { _jsonTextureCleanup(&entry); util_free(texture); return 0; } critbitInsert(&theme->textures, name, texture, NULL); _flubGuiThemeIndexAdd(theme, entry.id, texture); debugf(DBG_GUI, DBG_GUI_DTL_THEME, "Found texture /"%s/" as %d, file [%s], %s %s %s", name, entry.id, entry.filename, texmgrGLMinFilterStr(entry.minfilter), texmgrGLMagFilterStr(entry.magfilter), ((entry.colorkey == NULL) ? "No colorkey" : entry.colorkey)); _jsonTextureCleanup(&entry); return 1;}
开发者ID:Mojofreem,项目名称:flub,代码行数:34,
示例12: _themeParseFontEntrystatic int _themeParseFontEntry(const char *json, jsmntok_t *tokens, const char *name, void *context) { flubGuiTheme_t *theme = (flubGuiTheme_t *)context; _jsonFontEntry_t entry; flubGuiThemeFont_t *font; memset(&entry, 0, sizeof(_jsonFontEntry_t)); if(!jsonParseToStruct(json, tokens, _themeFontParseMap, "Theme font entry", &entry, _jsonFontCleanup)) { return 0; } font = util_calloc(sizeof(flubGuiThemeFont_t), 0, NULL); font->type = eFlubGuiThemeFont; font->id = entry.id; if(entry.filename != NULL) { if(!flubFontLoad(entry.filename)) { _jsonFontCleanup(&entry); util_free(font); return 0; } } if((font->font = fontGet(entry.font, entry.size, 0)) == NULL) { _jsonFontCleanup(&entry); util_free(font); return 0; } critbitInsert(&theme->fonts, name, font, NULL); _flubGuiThemeIndexAdd(theme, entry.id, font); debugf(DBG_GUI, DBG_GUI_DTL_THEME, "Found font /"%s/" as %d, file [%s], %s size %d", name, entry.id, entry.filename, entry.font, entry.size); _jsonFontCleanup(&entry); return 1;}
开发者ID:Mojofreem,项目名称:flub,代码行数:31,
示例13: _themeParseColorEntrystatic int _themeParseColorEntry(const char *json, jsmntok_t *tokens, const char *name, void *context) { flubGuiTheme_t *theme = (flubGuiTheme_t *)context; _jsonColorEntry_t entry; flubGuiThemeColor_t *color; int red; int green; int blue; memset(&entry, 0, sizeof(_jsonColorEntry_t)); if(!jsonParseToStruct(json, tokens,_themeColorParseMap, "Theme color entry", &entry, _jsonColorCleanup)) { return 0; } color = util_calloc(sizeof(flubGuiThemeColor_t), 0, NULL); color->type = eFlubGuiThemeColor; color->id = entry.id; parseColor(entry.color, &red, &green, &blue, NULL); color->red = COLOR_ITOF(red); color->green = COLOR_ITOF(green); color->blue = COLOR_ITOF(blue); critbitInsert(&theme->colors, name, color, NULL); _flubGuiThemeIndexAdd(theme, entry.id, color); _jsonColorCleanup(&entry); debugf(DBG_GUI, DBG_GUI_DTL_THEME, "Found color /"%s/" as %d, value #%02x%02x%02x", name, entry.id, red, green, blue); return 1;}
开发者ID:Mojofreem,项目名称:flub,代码行数:26,
示例14: ecl_util_get_num_parallel_cpu__static int ecl_util_get_num_parallel_cpu__(parser_type* parser, FILE* stream, const char * data_file) { int num_cpu = 1; char * buffer; long int start_pos = util_ftell( stream ); int buffer_size; /* Look for terminating '/' */ if (!parser_fseek_string( parser , stream , "/" , false , true)) util_abort("%s: sorry - could not find /"//" termination of PARALLEL keyword in data_file: /n",__func__ , data_file); buffer_size = (util_ftell(stream) - start_pos) ; buffer = util_calloc( buffer_size + 1 , sizeof * buffer ); util_fseek( stream , start_pos , SEEK_SET); util_fread( buffer , sizeof * buffer , buffer_size ,stream , __func__); buffer[buffer_size] = '/0'; { stringlist_type * tokens = parser_tokenize_buffer( parser , buffer , true ); if (stringlist_get_size( tokens ) > 0) { const char * num_cpu_string = stringlist_iget( tokens , 0 ); if (!util_sscanf_int( num_cpu_string , &num_cpu)) fprintf(stderr,"** Warning: failed to interpret:%s as integer - assuming one CPU/n",num_cpu_string); } else fprintf(stderr,"** Warning: failed to load data for PARALLEL keyword - assuming one CPU/n"); stringlist_free( tokens ); } free( buffer ); return num_cpu; }
开发者ID:danielfmva,项目名称:ert,代码行数:31,
示例15: create_submit_script_script_according_to_inputvoid create_submit_script_script_according_to_input() { char ** args = util_calloc(2, sizeof * args); args[0] = "/tmp/jaja/"; args[1] = "number2arg"; char * script_filename = util_alloc_filename("/tmp/", "qsub_script", "sh"); torque_job_create_submit_script(script_filename, "job_program.py", 2, (const char **) args); printf("Create submit script OK/n"); FILE* file_stream = util_fopen(script_filename, "r"); bool at_eof = false; char * line = util_fscanf_alloc_line(file_stream, &at_eof); test_assert_string_equal("#!/bin/sh", line); free(line); line = util_fscanf_alloc_line(file_stream, &at_eof); test_assert_string_equal("job_program.py /tmp/jaja/ number2arg", line); free(line); line = util_fscanf_alloc_line(file_stream, &at_eof); free(line); test_assert_true(at_eof); fclose(file_stream);}
开发者ID:joelmheim,项目名称:ResInsight,代码行数:25,
示例16: matrix_dgeqrfvoid matrix_dgeqrf(matrix_type * A , double * tau) { int lda = matrix_get_column_stride( A ); int m = matrix_get_rows( A ); int n = matrix_get_columns( A ); double * work = util_calloc(1 , sizeof * work ); int worksize; int info; /* Determine optimal worksize. */ worksize = -1; dgeqrf_(&m , &n , matrix_get_data( A ), &lda , tau , work , &worksize , &info); if (info != 0) util_abort("%s: dgerqf routine failed with info:%d /n",__func__ , info); worksize = ( int ) work[0]; { double * tmp = realloc(work , sizeof * work * worksize ); if (tmp == NULL) { /* OK - we could not get the optimal worksize, try again with the minimum. */ worksize = n; work = util_realloc(work , sizeof * work * worksize ); } else work = tmp; /* The request for optimal worksize succeeded */ } /* Second call - do the actual computation. */ dgeqrf_(&m , &n , matrix_get_data( A ), &lda , tau , work , &worksize , &info); if (info != 0) util_abort("%s: dgerqf routine failed with info:%d /n",__func__ , info); free( work );}
开发者ID:JacobStoren,项目名称:ert,代码行数:35,
示例17: create_submit_script_script_according_to_inputvoid create_submit_script_script_according_to_input() { test_work_area_type * work_area = test_work_area_alloc("job_torque_test" , true); const char * script_filename = "qsub_script.sh"; { char ** args = util_calloc(2, sizeof * args); args[0] = "/tmp/jaja/"; args[1] = "number2arg"; torque_job_create_submit_script(script_filename, "job_program.py", 2, (const char **) args); free( args ); } { FILE* file_stream = util_fopen(script_filename, "r"); bool at_eof = false; char * line = util_fscanf_alloc_line(file_stream, &at_eof); test_assert_string_equal("#!/bin/sh", line); free(line); line = util_fscanf_alloc_line(file_stream, &at_eof); test_assert_string_equal("job_program.py /tmp/jaja/ number2arg", line); free(line); line = util_fscanf_alloc_line(file_stream, &at_eof); free(line); test_assert_true(at_eof); fclose(file_stream); } test_work_area_free( work_area );}
开发者ID:JacobStoren,项目名称:ert,代码行数:32,
示例18: util_callocwidget_t *widgetCreate(int id, int type, int x, int y, int width, int height, unsigned int flags, flubGuiTheme_t *theme, widgetHandlers_t *handlers, layoutNode_t *layout, int dataSize) { widget_t *widget; widget = util_calloc(sizeof(widget_t) + dataSize, 0, NULL); widget->id = id; widget->type = type; widget->x = x; widget->y = y; widget->handlers = handlers; if((widget->handlers != NULL) && (widget->handlers->init != NULL)) { widget->handlers->init(widget); } widgetThemeApply(widget, theme); widgetAddToLayout(widget, layout); if((widget->handlers != NULL) && (widget->handlers->state != NULL)) { widget->handlers->state(widget, 1, flags); } widgetResize(widget, width, height); return widget;}
开发者ID:Mojofreem,项目名称:flub,代码行数:30,
示例19: validate_set_argc_minmaxstatic void validate_set_argc_minmax(validate_type * validate , int argc_min , int argc_max) { if (validate->argc_min != CONFIG_DEFAULT_ARG_MIN) util_abort("%s: sorry - current implementation does not allow repeated calls to: %s /n",__func__ , __func__); if (argc_min == CONFIG_DEFAULT_ARG_MIN) argc_min = 0; validate->argc_min = argc_min; validate->argc_max = argc_max; if ((argc_max != CONFIG_DEFAULT_ARG_MAX) && (argc_max < argc_min)) util_abort("%s invalid arg min/max values. argc_min:%d argc_max:%d /n",__func__ , argc_min , argc_max); { int internal_type_size = 0; /* Should end up in the range [argc_min,argc_max] */ if (argc_max > 0) internal_type_size = argc_max; else internal_type_size = argc_min; if (internal_type_size > 0) { validate->indexed_selection_set = util_calloc( internal_type_size , sizeof * validate->indexed_selection_set ); for (int iarg=0; iarg < internal_type_size; iarg++) validate->indexed_selection_set[iarg] = NULL; } }}
开发者ID:JacobStoren,项目名称:ert,代码行数:28,
|