Example #1
0
/* allocate room for  'num'   X and Y  arrays in struct line_pnts 
 **   returns -1 on out of memory 
 */
int dig_alloc_points(struct line_pnts *points, int num)
{
    int alloced;
    char *p;

    alloced = points->alloc_points;
    /* alloc_space will just return if no space is needed */
    if (!(p =
	  dig__alloc_space(num, &alloced, 50, (char *)points->x,
			   sizeof(double)))) {
	return (dig_out_of_memory());
    }
    points->x = (double *)p;

    alloced = points->alloc_points;
    /* alloc_space will just return if no space is needed */
    if (!(p =
	  dig__alloc_space(num, &alloced, 50, (char *)points->y,
			   sizeof(double)))) {
	return (dig_out_of_memory());
    }
    points->y = (double *)p;

    alloced = points->alloc_points;
    /* alloc_space will just return if no space is needed */
    if (!(p =
	  dig__alloc_space(num, &alloced, 50, (char *)points->z,
			   sizeof(double)))) {
	return (dig_out_of_memory());
    }
    points->z = (double *)p;

    points->alloc_points = alloced;
    return (0);
}
Example #2
0
/* allocate room for  'num'  fields and category arrays 
 ** in struct line_cats 
 **   returns -1 on out of memory 
 */
int dig_alloc_cats(struct line_cats *cats, int num)
{
    int alloced;
    char *p;

    /* alloc_space will just return if no space is needed */
    alloced = cats->alloc_cats;
    if (!(p =
	  dig__alloc_space(num, &alloced, 1, (int *)cats->field,
			   sizeof(int)))) {
	return (dig_out_of_memory());
    }
    cats->field = (int *)p;

    alloced = cats->alloc_cats;
    if (!(p =
	  dig__alloc_space(num, &alloced, 1, (int *)cats->cat,
			   sizeof(int)))) {
	return (dig_out_of_memory());
    }
    cats->cat = (int *)p;

    cats->alloc_cats = alloced;
    return (0);
}
Example #3
0
static int buf_alloc(int needed)
{
    char *p;
    int cnt;

    if (needed <= buf_alloced)
	return (0);
    cnt = buf_alloced;
    p = dig__alloc_space(needed, &cnt, 100, buffer, 1);
    if (p == NULL)
	return (dig_out_of_memory());
    buffer = p;
    buf_alloced = cnt;
    return (0);
}
Example #4
0
void *dig_alloc_space(int n_wanted,
		      int *n_elements,
		      int chunk_size, void *ptr, int element_size)
{
    char *p;

    p = dig__alloc_space(n_wanted, n_elements, chunk_size, ptr, element_size);

    if (p == NULL) {
	fprintf(stderr, "\nERROR: out of memory.  memory asked for: %d\n",
		n_wanted);
	exit(EXIT_FAILURE);
    }

    return (p);
}