当前位置: 首页>>代码示例>>C++>>正文


C++ Calloc函数代码示例

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


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

示例1: read_mtp

SEXP
read_mtp(SEXP fname)
{
    FILE *f;
    char buf[MTP_BUF_SIZE], blank[1], *pres;
    MTB  *mtb, thisRec;
    int i, j, res, nMTB = MTB_INITIAL_ENTRIES;

    PROTECT(fname = asChar(fname));
#ifdef WIN32 /* force text-mode read */
    if ((f = fopen(R_ExpandFileName(CHAR(fname)), "rt")) == NULL)
#else
    if ((f = fopen(R_ExpandFileName(CHAR(fname)), "r")) == NULL)
#endif
	error(_("unable to open file '%s': '%s'"), 
	      CHAR(fname), strerror(errno));
    if ((fgets(buf, MTP_BUF_SIZE, f) == NULL) ||
	strncmp(buf, "Minitab Portable Worksheet ", 27) != 0)
	error(_("file '%s' is not in Minitab Portable Worksheet format"),
	      CHAR(fname));
    pres = fgets(buf, MTP_BUF_SIZE, f);
    if(pres != buf) error(_("file read error"));
    UNPROTECT(1);

    mtb = Calloc(nMTB, MTB);
    for (i = 0; !feof(f); i++) {
	if (i >= nMTB) {
	    nMTB *= 2;
	    mtb = Realloc(mtb, nMTB, MTB);
	}
	thisRec = mtb[i] = Calloc(1, MTBDATC);
	if (sscanf(buf, "%%%7d%7d%7d%7d%c%8c", &(thisRec->type),
		   &(thisRec->cnum), &(thisRec->len),
		   &(thisRec->dtype), blank, thisRec->name) != 6)
	    error(_("first record for entry %d is corrupt"), i+1);
	thisRec->name[8] = '\0';
	strtrim(thisRec->name);	/* trim trailing white space on name */
	switch (thisRec->dtype) {
	case 0:		/* numeric data */
	    thisRec->dat.ndat = Calloc(thisRec->len, double);
	    for (j = 0; j < thisRec->len; j++) {
		res = fscanf(f, "%lg", thisRec->dat.ndat + j);
		if(res == EOF) error(_("file read error"));
	    }
	    break;
	default:
	    if (thisRec->type == 4) { /* we have a matrix so dtype is number of columns */
		thisRec->dat.ndat = Calloc(thisRec->len, double);
		for (j = 0; j < thisRec->len; j++) {
		    res = fscanf(f, "%lg", thisRec->dat.ndat + j);
		    if(res == EOF) error(_("file read error"));
		}
	    } else {
		error(_("non-numeric data types are not yet implemented"));
	    }
	}
开发者ID:cran,项目名称:foreign,代码行数:56,代码来源:minitab.c

示例2: Calloc

SLABELS *CreateSLabels(void){
  uint32_t n;
  SLABELS *SL = (SLABELS *) Calloc(1, sizeof(SLABELS));
  SL->idx     = 0;
  SL->maxV    = SLCACHE;
  SL->maxH    = SLMAXSTR;
  SL->names   = (uint8_t **) Calloc(SL->maxV, sizeof(uint8_t *));
  for(n = 0 ; n < SL->maxV ; ++n)
    SL->names[n] = (uint8_t *) Calloc(SL->maxH+1, sizeof(uint8_t));
  return SL;
  }
开发者ID:pratas,项目名称:falcon,代码行数:11,代码来源:labels.c

示例3: ssc_metis_order

/**
 * Establish a fill-reducing permutation for the sparse symmetric
 * matrix of order n represented by the column pointers Tp and row
 * indices Ti.
 *
 * @param n  order of the sparse symmetric matrix
 * @param Tp  column pointers (total length n + 1)
 * @param Ti  row indices (total length Tp[n])
 * @param Perm array of length n to hold the permutation
 * @param iPerm array of length n to hold the inverse permutation
 *
 */
void ssc_metis_order(int n, const int Tp [], const int Ti [],
                     int Perm[], int iPerm[])
{
    int  j, num_flag = 0, options_flag = 0;
    idxtype
    *perm = Calloc(n, idxtype), /* in case idxtype != int */
     *iperm = Calloc(n, idxtype),
      *xadj = Calloc(n+1, idxtype),
       *adj = Calloc(2 * (Tp[n] - n), idxtype);

    /* check row indices for correct range */
    for (j = 0; j < Tp[n]; j++)
        if (Ti[j] < 0 || Ti[j] >= n)
            error(_("row index Ti[%d] = %d is out of range [0,%d]"),
                  j, Ti[j], n - 1);
    /* temporarily use perm to store lengths */
    AZERO(perm, n);
    for (j = 0; j < n; j++) {
        int ip, p2 = Tp[j+1];
        for (ip = Tp[j]; ip < p2; ip++) {
            int i = Ti[ip];
            if (i != j) {
                perm[i]++;
                perm[j]++;
            }
        }
    }
    xadj[0] = 0;
    for (j = 0; j < n; j++) xadj[j+1] = xadj[j] + perm[j];
    /* temporarily use perm to store pointers */
    Memcpy(perm, xadj, n);
    for (j = 0; j < n; j++) {
        int ip, p2 = Tp[j+1];
        for (ip = Tp[j]; ip < p2; ip++) {
            int i = Ti[ip];
            if (i != j) {
                adj[perm[i]] = j;
                adj[perm[j]] = i;
                perm[i]++;
                perm[j]++;
            }
        }
    }
    METIS_NodeND(&n, xadj, adj, &num_flag, &options_flag, perm, iperm);
    for (j = 0; j < n; j++) {
        Perm[j] = (int) perm[j];
        iPerm[j] = (int) iperm[j];
    }
    Free(iperm);
    Free(perm);
    Free(xadj);
    Free(adj);
}
开发者ID:rforge,项目名称:matrix,代码行数:65,代码来源:Metis_utils.c

示例4: greet

/*
 *  woo.. no args? we use CurrentChan, CurrentNick and CurrentUser.
 */
void greet(void)
{
	Strp	*sp,**pp;
	char	linebuf[MSGLEN],readbuf[MSGLEN];
	char	*str;
	int	fd,sz;

	pp = &current->sendq;
	while(*pp)
		pp = &(*pp)->next;

	if (CurrentUser->x.x.greetfile)
	{
		if ((fd = open(CurrentUser->greet,O_RDONLY)) < 0)
			return;

		sz = sizeof(Strp) + 9 + strlen(CurrentNick);

		memset(readbuf,0,sizeof(readbuf));
		while(TRUE)
		{
			str = sockread(fd,readbuf,linebuf);
			if (str)
			{
				*pp = sp = (Strp*)Calloc(sz + strlen(str));
				/* Calloc sets to zero sp->next = NULL; */
				pp = &sp->next;
				sprintf(sp->p,"NOTICE %s :%s",CurrentNick,str);
			}
			else
			if (errno != EAGAIN)
				break;
		}

		close(fd);
	}
	else
	if (CurrentUser->x.x.randline)
	{
		if ((str = randstring(CurrentUser->greet)))
			goto single_line;
		return;
	}
	else
	{
		str = CurrentUser->greet;
single_line:
		*pp = sp = (Strp*)Calloc(sizeof(Strp) + 13 + Strlen(CurrentChan->name,CurrentNick,str,NULL));
		sprintf(sp->p,"PRIVMSG %s :[%s] %s",CurrentChan->name,CurrentNick,str);
		/* Calloc sets to zero sp->next = NULL; */
	}
}
开发者ID:Cloudxtreme,项目名称:energymech,代码行数:55,代码来源:greet.c

示例5: make_mi

int make_mi(mi_t* const m, const int n, const int k) {
  if (n < k) return 0;

  m->k = k;
  m->n = n;
  init_psi(m);
  m->sxs  = Calloc(n, coord_t);
  m->xiis = Calloc(n, int);
  m->sys  = Calloc(n, coord_t);
  m->yiis = Calloc(n, int);

  return 1;
}
开发者ID:cran,项目名称:rsgcc,代码行数:13,代码来源:mi.c

示例6: assert

lh *lh_init(char *name, int dim) {
  lh *x;

  assert(name != 0);			/* pre */
  assert(dim > 0 && dim < LH_MAX_DIM);

  x = Calloc(1, sizeof(lh));
  x->name = name;
  x->h = Calloc(dim, sizeof(float));
  x->dim = dim;
  x->cnt = 0, x->outlyers = 0;
  return x;
}
开发者ID:mcromaz,项目名称:petcat,代码行数:13,代码来源:lh.c

示例7: fprintf

CModel *CreateCModel(uint32_t ctxSize, uint32_t nSymbols, uint32_t deltaNum, 
	uint32_t deltaDen)
{
	uint32_t  n, prod = 1;
	CModel    *cModel;

	if(ctxSize < 1)
	{
		fprintf(stderr, "Error (CreateCModel): context size must be greater than 0!\n");
		fprintf(stderr, "Error (CreateCModel): context size read = %"PRIu32"\n", ctxSize);
		exit(EXIT_FAILURE);
	}
	
	if(nSymbols < 1)
	{
		fprintf(stderr, "Error (CreateCModel): number of symbols must be greater than 0!\n");
		fprintf(stderr, "Error (CreateCModel): number of symbols read = %"PRIu32"\n", nSymbols);
		exit(EXIT_FAILURE);
	}

	cModel               = (CModel   *) Calloc(1,       sizeof(CModel  ));
	cModel->multipliers  = (uint32_t *) Calloc(ctxSize, sizeof(uint32_t));
	cModel->nPModels     = (uint64_t)   pow(nSymbols, ctxSize);
	cModel->ctxSize      = ctxSize;
	cModel->nSymbols     = nSymbols;
	cModel->pModelIdx    = 0;
	cModel->deltaNum = deltaNum;
	cModel->deltaDen = deltaDen;

	switch(nSymbols)
	{
    	case 2:
			cModel->kMinusOneMask = (0x01 << (ctxSize - 1)) - 1;
			break;

		case 4:
			cModel->kMinusOneMask = (0x01 << 2 * (ctxSize - 1)) - 1;
			break;
    }

	for(n = 0 ; n != ctxSize ; ++n)
    {
		cModel->multipliers[n] = prod;
    	prod                  *= nSymbols;
    }
	
	cModel->counters = (ACCounter *) Calloc(cModel->nPModels * nSymbols,
		sizeof(ACCounter));
	return cModel;
}
开发者ID:lumiratos,项目名称:mafco,代码行数:50,代码来源:context.c

示例8: ShowTemplate

void ShowTemplate(CTemplate *cTemplate)
{
	int8_t minRow, maxRow, minCol, maxCol, n, row, col;
	int8_t **templateMatrix=NULL;
	minRow = maxRow = cTemplate->position[0].row;
	minCol = maxCol = cTemplate->position[0].col;
  
	for(n = 1 ; n != cTemplate->size ; ++n)
 	{
		if(cTemplate->position[n].row > maxRow)
			maxRow = cTemplate->position[n].row;

		if(cTemplate->position[n].row < minRow)
			minRow = cTemplate->position[n].row;

		if(cTemplate->position[n].col > maxCol)
			maxCol = cTemplate->position[n].col;

		if(cTemplate->position[n].col < minCol)
			minCol = cTemplate->position[n].col;
	}

	templateMatrix = (int8_t **)Calloc(maxRow - minRow + 2, sizeof(int8_t *));

	for(row = 0 ; row != maxRow - minRow + 2 ; ++row)
		templateMatrix[row] = (int8_t *)Calloc(maxCol - minCol + 2, sizeof(int8_t));
	
	for(n = 0 ; n < cTemplate->size ; n++)
		templateMatrix[cTemplate->position[n].row - minRow][cTemplate->position[n].col - minCol] = n + 1;

	templateMatrix[-minRow][-minCol] = -1;
	for(row = 0 ; row != maxRow - minRow + 2 ; ++row)
	{
		for(col = 0 ; col != maxCol - minCol + 2 ; ++col)
			if(templateMatrix[row][col])
			{
				if(templateMatrix[row][col] == -1)
					printf("  X");
				else
					printf("%3"PRIu8"", templateMatrix[row][col]);
			}
			else printf("   ");

		putchar('\n');
	}
	
  	for(row = 0 ; row != maxRow - minRow + 2 ; ++row)
  		Free(templateMatrix[row], (maxCol-minCol+2)* sizeof(int8_t));
  	Free(templateMatrix, (maxRow - minRow + 2) * sizeof(int8_t *));
}
开发者ID:lumiratos,项目名称:mafco,代码行数:50,代码来源:context.c

示例9: Calloc

/*********************
 void WtMHProposalInitialize

 A helper function to process the MH_* related initialization.
*********************/
WtMHProposal *WtMHProposalInitialize(
	     char *MHProposaltype, char *MHProposalpackage, 
	       double *inputs,
	     int fVerbose,
	     WtNetwork *nwp){
  WtMHProposal *MHp = Calloc(1, WtMHProposal);

  char *fn, *sn;
  int i;
  for (i = 0; MHProposaltype[i] != ' ' && MHProposaltype[i] != 0; i++);
  MHProposaltype[i] = 0;
  /* Extract the required string information from the relevant sources */
  fn = Calloc(i+4, char);
  fn[0]='M';
  fn[1]='H';
  fn[2]='_';
  for(int j=0;j<i;j++)
    fn[j+3]=MHProposaltype[j];
  fn[i+3]='\0';
  /* fn is now the string 'MH_[name]', where [name] is MHProposaltype */
  for (i = 0; MHProposalpackage[i] != ' ' && MHProposalpackage[i] != 0; i++);
  MHProposalpackage[i] = 0;
  sn = Calloc(i+1, char);
  sn=strncpy(sn,MHProposalpackage,i);
  sn[i]='\0';
  
  /* Search for the MH proposal function pointer */
  MHp->func=(void (*)(WtMHProposal*, WtNetwork*)) R_FindSymbol(fn,sn,NULL);
  if(MHp->func==NULL){
    error("Error in MH_* initialization: could not find function %s in "
	  "namespace for package %s."
	  "Memory has not been deallocated, so restart R sometime soon.\n",fn,sn);
  }

  MHp->inputs=inputs;
  
  MHp->discord=NULL;

  /*Clean up by freeing sn and fn*/
  Free(fn);
  Free(sn);

  MHp->ntoggles=0;
  (*(MHp->func))(MHp, nwp); /* Call MH proposal function to initialize */
  MHp->toggletail = (Vertex *)Calloc(MHp->ntoggles, Vertex);
  MHp->togglehead = (Vertex *)Calloc(MHp->ntoggles, Vertex);
  MHp->toggleweight = (double *)Calloc(MHp->ntoggles, double);

  return MHp;
}
开发者ID:cran,项目名称:ergm,代码行数:55,代码来源:wtMHproposal.c

示例10: compute_hits

word_t *
compute_hits (unsigned from, unsigned to, unsigned n, const wfa_t *wfa)
/*
 *  Selects the 'n' most popular domain images of the given 'wfa'.
 *  Consider only linear combinations of state images
 *  {i | 'from' <= i <= 'to'}. I.e. domains are in {i | from <= i < 'to'}
 *  Always ensure that state 0 is among selected states even though from
 *  may be > 0.
 *  
 *  Return value:
 *	pointer to array of the most popular state images
 *	sorted by increasing state numbers and terminated by -1
 */
{
   word_t   *domains;
   unsigned  state, label, edge;
   int       domain;
   pair_t   *hits = Calloc (to, sizeof (pair_t));

   for (domain = 0; domain < (int) to; domain++)
   {
      hits [domain].value = domain;
      hits [domain].key   = 0;
   }
   
   for (state = from; state <= to; state++)
      for (label = 0; label < MAXLABELS; label++)
	 for (edge = 0; isedge (domain = wfa->into [state][label][edge]);
	      edge++)
	    hits [domain].key++;

   qsort (hits + 1, to - 1, sizeof (pair_t), sort_desc_pair);

   n       = min (to, n);
   domains = Calloc (n + 1, sizeof (word_t));

   for (domain = 0; domain < (int) n && (!domain || hits [domain].key);
	domain++)
      domains [domain] = hits [domain].value;
   if (n != domain)
      debug_message ("Only %d domains have been used in the luminance.",
		     domain);
   n = domain;
   qsort (domains, n, sizeof (word_t), sort_asc_word);
   domains [n] = -1;
   
   Free (hits);
   
   return domains;
}
开发者ID:emanuele,项目名称:Fiasco,代码行数:50,代码来源:wfalib.c

示例11: main

S32 main()
{
    S32 ret;
    U32 length;
    U8  *keySalt;
    U8  *base64KeySalt;
    U8  index;

    /* Create a memory pool */
    pool = CreateMemoryPool(MEMORY_POOL_SIZE);
    if (pool == NULL)
    {
		DP("Memory pool failed to be created.\n");
        return RFAILED;
    }

    length = ((KEY_SALT_ORIG_LEN + 2) / 3) * 4 + 1;
    base64KeySalt = (U8 *)Calloc(pool, length);
    keySalt = (U8 *)Calloc(pool, KEY_SALT_ORIG_LEN);

    /* create master key and salt */
    DP("1. Start to create master key and salt...\n\n");
    ret = CreateCryptoKeySalt(base64KeySalt);
    if (ret != ROK)
    {
        DP("Master key and salt could not be created.\n");
        return ret;
    }
    DP("Base64 master key and salt[%d]:\n\"%s\"\n\n", strlen(base64KeySalt), base64KeySalt);

    /* base64 decoding */
    DP("2. Start to base64 decode master key and salt...\n\n");
    ret = Base64Decode(base64KeySalt, length - 1, keySalt);
    if (ret != ROK)
    {
        DP("Master key and salt could not be decoded.\n");
        return ret;
    }

    DP("Master key and salt:\n");
    for (index = 0; index < KEY_SALT_ORIG_LEN; index++)
    {
        DP("0x%02x ", keySalt[index]);
    }
    DP("\n\n");

    /* Destroy a memory pool */
    DestroyMemoryPool(pool);
    return ROK;
}
开发者ID:conniechen19870216,项目名称:kavonUT,代码行数:50,代码来源:sdes_main.c

示例12: AddID

void
AddID(Element *e, char *idval)
{
    static ID *id_last;
    if (!IDList) {
	Calloc(1, id_last, ID);
	IDList = id_last;
    }
    else {
	Calloc(1, id_last->next, ID);
	id_last = id_last->next;
    }
    id_last->elem = e;
    id_last->id   = idval;
}
开发者ID:juddy,项目名称:edcde,代码行数:15,代码来源:hyper.c

示例13: initialize_circulant

static void initialize_circulant(hbhankel_matrix *h,
                                 const double *F,
                                 R_len_t rank,
                                 const R_len_t *N,
                                 const R_len_t *L,
                                 const int *circular) {
  fftw_complex *ocirc;
  fftw_plan p1, p2;
  double *circ;
  R_len_t *revN, r;

  /* Allocate needed memory */
  circ = (double*) fftw_malloc(prod(rank, N) * sizeof(double));
  ocirc = (fftw_complex*) fftw_malloc(hprod(rank, N) * sizeof(fftw_complex));

  /* Estimate the best plans for given input length, note, that input data is
     stored in column-major mode, that's why we're passing dimensions in
     *reverse* order */
  revN = Calloc(rank, R_len_t);
  for (r = 0; r < rank; ++r) revN[r] = N[rank - 1 - r];
  p1 = fftw_plan_dft_r2c(rank, revN, circ, ocirc, FFTW_ESTIMATE);
  p2 = fftw_plan_dft_c2r(rank, revN, ocirc, circ, FFTW_ESTIMATE);
  Free(revN);

  /* Fill input buffer */
  memcpy(circ, F, prod(rank, N) * sizeof(double));

  /* Run the plan on input data */
  fftw_execute(p1);

  /* Cleanup and return */
  fftw_free(circ);

  h->circ_freq = ocirc;
  h->r2c_plan = p1;
  h->c2r_plan = p2;

  h->rank = rank;

  h->window = Calloc(rank, R_len_t);
  memcpy(h->window, L, rank * sizeof(R_len_t));

  h->length = Calloc(rank, R_len_t);
  memcpy(h->length, N, rank * sizeof(R_len_t));

  h->factor = Calloc(rank, R_len_t);
  for (r = 0; r < rank; ++r) h->factor[r] = circular[r] ? N[r] : N[r] - L[r] + 1;
}
开发者ID:asl,项目名称:rssa,代码行数:48,代码来源:hbhankel.c

示例14: mulcol

/*---------------------------------------*/
void mulcol(csr_t *A, options_t *opts,
            precon_t *prec, int *perm) {
    /*---------------------------------------*/
    PREC_TYPE ptype;
    int n,i,maxcol,ncol,*kolrs,*il,err;
    csr_t *C;
    /*---------------------------------------*/
    n = A->n;
    ptype = opts->prectype;
    printf("begin MULTI-COLOR ...\n");
    /*------- symetrize matrix */
    Calloc(C, 1, csr_t);
    symmgraph(A, C);
    /*-------- multi-color reordering */
    if (ptype == MCSOR)
        maxcol = opts->mcsor_opt->maxcol;
    else
        maxcol = opts->mcilu0_opt->maxcol;
    /*---------------------*/
    Calloc(kolrs, n, int);
    Calloc(il, maxcol+1, int);
    /*-------- input node order */
    for (i=0; i<n; i++) perm[i] = i+1;
    /*-------- multi-coloring, greedy alg */
    multic_(&n, C->ja, C->ia, &ncol, kolrs,
            il, perm, &maxcol, &err);
    if (err != 0) {
        printf("exceed max num of colors\n");
        exit(-1);
    }
    printf("  done, %d colors\n", ncol);
    /*-----------------------*/
    if (ptype == MCSOR) {
        Calloc(prec->mcsor, 1, mcsor_prec_t);
        prec->mcsor->ncol = ncol;
        prec->mcsor->kolrs = kolrs;
        prec->mcsor->il = il;
    } else {
        Calloc(prec->mcilu0, 1, mcilu0_prec_t);
        prec->mcilu0->ncol = ncol;
        prec->mcilu0->kolrs = kolrs;
        prec->mcilu0->il = il;
    }
    /*----------------- done */
    free(C->ja);
    free(C->ia);
    free(C);
}
开发者ID:ypzhang,项目名称:playground,代码行数:49,代码来源:reorder_mc.cpp

示例15: Calloc

lh *lh_init_ia(char *name, int *h, int dim) {

  lh *x;
  int i;

  x = Calloc(1, sizeof(lh));
  x->name = name;
  x->h = Calloc(dim, sizeof(float));
  x->dim = dim;
  for (i = 0; i < x->dim; i++) {
    x->h[i] = (float) h[i];
    x->cnt += h[i];
  }
  x->outlyers = 0;
  return x;
}
开发者ID:mcromaz,项目名称:petcat,代码行数:16,代码来源:lh.c


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