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

C++ Calloc函数代码示例

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

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



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


示例16: Calloc

cache *initialize_cache(){
	cache *proxy_cache = Calloc(1, sizeof(cache));
	proxy_cache->start = NULL;
	proxy_cache->end = NULL;
	proxy_cache->cache_size = 0;
	return proxy_cache;
}
开发者ID:abist,项目名称:Web-caching-proxy,代码行数:7,代码来源:proxy.c


示例17: ngin

double *Nonlinear_equation(double *magnitude, double *phase)
  { 
    extern int ngin();
    int m,n,i,ka;
    double eps1,eps2;
    void nginf(int,int,double [],double []);
    void ngins(int,int,double [],double [][4]);
    double *x;
   
    x = Calloc(4 , sizeof(double));   
    x[0] = 5400.0;
    x[1] = 340.0;
    x[2] = 0.5;
    x[3] = 0.4;
    
    m=In_vect_n*In_vect_n; n=4; ka=m+1; eps1=0.0000000001; eps2=0.00000001;
    i=ngin(m,n,eps1,eps2,x,ka,nginf,ngins,magnitude,phase);
    printf("\n");
    printf("i=%d\n",i);
    printf("\n");
    for (i=0; i<=3; i++)
      printf("x[%d]=%13.7e\n",i,x[i]);
    printf("\n");
	return x;
  }
开发者ID:crossvalidator,项目名称:neural_net_time_series,代码行数:25,代码来源:Non_linear_equation.c


示例18: main

int
main(int argc, char **argv)
{
	int			listenfd, i;
	socklen_t	addrlen;
	void		sig_int(int);
	pid_t		child_make(int, int, int);

	if (argc == 3)
		listenfd = Tcp_listen(NULL, argv[1], &addrlen);
	else if (argc == 4)
		listenfd = Tcp_listen(argv[1], argv[2], &addrlen);
	else
		err_quit("usage: serv03 [ <host> ] <port#> <#children>");
	nchildren = atoi(argv[argc-1]);
	pids = Calloc(nchildren, sizeof(pid_t));
	cptr = meter(nchildren);

	my_lock_init("/tmp/lock.XXXXXX");	/* one lock file for all children */
	for (i = 0; i < nchildren; i++)
		pids[i] = child_make(i, listenfd, addrlen);	/* parent returns */

	Signal(SIGINT, sig_int);

	for ( ; ; )
		pause();	/* everything done by children */
}
开发者ID:tcharding,项目名称:self_learning,代码行数:27,代码来源:serv03m.c


示例19: ControlInit

/*========================================================================*/
int ControlInit(PyMOLGlobals * G)
{
  register CControl *I = NULL;

  if((I = (G->Control = Calloc(CControl, 1)))) {

    I->Block = OrthoNewBlock(G, NULL);
    I->Block->fClick = ControlClick;
    I->Block->fDraw = ControlDraw;
    I->Block->fDrag = ControlDrag;
    I->Block->fRelease = ControlRelease;
    I->Block->fReshape = ControlReshape;
    I->Block->active = true;
    I->Block->TextColor[0] = 1.0;
    I->Block->TextColor[1] = 0.75;
    I->Block->TextColor[2] = 0.75;
    I->ButtonColor[0] = 0.5F;
    I->ButtonColor[1] = 0.5F;
    I->ButtonColor[2] = 0.5F;
    I->ActiveColor[0] = 0.65F;
    I->ActiveColor[1] = 0.65F;
    I->ActiveColor[2] = 0.65F;
    I->Pressed = -1;
    I->Active = -1;
    OrthoAttach(G, I->Block, cOrthoTool);
    I->SaveWidth = 0;
    I->LastClickTime = UtilGetSeconds(G);
    I->NButton = 9;
    return 1;
  } else
    return 0;
}
开发者ID:aghozlane,项目名称:pymol,代码行数:33,代码来源:Control.c


示例20: do_note

void do_note(COMMAND_ARGS)
{
	User	*u;
	Note	*n;
	Strp	*sp,**np;
	char	header[MSGLEN];

	/*
	 *  no-args is handled in on_msg()
	 */
	if (!(u = find_handle(rest)))
	{
		to_user(from,TEXT_UNKNOWNUSER,rest);
		return;
	}
	to_user(from,"Enter your note for %s, end with \".\" on a line by itself",
		u->name);

	set_mallocdoer(do_note);
	n = Calloc(sizeof(Note) + StrlenX(from,to,u->name,NULL));
	n->start = now;
	n->next = notelist;
	notelist = n;

	n->to = stringcat(n->from,from) + 1;
	n->user = stringcat(n->to,to) + 1;
	stringcpy(n->user,rest);

	/*
	 *  add a note header
	 */
	sprintf(header,"\001%s %s",from,time2str(now));
	append_strp(&u->note,header);
}
开发者ID:MadCamel,项目名称:energymech,代码行数:34,代码来源:note.c



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C++ Camera函数代码示例发布时间:2022-05-30
下一篇:
C++ Callback函数代码示例发布时间: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