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

C++ scalloc函数代码示例

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

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



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

示例1: domain

 /* make the allocations based on the largest need by the three comms:
    1- transfer an atom who has moved into other proc's domain (mpi_atom)
    2- exchange boundary atoms (boundary_atom)
    3- update position info for boundary atoms (mpi_rvec)
    
    the largest space by far is required for the 2nd comm operation above.
    buffers are void*, type cast to the correct pointer type to access 
    the allocated buffers */
int  Allocate_MPI_Buffers( mpi_datatypes *mpi_data, int est_recv, 
			   neighbor_proc *my_nbrs, char *msg )
{
  int i;
  mpi_out_data  *mpi_buf;
  MPI_Comm comm;

  comm = mpi_data->world;

  /* in buffers */
  mpi_data->in1_buffer = (void*) 
    scalloc( est_recv, sizeof(boundary_atom), "in1_buffer", comm );
  mpi_data->in2_buffer = (void*) 
    scalloc( est_recv, sizeof(boundary_atom), "in2_buffer", comm );
  
  /* out buffers */
  for( i = 0; i < MAX_NBRS; ++i ) {
    mpi_buf = &( mpi_data->out_buffers[i] );
    /* allocate storage for the neighbor processor i */
    mpi_buf->index = (int*) 
      scalloc( my_nbrs[i].est_send, sizeof(int), "mpibuf:index", comm );
    mpi_buf->out_atoms = (void*) 
      scalloc( my_nbrs[i].est_send, sizeof(boundary_atom), "mpibuf:out_atoms", 
	       comm );
  }
  
  return SUCCESS;
}
开发者ID:DELILE,项目名称:mdhandle,代码行数:36,代码来源:reaxc_allocate.cpp


示例2: main

int main(int argc, char ** argv) {
  
  assert(argc == 3);
  uint64_t msg_size = atoi(argv[1]);
  int loop_length = atoi(argv[2]);

  bsparrow_t * bsp = bsparrow_new(50000, 4000, 2, 2, 1, "9003");

  bsparrow_event_t bspev;
  bsparrow_socket_t * bsock;
  bsparrow_wait(bsp, &bspev, 0);

  if(bspev.event & 16) {
    bsock = bspev.bsock;
    bsparrow_socket_assign_id(bsock, 1);
  } else {
    exit(-1);
  }
  
  sparrow_msg_t msg;
  int j = 0;
  int64_t time = now();
  while(j < loop_length) {
    int i = 0;
    while(i < 10000) {
      if(i == 5000) {
        char *data = scalloc(1, 100);
        uint64_t temp = 92;
        memcpy(data, &temp, 8);
        sprintf(data + 8,"Got 50, need mooooreee!");
        bsparrow_send(bsp, bsock, &data, 100);
        Dprintf("I am sending an aknowledge msg at msg number: %lu\n", j*100 + 50);
      }
      get_msg(bsp, bsock, &bspev, &msg); 
    
      Dprintf("i: %d\n", i); 
      Dprintf("Remaining length: %lu\n", bspev.total_length -msg_size);
      printmsg(msg);
      i++;
    }
    Dprintf("j: %d\n", j); 
    Dprintf("Remaining length: %lu\n", bspev.total_length -msg_size);
    j++;
  }

  printf("Sending: Got them all, thanks!\n");
  char *data = scalloc(1, 100);
  uint64_t temp = 92;
  memcpy(data, &temp, 8);
  sprintf(data + 8, "Got them all, thanks!");
  bsparrow_send(bsp, bsock, &data, 100);
  results(j*10000, time, msg_size);

  bsparrow_destroy(bsp);
  return 0;
}
开发者ID:xekoukou,项目名称:sparrow,代码行数:56,代码来源:mthr_server.c


示例3: open_new_qseqs

int open_new_qseqs(Settings *opts, Trace_reader *trc, Spot_info *spot) {
  size_t  name_len;
  char   *name;
  int     i;

  if (NULL == trc->qseqs) {
    name_len = strlen(opts->qseq_dir) + strlen(opts->qseq_suffix) + 64;
    name = smalloc(name_len);

    for (i = 0; ; i++) {
      snprintf(name, name_len, "%s/s_%d_%d_%04d_%s",
	       opts->qseq_dir, spot->lane, i + 1,
	       spot->tile, opts->qseq_suffix);
      if (0 != access(name, F_OK)) {
	if (ENOENT == errno) break;
	printf("Error looking up %s: %s\n", name, strerror(errno));
	free(name);
	return -1;
      }
    }

    if (0 == i) {
      printf("Couldn't find qseq files\n");
      free(name);
      return -1;
    }

    trc->nqseqs     = i;
    trc->qseqs      = scalloc(i, sizeof(FILE *));
    trc->qseq_names = scalloc(i, sizeof(char *));
    free(name);

  } else {

    if (0 != close_qseq_files(trc)) return -1;

  }

  for (i = 0; i < trc->nqseqs; i++) {
    trc->qseq_names[i] = aprintf("%s/s_%d_%d_%04d_%s",
				 opts->qseq_dir, spot->lane, i + 1,
				 spot->tile, opts->qseq_suffix);
    trc->qseqs[i] = fopen(trc->qseq_names[i], "r");
    if (NULL == trc->qseqs[i]) {
      printf("Couldn't open %s: %s\n",
	      trc->qseq_names[i], strerror(errno));
      return -1;
    }
  }
  
  return 0;
}
开发者ID:srl147,项目名称:pb_calibration,代码行数:52,代码来源:check_srf.c


示例4: scalloc

/*
 * Build an i3String from an UTF-8 encoded string with fixed length.
 * To be used when no proper NUL-terminaison is available.
 * Returns the newly-allocated i3String.
 *
 */
i3String *i3string_from_utf8_with_length(const char *from_utf8, size_t num_bytes) {
    i3String *str = scalloc(sizeof(i3String));

    /* Copy the actual text to our i3String */
    str->utf8 = scalloc(sizeof(char) * (num_bytes + 1));
    strncpy(str->utf8, from_utf8, num_bytes);
    str->utf8[num_bytes] = '\0';

    /* Store the length */
    str->num_bytes = num_bytes;

    return str;
}
开发者ID:smrt28,项目名称:i3,代码行数:19,代码来源:string.c


示例5: strchr

/*
 * This function resolves ~ in pathnames.
 * It may resolve wildcards in the first part of the path, but if no match
 * or multiple matches are found, it just returns a copy of path as given.
 *
 */
char *resolve_tilde(const char *path) {
    static glob_t globbuf;
    char *head, *tail, *result;

    tail = strchr(path, '/');
    head = strndup(path, tail ? (size_t)(tail - path) : strlen(path));

    int res = glob(head, GLOB_TILDE, NULL, &globbuf);
    free(head);
    /* no match, or many wildcard matches are bad */
    if (res == GLOB_NOMATCH || globbuf.gl_pathc != 1)
        result = sstrdup(path);
    else if (res != 0) {
        die("glob() failed");
    } else {
        head = globbuf.gl_pathv[0];
        result = scalloc(strlen(head) + (tail ? strlen(tail) : 0) + 1);
        strncpy(result, head, strlen(head));
        if (tail)
            strncat(result, tail, strlen(tail));
    }
    globfree(&globbuf);

    return result;
}
开发者ID:Fresne,项目名称:i3-1,代码行数:31,代码来源:util.c


示例6: PreAllocate_Space

/* allocate space for my_atoms
   important: we cannot know the exact number of atoms that will fall into a 
   process's box throughout the whole simulation. therefore 
   we need to make upper bound estimates for various data structures */
int PreAllocate_Space( reax_system *system, control_params *control, 
		       storage *workspace, MPI_Comm comm )
{
  int  i;

  /* determine the local and total capacity */
  system->local_cap = MAX( (int)(system->n * SAFE_ZONE), MIN_CAP );
  system->total_cap = MAX( (int)(system->N * SAFE_ZONE), MIN_CAP );
#if defined(DEBUG)
  fprintf( stderr, "p%d: local_cap=%d total_cap=%d\n", 
	   system->my_rank, system->local_cap, system->total_cap );
#endif

  system->my_atoms = (reax_atom*) 
    scalloc( system->total_cap, sizeof(reax_atom), "my_atoms", comm );
  
  /* space for keeping restriction info, if any */
  // not yet implemented in the parallel version!!!
  // if( control->restrict_bonds ) {
  //   workspace->restricted  = (int*) 
  //     scalloc( system->local_cap, sizeof(int), "restricted_atoms", comm );
    
  //   workspace->restricted_list = (int**) 
  //     scalloc( system->local_cap, sizeof(int*), "restricted_list", comm );
    
  //   for( i = 0; i < system->local_cap; ++i )
  //     workspace->restricted_list[i] = (int*) 
  // 	scalloc( MAX_RESTRICT, sizeof(int), "restricted_list[i]", comm );
  // }
  
  return SUCCESS;
}
开发者ID:DELILE,项目名称:mdhandle,代码行数:36,代码来源:reaxc_allocate.cpp


示例7: tdpotn_get_all_degree

static void tdpotn_get_all_degree(int *sp, int N, int **alld, int *alldNum, double **p_alld, double rate_airedgeChoose) {
	int *ddis = scalloc(N, sizeof(int));

	int i;
	for (i=0; i<N; ++i) {
		if (sp[i] > 0) {
			ddis[sp[i]]++;
		}
	}
	*alld = smalloc(N*sizeof(int));
	*alldNum = 0;
	for (i=2; i<N; ++i) {
		if (ddis[i]) {
			(*alld)[(*alldNum)++] = i;
		}
	}
	free(ddis);

	*p_alld = malloc((*alldNum)*sizeof(double));
	for (i=0; i<*alldNum; ++i) {
		(*p_alld)[i] = pow((*alld)[i], 0-rate_airedgeChoose);
	}
	double total = 0;
	for (i=0; i<*alldNum; ++i) {
		total += (*p_alld)[i];
	}
	for (i=0; i<*alldNum; ++i) {
		(*p_alld)[i] /= total;
	}
	for (i=1; i<*alldNum; ++i) {
		(*p_alld)[i] += (*p_alld)[i-1];
	}
}
开发者ID:xrfind,项目名称:TL,代码行数:33,代码来源:air.c


示例8: fake_configure_notify

/*
 * Generates a configure_notify event and sends it to the given window
 * Applications need this to think they’ve configured themselves correctly.
 * The truth is, however, that we will manage them.
 *
 */
void fake_configure_notify(xcb_connection_t *conn, xcb_rectangle_t r, xcb_window_t window, int border_width) {
    /* Every X11 event is 32 bytes long. Therefore, XCB will copy 32 bytes.
     * In order to properly initialize these bytes, we allocate 32 bytes even
     * though we only need less for an xcb_configure_notify_event_t */
    void *event = scalloc(32);
    xcb_configure_notify_event_t *generated_event = event;

    generated_event->event = window;
    generated_event->window = window;
    generated_event->response_type = XCB_CONFIGURE_NOTIFY;

    generated_event->x = r.x;
    generated_event->y = r.y;
    generated_event->width = r.width;
    generated_event->height = r.height;

    generated_event->border_width = border_width;
    generated_event->above_sibling = XCB_NONE;
    generated_event->override_redirect = false;

    xcb_send_event(conn, false, window, XCB_EVENT_MASK_STRUCTURE_NOTIFY, (char *)generated_event);
    xcb_flush(conn);

    free(event);
}
开发者ID:netzverweigerer,项目名称:i3,代码行数:31,代码来源:fake_configure_notify.c


示例9: createFromBoolean

static r_type_ptr createFromBoolean(int I, type_info* ti) {
	int *space = scalloc(1, sizeof(int));
	*space = I;
	int** ret = salloc(sizeof(int*));
	*ret = space;
	return (r_type_ptr)ret;
}
开发者ID:takumib,项目名称:cpsc855-final,代码行数:7,代码来源:Std_Boolean_Realiz.c


示例10: add_ignore

void add_ignore(const char *nick, time_t delta)
{
    IgnoreData *ign;
    char who[NICKMAX];
    time_t now = time(NULL);
    IgnoreData **whichlist = &ignore[tolower(nick[0])];

    strscpy(who, nick, NICKMAX);
    for (ign = *whichlist; ign; ign = ign->next) {
        if (stricmp(ign->who, who) == 0)
            break;
    }
    if (ign) {
        if (ign->time > now)
            ign->time += delta;
        else
            ign->time = now + delta;
    } else {
        ign = scalloc(sizeof(*ign), 1);
        strscpy(ign->who, who, sizeof(ign->who));
        ign->time = now + delta;
        ign->next = *whichlist;
        *whichlist = ign;
    }
}
开发者ID:TheKing,项目名称:xanadu-irc-services,代码行数:25,代码来源:process.c


示例11: split_buf

int split_buf(char *buf, char ***argv, int colon_special)
{
    int argvsize = 8;
    int argc;
    char *s;

    *argv = scalloc(sizeof(char *) * argvsize, 1);
    argc = 0;
    while (*buf) {
        if (argc == argvsize) {
            argvsize += 8;
            *argv = srealloc(*argv, sizeof(char *) * argvsize);
        }
        if (*buf == ':') {
            (*argv)[argc++] = buf + 1;
            buf = "";
        } else {
            s = strpbrk(buf, " ");
            if (s) {
                *s++ = 0;
                while (*s == ' ')
                    s++;
            } else {
                s = buf + strlen(buf);
            }
            (*argv)[argc++] = buf;
            buf = s;
        }
    }
    return argc;
}
开发者ID:TheKing,项目名称:xanadu-irc-services,代码行数:31,代码来源:process.c


示例12: scalloc

/*
 * Converts the given string to UTF-8 from UCS-2 big endian. The return value
 * must be freed after use.
 *
 */
char *convert_ucs2_to_utf8(xcb_char2b_t *text, size_t num_glyphs) {
    /* Allocate the output buffer (UTF-8 is at most 4 bytes per glyph) */
    size_t buffer_size = num_glyphs * 4 + 1;
    char *buffer = scalloc(buffer_size, 1);

    /* We need to use an additional pointer, because iconv() modifies it */
    char *output = buffer;
    size_t output_size = buffer_size - 1;

    if (utf8_conversion_descriptor == (iconv_t)-1) {
        /* Get a new conversion descriptor */
        utf8_conversion_descriptor = iconv_open("UTF-8", "UCS-2BE");
        if (utf8_conversion_descriptor == (iconv_t)-1)
            err(EXIT_FAILURE, "Error opening the conversion context");
    } else {
        /* Reset the existing conversion descriptor */
        iconv(utf8_conversion_descriptor, NULL, NULL, NULL, NULL);
    }

    /* Do the conversion */
    size_t input_len = num_glyphs * sizeof(xcb_char2b_t);
    size_t rc = iconv(utf8_conversion_descriptor, (char **)&text,
                      &input_len, &output, &output_size);
    if (rc == (size_t)-1) {
        perror("Converting to UTF-8 failed");
        free(buffer);
        return NULL;
    }

    return buffer;
}
开发者ID:Acidburn0zzz,项目名称:i3,代码行数:36,代码来源:ucs2_conversion.c


示例13: scalloc

static User *new_user(const char *nick)
{
    User *user, **list;

    user = scalloc(sizeof(User), 1);
    if (!nick)
        nick = "";
    strscpy(user->nick, nick, NICKMAX);
    list = &userlist[HASH(user->nick)];
    user->next = *list;
    if (*list)
        (*list)->prev = user;
    *list = user;
    user->na = findnick(nick);
    if (user->na)
        user->na->u = user;
    usercnt++;
    if (usercnt > maxusercnt) {
        maxusercnt = usercnt;
        maxusertime = time(NULL);
        if (LogMaxUsers)
            alog("user: New maximum user count: %d", maxusercnt);
    }
    user->isSuperAdmin = 0;     /* always set SuperAdmin to 0 for new users */
    user->nickTrack = NULL;     /* ensure no default tracking nick */
    return user;
}
开发者ID:Elemental-IRCd,项目名称:anope,代码行数:27,代码来源:users.c


示例14: common_unban2

void common_unban2(ChannelInfo * ci, char *nick) {
   User *u;
   char *av[3], **bans;
   int count, i;

   if (!ci || !nick)
      return;
   else if (!(u = finduser(nick)))
      return;
   
   av[0] = ci->name;
   av[1] = sstrdup("-b");
   count = ci->c->bancount;
   bans = scalloc(sizeof(char *) * count, 1);
   memcpy(bans, ci->c->bans, sizeof(char *) * count);
   for (i = 0; i < count; i++) {
      if (match_usermask2(bans[i], u)) {
         anope_cmd_mode(whosends(ci), ci->name, "-b %s", bans[i]);
         av[2] = bans[i];
         do_cmode(whosends(ci), 3, av);
      }
   }
   free(bans);
   free(av[1]);
}
开发者ID:SwiftIRC,项目名称:services,代码行数:25,代码来源:bs_fantasy_unban.c


示例15: createBoolean

static r_type_ptr createBoolean(type_info* ti) {
    int* t = scalloc(1, sizeof(int));
	*t = 0;
    int** ret = salloc(sizeof(int*));
    *ret = t;
    return (r_type_ptr)ret;
}
开发者ID:takumib,项目名称:cpsc855-final,代码行数:7,代码来源:Std_Boolean_Realiz.c


示例16: add_session

int add_session(char *nick, char *host, char *hostip)
{
    Session *session, **list;
    Exception *exception;
    int sessionlimit = 0;

    session = findsession(host);

    if (session) {
        exception = find_hostip_exception(host, hostip);

        if (checkDefCon(DEFCON_REDUCE_SESSION)) {
            sessionlimit =
                exception ? exception->limit : DefConSessionLimit;
        } else {
            sessionlimit = exception ? exception->limit : DefSessionLimit;
        }

        if (sessionlimit != 0 && session->count >= sessionlimit) {
            if (SessionLimitExceeded)
                notice(s_OperServ, nick, SessionLimitExceeded, host);
            if (SessionLimitDetailsLoc)
                notice(s_OperServ, nick, "%s", SessionLimitDetailsLoc);

            /* We don't use kill_user() because a user stucture has not yet
             * been created. Simply kill the user. -TheShadow
             */
            kill_user(s_OperServ, nick, "Session limit exceeded");

            session->hits++;
            if (MaxSessionKill && session->hits >= MaxSessionKill) {
                char akillmask[BUFSIZE];
                snprintf(akillmask, sizeof(akillmask), "*@%s", host);
                add_akill(NULL, akillmask, s_OperServ,
                          time(NULL) + SessionAutoKillExpiry,
                          "Session limit exceeded");
                anope_cmd_global(s_OperServ,
                                 "Added a temporary AKILL for \2%s\2 due to excessive connections",
                                 akillmask);
            }
            return 0;
        } else {
            session->count++;
            return 1;
        }
    }

    nsessions++;
    session = scalloc(sizeof(Session), 1);
    session->host = sstrdup(host);
    list = &sessionlist[HASH(session->host)];
    session->next = *list;
    if (*list)
        (*list)->prev = session;
    *list = session;
    session->count = 1;

    return 1;
}
开发者ID:Elemental-IRCd,项目名称:anope,代码行数:59,代码来源:sessions.c


示例17: scalloc

/* debug calloc: scalloc() with memory management */
void *d_calloc( size_t elsize, size_t els )
{
	void *p = scalloc( elsize, els );
	
	clog( CL_DEBUG, "scalloc(%d,%d) -> %p", elsize, els, p );
	
	return p;
}
开发者ID:theojulienne,项目名称:Claro,代码行数:9,代码来源:memory.c


示例18: snprintf

static database_handle_t *opensex_db_open_read(const char *filename)
{
	database_handle_t *db;
	opensex_t *rs;
	FILE *f;
	int errno1;
	char path[BUFSIZE];

	snprintf(path, BUFSIZE, "%s/%s", datadir, filename != NULL ? filename : "services.db");
	f = fopen(path, "r");
	if (!f)
	{
		errno1 = errno;

		/* ENOENT can happen if the database does not exist yet. */
		if (errno == ENOENT)
		{
			slog(LG_ERROR, "db-open-read: database '%s' does not yet exist; a new one will be created.", path);
			return NULL;
		}

		slog(LG_ERROR, "db-open-read: cannot open '%s' for reading: %s", path, strerror(errno1));
		wallops(_("\2DATABASE ERROR\2: db-open-read: cannot open '%s' for reading: %s"), path, strerror(errno1));
		return NULL;
	}

	rs = scalloc(sizeof(opensex_t), 1);
	rs->grver = 1;
	rs->buf = scalloc(512, 1);
	rs->bufsize = 512;
	rs->token = NULL;
	rs->f = f;

	db = scalloc(sizeof(database_handle_t), 1);
	db->priv = rs;
	db->vt = &opensex_vt;
	db->txn = DB_READ;
	db->file = sstrdup(path);
	db->line = 0;
	db->token = 0;

	return db;
}
开发者ID:ItsAGeekThing,项目名称:Xtheme,代码行数:43,代码来源:opensex.c


示例19: add_bot_to_chan

/**
 * add a bot to a channel
 */
void add_bot_to_chan(char *botname, char *chan) {
	bot *b = findbot(botname);
	botchan *bc = scalloc(sizeof(botchan),1);
	bc->next = b->chanlist;
	if (b->chanlist) {
		b->chanlist->prev = bc;
	}
	b->chanlist = bc;
	bc->chan = sstrdup(chan);
}
开发者ID:fish-guts,项目名称:reefmaster,代码行数:13,代码来源:botserv.c


示例20: uds_connection_cb

static void uds_connection_cb(EV_P_ ev_io *w, int revents) {
    struct sockaddr_un addr;
    socklen_t addrlen = sizeof(addr);
    const int clientfd = accept(w->fd, (struct sockaddr *)&addr, &addrlen);
    if (clientfd == -1) {
        if (errno == EINTR) {
            return;
        }
        err(EXIT_FAILURE, "accept()");
    }

    struct connstate *connstate = scalloc(1, sizeof(struct connstate));

    ev_io *clientw = scalloc(1, sizeof(ev_io));
    connstate->clientw = clientw;
    clientw->data = connstate;
    ev_io_init(clientw, read_client_setup_request_cb, clientfd, EV_READ);
    ev_io_start(EV_A_ clientw);
}
开发者ID:bsmr-i3,项目名称:i3,代码行数:19,代码来源:inject_randr1.5.c



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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