• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ G_realloc函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中G_realloc函数的典型用法代码示例。如果您正苦于以下问题:C++ G_realloc函数的具体用法?C++ G_realloc怎么用?C++ G_realloc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了G_realloc函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: offset

/*!
   \brief Add new line to updated

   \param Plus pointer to Plus_head structure
   \param line line id
   \param offset line offset (negative offset is ignored)
 */
void dig_line_add_updated(struct Plus_head *Plus, int line)
{
    int i;
    
    G_debug(3, "dig_line_add_updated(): line = %d", line);

    /* Check if already in list */
    for (i = 0; i < Plus->uplist.n_uplines; i++) {
	if (Plus->uplist.uplines[i] == line) {
            G_debug(3, "\tskipped");
	    return;
        }
    }
    
    /* Alloc space if needed */
    if (Plus->uplist.n_uplines == Plus->uplist.alloc_uplines) {
	Plus->uplist.alloc_uplines += 1000;
	Plus->uplist.uplines =
	    (int *)G_realloc(Plus->uplist.uplines,
			     Plus->uplist.alloc_uplines * sizeof(int));
	Plus->uplist.uplines_offset =
	    (off_t *)G_realloc(Plus->uplist.uplines_offset,
			     Plus->uplist.alloc_uplines * sizeof(off_t));
    }

    Plus->uplist.uplines[Plus->uplist.n_uplines] = line;
    Plus->uplist.n_uplines++;
}
开发者ID:caomw,项目名称:grass,代码行数:35,代码来源:update.c


示例2: offset

/*!
   \brief Add new line to updated

   \param Plus pointer to Plus_head structure
   \param line line id
   \param offset line offset (negative offset is ignored)
 */
void dig_line_add_updated(struct Plus_head *Plus, int line, off_t offset)
{
    int i;
    
    G_debug(3, "dig_line_add_updated(): line = %d", line);

    /* undo/redo in the digitizer needs all steps, 
     * disable check */
#if 0
    /* Check if already in list */
    for (i = 0; i < Plus->uplist.n_uplines; i++) {
	if (Plus->uplist.uplines[i] == line) {
            G_debug(3, "\tskipped");
	    return;
        }
    }
#endif
    
    /* Alloc space if needed */
    if (Plus->uplist.n_uplines == Plus->uplist.alloc_uplines) {
	Plus->uplist.alloc_uplines += 1000;
	Plus->uplist.uplines =
	    (int *)G_realloc(Plus->uplist.uplines,
			     Plus->uplist.alloc_uplines * sizeof(int));
	Plus->uplist.uplines_offset =
	    (off_t *)G_realloc(Plus->uplist.uplines_offset,
			     Plus->uplist.alloc_uplines * sizeof(off_t));
    }

    Plus->uplist.uplines[Plus->uplist.n_uplines] = line;
    Plus->uplist.uplines_offset[Plus->uplist.n_uplines] = offset;
    Plus->uplist.n_uplines++;
}
开发者ID:rashadkm,项目名称:grass_cmake,代码行数:40,代码来源:update.c


示例3: draw_cell

static int draw_cell(int A_row,
		     const void *array,
		     struct Colors *colors, RASTER_MAP_TYPE data_type)
{
    static unsigned char *red, *grn, *blu, *set;
    static int nalloc;

    int ncols = src[0][1] - src[0][0];
    int i;

    if (nalloc < ncols) {
	nalloc = ncols;
	red = G_realloc(red, nalloc);
	grn = G_realloc(grn, nalloc);
	blu = G_realloc(blu, nalloc);
	set = G_realloc(set, nalloc);
    }

    Rast_lookup_colors(array, red, grn, blu, set, ncols, colors,
			   data_type);

    if (D__overlay_mode)
	for (i = 0; i < ncols; i++) {
	    set[i] = Rast_is_null_value(array, data_type);
	    array = G_incr_void_ptr(array, Rast_cell_size(data_type));
	}

    A_row =
	COM_raster(ncols, A_row, red, grn, blu, D__overlay_mode ? set : NULL);

    return (A_row < src[1][1])
	? A_row : -1;
}
开发者ID:AsherBond,项目名称:MondocosmOS,代码行数:33,代码来源:raster.c


示例4: Vect_array_to_cat_list

/*!
   \brief Convert ordered array of integers to cat_list structure.

   \param vals array of integers
   \param nvals number of values
   \param[in,out] list pointer to cat_list structure

   \return number of ranges
 */
int Vect_array_to_cat_list(const int *vals, int nvals, struct cat_list *list)
{
    int i, range;

    G_debug(1, "Vect_array_to_cat_list()");
    range = -1;
    for (i = 0; i < nvals; i++) {
	if (i == 0 || (vals[i] - list->max[range]) > 1) {
	    range++;
	    if (range == list->alloc_ranges) {
		list->alloc_ranges += 1000;
		list->min = (int *)G_realloc((void *)list->min,
					     list->alloc_ranges *
					     sizeof(int));
		list->max =
		    (int *)G_realloc((void *)list->max,
				     list->alloc_ranges * sizeof(int));
	    }
	    list->min[range] = vals[i];
	    list->max[range] = vals[i];
	}
	else {
	    list->max[range] = vals[i];
	}
    }

    list->n_ranges = range + 1;

    return (list->n_ranges);
}
开发者ID:rashadkm,项目名称:grass_cmake,代码行数:39,代码来源:cats.c


示例5: I_new_control_point

int I_new_control_point(struct Control_Points *cp,
			double e1, double n1, double e2, double n2,
			int status)
{
    int i;
    unsigned int size;

    if (status < 0)
	return 1;
    i = (cp->count)++;
    size = cp->count * sizeof(double);
    cp->e1 = (double *)G_realloc(cp->e1, size);
    cp->e2 = (double *)G_realloc(cp->e2, size);
    cp->n1 = (double *)G_realloc(cp->n1, size);
    cp->n2 = (double *)G_realloc(cp->n2, size);
    size = cp->count * sizeof(int);
    cp->status = (int *)G_realloc(cp->status, size);

    cp->e1[i] = e1;
    cp->e2[i] = e2;
    cp->n1[i] = n1;
    cp->n2[i] = n2;
    cp->status[i] = status;

    return 0;
}
开发者ID:AsherBond,项目名称:MondocosmOS,代码行数:26,代码来源:points.c


示例6: G_rasprintf

int G_rasprintf(char **out, size_t *size, const char *fmt, ...)
{
    va_list ap;
    int count;
    char *buf = *out;
    size_t osize = *size;

    if (osize < strlen(fmt) + 50) {
	osize = strlen(fmt) + 50;
	buf = G_realloc(buf, osize);
    }

    for (;;) {
	va_start(ap, fmt);
	count = vsnprintf(buf, osize, fmt, ap);
	va_end(ap);
	if (count >= 0 && count < osize)
	    break;
	if (count > -1)
	    osize = count + 1;
	else
	    osize *= 2;
	
	buf = G_realloc(buf, osize);
    }

    *out = buf;
    *size = osize;

    return count;
}
开发者ID:rashadkm,项目名称:grass_cmake,代码行数:31,代码来源:asprintf.c


示例7: G_vasprintf

int G_vasprintf(char **out, const char *fmt, va_list ap)
{
#ifdef HAVE_ASPRINTF
    return vasprintf(out, fmt, ap);
#else
    size_t size = strlen(fmt) + 50;
    char *buf = G_malloc(size);
    int count;

    for (;;) {
	/* BUG: according to man vsnprintf,
	 * va_start() should be called immediately before vsnprintf(),
	 * and va_end() immediately after vsnprintf()
	 * otherwise there will be memory corruption */
	count = vsnprintf(buf, size, fmt, ap);
	if (count >= 0 && count < size)
	    break;
	size *= 2;
	buf = G_realloc(buf, size);
    }

    buf = G_realloc(buf, count + 1);
    *out = buf;

    return count;
#endif /* HAVE_ASPRINTF */
}
开发者ID:rashadkm,项目名称:grass_cmake,代码行数:27,代码来源:asprintf.c


示例8: I_new_ref_point

int
I_new_ref_point(struct Ortho_Photo_Points *cp, double e1, double n1,
		double e2, double n2, int status)
{
    int i;
    size_t size;

    /*fprintf (stderr, "Try to new_ref_point \n"); */
    if (status < 0)
	return 0;
    i = (cp->count)++;
    size = cp->count * sizeof(double);
    cp->e1 = (double *)G_realloc(cp->e1, size);
    cp->e2 = (double *)G_realloc(cp->e2, size);
    cp->n1 = (double *)G_realloc(cp->n1, size);
    cp->n2 = (double *)G_realloc(cp->n2, size);
    size = cp->count * sizeof(int);
    cp->status = (int *)G_realloc(cp->status, size);

    cp->e1[i] = e1;
    cp->e2[i] = e2;
    cp->n1[i] = n1;
    cp->n2[i] = n2;
    cp->status[i] = status;

    return 0;
}
开发者ID:AsherBond,项目名称:MondocosmOS,代码行数:27,代码来源:ref_points.c


示例9: newpoint

void newpoint(double z, double east, double north, int noindex)
{
    int row, column;

    row = (int)((window.north - north) / window.ns_res);
    column = (int)((east - window.west) / window.ew_res);

    if (!noindex) {
        if (row < 0 || row >= window.rows || column < 0 ||
                column >= window.cols) ;
        else {			/* Ignore sites outside current region as can't be indexed */

            points[row][column] =
                (struct Point *)G_realloc(points[row][column],
                                          (1 +
                                           npoints_currcell[row][column]) *
                                          sizeof(struct Point));
            points[row][column][npoints_currcell[row][column]].north = north;
            points[row][column][npoints_currcell[row][column]].east = east;
            points[row][column][npoints_currcell[row][column]].z = z;
            npoints_currcell[row][column]++;
            npoints++;
        }
    }
    else {
        noidxpoints = (struct Point *)G_realloc(noidxpoints,
                                                (1 +
                                                        npoints) *
                                                sizeof(struct Point));
        noidxpoints[npoints].north = north;
        noidxpoints[npoints].east = east;
        noidxpoints[npoints].z = z;
        npoints++;
    }
}
开发者ID:rkrug,项目名称:grass-ci,代码行数:35,代码来源:main.c


示例10: dig_boxlist_add

/* Add item to box list, does not check for duplicates */
int dig_boxlist_add(struct boxlist *list, int id, struct bound_box box)
{
    if (list->n_values == list->alloc_values) {
	size_t size = (list->n_values + 1000) * sizeof(int);
	void *p = G_realloc((void *)list->id, size);

	if (p == NULL)
	    return 0;
	list->id = (int *)p;

	if (list->have_boxes) {
	    size = (list->n_values + 1000) * sizeof(struct bound_box);
	    p = G_realloc((void *)list->box, size);

	    if (p == NULL)
		return 0;
	    list->box = (struct bound_box *)p;
	}

	list->alloc_values = list->n_values + 1000;
    }

    list->id[list->n_values] = id;
    if (list->have_boxes)
	list->box[list->n_values] = box;
    list->n_values++;

    return 1;
}
开发者ID:AsherBond,项目名称:MondocosmOS,代码行数:30,代码来源:list.c


示例11: add_coor

void add_coor(SYMBCHAIN *chain, double x, double y)
{
    G_debug(5, "    add_coor %f, %f", x, y);
    if (chain->scount == chain->salloc) {
	chain->salloc += 10;
	chain->sx = (double *)G_realloc(chain->sx, chain->salloc * sizeof(double));
	chain->sy = (double *)G_realloc(chain->sy, chain->salloc * sizeof(double));
    }
    chain->sx[chain->scount] = x;
    chain->sy[chain->scount] = y;
    chain->scount++;
}
开发者ID:rashadkm,项目名称:grass_cmake,代码行数:12,代码来源:stroke.c


示例12: loadSiteCoordinates

int loadSiteCoordinates(struct Map_info *Map, struct Point **points, int region,
			struct Cell_head *window, int field, struct cat_list *cat_list)
{
    int i, pointIdx;
    struct line_pnts *sites;
    struct line_cats *cats;
    struct bound_box box;
    int type;

    sites = Vect_new_line_struct();
    cats = Vect_new_cats_struct();

    *points = NULL;
    pointIdx = 0;
    
    /* copy window to box */
    Vect_region_box(window, &box);

    while ((type = Vect_read_next_line(Map, sites, cats)) > -1) {

	if (type != GV_POINT && !(type & GV_LINES))
	    continue;

	if (field > 0 && !Vect_cats_in_constraint(cats, field, cat_list))
	    continue;
	
	for (i = 0; i < sites->n_points; i++) {
	    G_debug(4, "Point: %f|%f|%f", sites->x[i], sites->y[i],
		    sites->z[i]);
	    
	    if (region && !Vect_point_in_box(sites->x[i], sites->y[i], sites->z[i], &box))
		continue;
	    
	    G_debug(4, "Point in the box");

	    if ((pointIdx % ALLOC_CHUNK) == 0)
		*points = (struct Point *) G_realloc(*points,
						     (pointIdx + ALLOC_CHUNK) * sizeof(struct Point));
	    
	    (*points)[pointIdx].x = sites->x[i];
	    (*points)[pointIdx].y = sites->y[i];
	    (*points)[pointIdx].z = sites->z[i];
	    pointIdx++;
	}
    }

    if (pointIdx > 0)
	*points = (struct Point *)G_realloc(*points,
					    (pointIdx + 1) * sizeof(struct Point));
    
    return pointIdx;
}
开发者ID:rashadkm,项目名称:grass_cmake,代码行数:52,代码来源:read.c


示例13: D_draw_raster_RGB

/*!
  \brief Draw raster row in RGB mode

  \param A_row row number
  \param r_raster red data buffer
  \param g_raster green data buffer
  \param b_raster blue data buffer
  \param r_colors colors used for red channel
  \param g_colors colors used for green channel
  \param b_colors colors used for blue channel
  \param r_type raster type used for red channel
  \param g_type raster type used for red channel
  \param b_type raster type used for red channel

  \return
*/
int D_draw_raster_RGB(int A_row,
		      const void *r_raster, const void *g_raster,
		      const void *b_raster, struct Colors *r_colors,
		      struct Colors *g_colors, struct Colors *b_colors,
		      RASTER_MAP_TYPE r_type, RASTER_MAP_TYPE g_type,
		      RASTER_MAP_TYPE b_type)
{
    static unsigned char *r_buf, *g_buf, *b_buf, *n_buf;
    static int nalloc;

    int r_size = Rast_cell_size(r_type);
    int g_size = Rast_cell_size(g_type);
    int b_size = Rast_cell_size(b_type);
    int ncols = src[0][1] - src[0][0];
    int i;

    /* reallocate color_buf if necessary */
    if (nalloc < ncols) {
	nalloc = ncols;
	r_buf = G_realloc(r_buf, nalloc);
	g_buf = G_realloc(g_buf, nalloc);
	b_buf = G_realloc(b_buf, nalloc);
	n_buf = G_realloc(n_buf, nalloc);
    }

    /* convert cell values to bytes */
    Rast_lookup_colors(r_raster, r_buf, n_buf, n_buf, n_buf, ncols,
			   r_colors, r_type);
    Rast_lookup_colors(g_raster, n_buf, g_buf, n_buf, n_buf, ncols,
			   g_colors, g_type);
    Rast_lookup_colors(b_raster, n_buf, n_buf, b_buf, n_buf, ncols,
			   b_colors, b_type);

    if (D__overlay_mode)
	for (i = 0; i < ncols; i++) {
	    n_buf[i] = (Rast_is_null_value(r_raster, r_type) ||
			Rast_is_null_value(g_raster, g_type) ||
			Rast_is_null_value(b_raster, b_type));

	    r_raster = G_incr_void_ptr(r_raster, r_size);
	    g_raster = G_incr_void_ptr(g_raster, g_size);
	    b_raster = G_incr_void_ptr(b_raster, b_size);
	}

    A_row = COM_raster(ncols, A_row, r_buf, g_buf, b_buf,
		       D__overlay_mode ? n_buf : NULL);

    return (A_row < src[1][1])
	? A_row : -1;
}
开发者ID:AsherBond,项目名称:MondocosmOS,代码行数:66,代码来源:raster.c


示例14: add_point

/* add point to line */
void add_point(SYMBEL * el, double x, double y)
{
    if (el->coor.line.count == el->coor.line.alloc) {
	el->coor.line.alloc += 10;
	el->coor.line.x =
	    (double *)G_realloc(el->coor.line.x,
				el->coor.line.alloc * sizeof(double));
	el->coor.line.y =
	    (double *)G_realloc(el->coor.line.y,
				el->coor.line.alloc * sizeof(double));
    }
    el->coor.line.x[el->coor.line.count] = x;
    el->coor.line.y[el->coor.line.count] = y;
    el->coor.line.count++;
}
开发者ID:GRASS-GIS,项目名称:grass-ci,代码行数:16,代码来源:read.c


示例15: scan_rules

/*!
  \brief Get list of color rules for Option->options
  
  \return allocated string buffer with options
*/
char *G_color_rules_options(void)
{
    char *list, **rules;
    const char *name;
    int size, len, nrules;
    int i, n;

    list = NULL;
    size = len = 0;

    rules = scan_rules(&nrules);
    
    for (i = 0; i < nrules; i++) {
        name = rules[i];
        n = strlen(name);

        if (size < len + n + 2) {
            size = len + n + 200;
            list = G_realloc(list, size);
        }

        if (len > 0)
            list[len++] = ',';

        memcpy(&list[len], name, n + 1);
        len += n;
    }

    G_free(rules);
    
    return list;
}
开发者ID:rashadkm,项目名称:grass_cmake,代码行数:37,代码来源:color_rules.c


示例16: list_mon

/* get list of running monitors */
void list_mon(char ***list, int *n)
{
    int i;
    const char *name;
    const char *env_prefix = "MONITOR_";
    int env_prefix_len;
    char **tokens;
    
    env_prefix_len = strlen(env_prefix);
    
    *list = NULL;
    *n    = 0;
    tokens = NULL;
    for (i = 0; (name = G_get_env_name(i)); i++) {
	if (strncmp(env_prefix, name, env_prefix_len) == 0) {
	    tokens = G_tokenize(name, "_");
	    if (G_number_of_tokens(tokens) != 3 ||
		strcmp(tokens[2], "ENVFILE") != 0)
		continue;
	    *list = G_realloc(*list, (*n + 1) * sizeof(char *));
	    /* GRASS variable names are upper case, but monitor names are lower
	     * case. */
	    (*list)[*n] = G_store_lower(tokens[1]);
	    (*n)++;
	    G_free_tokens(tokens);
	    tokens = NULL;
	}
    }
    
}
开发者ID:caomw,项目名称:grass,代码行数:31,代码来源:list.c


示例17: assert

char *G_rc_path(const char *element, const char *item)
{
    size_t len;
    char *path, *ptr;

    assert(!(element == NULL && item == NULL));

    /* Simple item in top-level */
    if (element == NULL) {
	path = _make_toplevel();
    }
    else if (item == NULL) {
	return _make_sublevels(element);
    }
    else {
	path = _make_sublevels(element);
    }


    assert(*item != '.');
    assert(path != NULL);
    ptr = strchr(item, '/');	/* should not have slashes */
    assert(ptr == NULL);
    len = strlen(path) + strlen(item) + 2;
    if ((ptr = G_realloc(path, len)) == NULL) {
	G_free(path);
	return NULL;
    }
    path = ptr;
    ptr = strchr(path, '\0');
    sprintf(ptr, "/%s", item);

    return path;
}				/* G_rc_path */
开发者ID:rashadkm,项目名称:grass_cmake,代码行数:34,代码来源:user_config.c


示例18: _get_list

static void _get_list(char ***list, int *count)
{
    char **a;
    int n;
    char *buf;

    *list = NULL;
    *count = 0;

    buf = _get_text_2();

    for (n = 0; *buf; n++) {
	if (n == 0)
	    a = G_malloc(sizeof(char *));
	else
	    a = G_realloc(a, (n + 1) * sizeof(char *));

	a[n] = G_strdup(buf);

	buf = _get_text_2();
    }

    *list = a;
    *count = n;
}
开发者ID:imincik,项目名称:pkg-grass,代码行数:25,代码来源:rem_pad.c


示例19: set_cat

int set_cat(CELL result, CELL * cat, struct Categories *pcats)
{
    int i, n;
    static char *buf = NULL;
    static int len = 0;
    char *lbl;


    if (result == 0)
	return 1;

    n = 0;
    for (i = 0; i < nfiles; i++) {
	lbl = get_label(cat[i], &labels[i]);
	n += strlen(lbl) + 2;
    }
    if (len < n)
	buf = G_realloc(buf, len = n);

    *buf = 0;
    for (i = 0; i < nfiles; i++) {
	if (i)
	    strcat(buf, "; ");
	lbl = get_label(cat[i], &labels[i]);
	strcat(buf, lbl);
    }
    G_set_cat(result, buf, pcats);
    return 0;
}
开发者ID:imincik,项目名称:pkg-grass,代码行数:29,代码来源:cats.c


示例20: add_to_list

static int add_to_list(int x, int y)
{
    int n, i;
    struct equiv_table *e_list_y;

    e_list_y = e_list + y;
    n = e_list_y->count;
    if (n == 0) {		/* first time through--start list */
	e_list_y->length = 20;	/* initial guess at storage needed */
	e_list_y->ptr = (int *)G_malloc(e_list_y->length * sizeof(int));
	*(e_list_y->ptr) = x;
	(e_list_y->count)++;
    }
    else {			/* list already started */

	for (i = 0; i < n; i++) {	/* check whether x is already *//*   in list */
	    if (*(e_list_y->ptr + i) == x)
		return (0);	/* if so, we don't need to add it */
	}

	if (n + 1 >= e_list_y->length) {	/* add more space for storage *//*   if necessary */
	    e_list_y->length += 10;
	    e_list_y->ptr =
		(int *)G_realloc(e_list_y->ptr,
				 e_list_y->length * sizeof(int));
	}

	*(e_list_y->ptr + n) = x;	/* add x to list */
	(e_list_y->count)++;
    }

    return (1);			/* indicate addition made */
}
开发者ID:imincik,项目名称:pkg-grass,代码行数:33,代码来源:areas.c



注:本文中的G_realloc函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ G_refPrintf函数代码示例发布时间:2022-05-30
下一篇:
C++ G_percent函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap