本文整理汇总了C++中G_realloc函数的典型用法代码示例。如果您正苦于以下问题:C++ G_realloc函数的具体用法?C++ G_realloc怎么用?C++ G_realloc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了G_realloc函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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++;
}
示例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++;
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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 */
}
示例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;
}
示例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++;
}
}
示例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;
}
示例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++;
}
示例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;
}
示例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;
}
示例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++;
}
示例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;
}