NAME

Rmalloc - allocate dynamic memory large enough to hold in-file and app cells

SYNOPSIS

#include "csf.h"

void *Rmalloc
(
	const MAP *m,
	size_t nrOfCells
);

PARAMETERS

const MAP *m
map handle
size_t nrOfCells
number of cells allocated memory must hold

DESCRIPTION

Rmalloc allocates memory to hold nrOfCells cells in both the in-file and app cell representation. Allocation is done by malloc for other users. Our own (utrecht university) applications calls ChkMalloc. Freeing memory allocated by Rmalloc is done by free (or Free).

RETURNS

a pointer the allocated memory or NULL if the request fails

NOTE

Note that a possible RuseAs call must be done BEFORE Rmalloc.

EXAMPLE


#include 
#include "csf.h"

/* process a raster per row
 * minimal checking
 */

extern void DoThatWithRow(REAL4 *, size_t );

void main(int argc, char *argv[] )
{

  REAL4 *buf;
  MAP *map;                      
  size_t r;
  size_t nrOfCells;

  if (argc != 2)
  {
   fprintf(stderr,"%s: no file specified\n",argv[0]);
   exit(1);
  }

  map = Mopen(argv[1], M_READ_WRITE);
  if (map == NULL)  
  {  
     Mperror(argv[1]);
     exit(1);
  }

  nrOfCells = RgetNrCols(map); 

  (void)RuseAs(map, CR_REAL4); 

  buf = (REAL4 *)Rmalloc(map, nrOfCells);

  for(r=0; r < RgetNrRows(map); r++ )
  {
    RgetRow(map, r, buf); 
    DoThatWithRow(buf, nrOfCells);
    RputRow(map,r, buf); 
  }

  Mclose(map);
  free(buf);

  exit(0);
}