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

C++ s_malloc函数代码示例

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

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



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

示例1: pthread_mutex_lock

compr *lzo_compress(unsigned char *buf, int buflen)
{
    int r;
    lzo_bytep in;
    lzo_bytep out;
    lzo_bytep wrkmem;
    lzo_uint out_len;
    compr *retdata;

    pthread_mutex_lock(&lzo_mutex);
    retdata = s_malloc(sizeof(compr));
    in = (lzo_bytep) buf;
    out = (lzo_bytep) lzo_malloc(OUT_LEN);
    wrkmem = (lzo_bytep) lzo_malloc(LZO1A_MEM_COMPRESS);
    if (in == NULL || out == NULL || wrkmem == NULL) {
        LFATAL("out of memory\n");
        exit(3);
    }

    r = lzo1a_compress(in, buflen, out, &out_len, wrkmem);
    if (r != LZO_E_OK) {
        /* this should NEVER happen */
        LFATAL("internal error - compression failed: %d\n", r);
        exit(2);
    }
    // LDEBUG("Compressed %i bytes to %lu bytes",buflen,(unsigned long)out_len);

    if ( out_len > buflen ) {
       retdata->data = s_malloc(buflen+1);
       memcpy(&retdata->data[1], buf, buflen);
       retdata->size = buflen+1;
       retdata->data[0]=0;
    } else {
       retdata->data = s_malloc(out_len+1);
       retdata->size = out_len+1;
       memcpy(&retdata->data[1], out, out_len);
       retdata->data[0]='L';
    }
    lzo_free(wrkmem);
    lzo_free(out);
    pthread_mutex_unlock(&lzo_mutex);
    return retdata;
}
开发者ID:crass,项目名称:lessfs,代码行数:43,代码来源:lib_lzo.c


示例2: s_calloc

void * s_calloc (size_t nmemb, size_t size)
{
	void *ret;
	ret = s_malloc(nmemb * size);
	if (ret == NULL) {
		debugf(DFAT, "Not enough memory!");
	}
	memset(ret, 0, nmemb * size);
	return ret;
}
开发者ID:jetlive,项目名称:xynth,代码行数:10,代码来源:alloc.c


示例3: sdsnewlen

/* Create a new sds string with the content specified by the 'init' pointer
 * and 'initlen'.
 * If NULL is used for 'init' the string is initialized with zero bytes.
 *
 * The string is always null-termined (all the sds strings are, always) so
 * even if you create an sds string with:
 *
 * mystring = sdsnewlen("abc",3);
 *
 * You can print the string with printf() as there is an implicit \0 at the
 * end of the string. However the string is binary safe and can contain
 * \0 characters in the middle, as the length is stored in the sds header. */
sds sdsnewlen(const void *init, size_t initlen) {
    void *sh;
    sds s;
    char type = sdsReqType(initlen);
    /* Empty strings are usually created in order to append. Use type 8
     * since type 5 is not good at this. */
    if (type == SDS_TYPE_5 && initlen == 0) type = SDS_TYPE_8;
    int hdrlen = sdsHdrSize(type);
    unsigned char *fp; /* flags pointer. */

    sh = s_malloc(hdrlen+initlen+1);
    if (!init)
        memset(sh, 0, hdrlen+initlen+1);
    if (sh == NULL) return NULL;
    s = (char*)sh+hdrlen;
    fp = ((unsigned char*)s)-1;
    switch(type) {
        case SDS_TYPE_5: {
            *fp = type | (initlen << SDS_TYPE_BITS);
            break;
        }
        case SDS_TYPE_8: {
            SDS_HDR_VAR(8,s);
            sh->len = initlen;
            sh->alloc = initlen;
            *fp = type;
            break;
        }
        case SDS_TYPE_16: {
            SDS_HDR_VAR(16,s);
            sh->len = initlen;
            sh->alloc = initlen;
            *fp = type;
            break;
        }
        case SDS_TYPE_32: {
            SDS_HDR_VAR(32,s);
            sh->len = initlen;
            sh->alloc = initlen;
            *fp = type;
            break;
        }
        case SDS_TYPE_64: {
            SDS_HDR_VAR(64,s);
            sh->len = initlen;
            sh->alloc = initlen;
            *fp = type;
            break;
        }
    }
    if (initlen && init)
        memcpy(s, init, initlen);
    s[initlen] = '\0';
    return s;
}
开发者ID:Ardnived,项目名称:flarum-chat-server,代码行数:67,代码来源:sds.c


示例4: s_thread_create

s_thread_t * s_thread_create (void * (*f) (void *), void *farg)
{
	s_thread_t *tid;
	s_thread_arg_t *arg;

	if ((s_thread_api == NULL) ||
	    (s_thread_api->thread_create == NULL)) {
		return NULL;
	}

	tid = (s_thread_t *) s_malloc(sizeof(s_thread_t));
	arg = (s_thread_arg_t *) s_malloc(sizeof(s_thread_arg_t));

	arg->r = &s_thread_run;
	arg->f = f;
	arg->arg = farg;
	s_thread_cond_init(&arg->cond);
	s_thread_mutex_init(&arg->mut);

	s_thread_mutex_lock(arg->mut);
	arg->flag = 0;
	s_thread_cond_signal(arg->cond);
	s_thread_mutex_unlock(arg->mut);

	s_thread_api->thread_create(tid, arg);

	s_thread_mutex_lock(arg->mut);
	while (arg->flag != 1) {
		if (s_thread_cond_wait(arg->cond, arg->mut)) {
			debugf(DSYS, "s_thread_cond_wait failed");
			return NULL;
		}
	}
	s_thread_mutex_unlock(arg->mut);

	s_thread_cond_destroy(arg->cond);
	s_thread_mutex_destroy(arg->mut);
	s_free(arg);
	arg = NULL;

	return tid;
}
开发者ID:anarsoul,项目名称:libxynth,代码行数:42,代码来源:thread.c


示例5: s_debug_debugf

void s_debug_debugf (unsigned short flags, char *file, int line, char *func, char *fmt, ...)
{
	int n;
	int s;
	char *p;
	va_list args;

#if !defined(CONFIG_DEBUG)
	if ((flags & DFAT) == 0) {
		return;
	}
#endif
	fprintf(stderr, "[0x%08X] ", s_thread_self());

	if (flags & DFAT) { fprintf(stderr, "FATAL : ");   }
	if (flags & DSYS) { fprintf(stderr, "SYSERR : ");  }
	if (flags & DSER) { fprintf(stderr, "SERVER :: "); }
	if (flags & DCLI) { fprintf(stderr, "CLIENT :: "); }
	
	s = 100;
	if ((p = s_malloc(sizeof(char) * s)) == NULL) {
		goto err;
	}

	while (1) {
		va_start(args, fmt);
		n = vsnprintf(p, s, fmt, args);
		va_end(args);
		if (n > -1 && n < s) {
			break;
		}
		if (n > -1) {
			s = n + 1;
		} else {
			s *= 2;
		}
		if ((p = s_realloc(p, s))  == NULL) {
			goto err;
		}
	}

	fprintf(stderr, p);
	s_free(p);

	if (flags & DSYS) {
		fprintf(stderr, " : %s", strerror(errno));
	}
	fprintf(stderr, " [%s (%s:%d)]\n", func, file, line);
	if (flags & DFAT) {
		goto err;
	}
	return;
err:	exit(1);
}
开发者ID:anarsoul,项目名称:libxynth,代码行数:54,代码来源:debug.c


示例6: s_malloc

char *strdup(const char *str)
  {
  char *new_str;

  if (!str) return NULL;

  new_str = s_malloc(sizeof(char)*(strlen(str)+1));
  strcpy(new_str, str);

  return new_str;
  }
开发者ID:dunghand,项目名称:msrds,代码行数:11,代码来源:compatibility.c


示例7: KMapAddKeyNode

/*
*  Add key + data pair to the linked list of nodes
*/
static KEYNODE *  KMapAddKeyNode(KMAP * km,void * key, int n, void * userdata )
{
    KEYNODE * knode;

    if( n < 0 )
    {
        return 0;
    }

    knode = (KEYNODE*) s_malloc( sizeof(KEYNODE) );

    if( !knode )
    {
        return 0;
    }

    memset(knode, 0, sizeof(KEYNODE) );

    knode->key = (unsigned char*)s_malloc(n); // Alloc the key space
    if( !knode->key )
    {
        free(knode);
        return 0;
    }

    memcpy(knode->key,key,n); // Copy the key
    knode->nkey     = n;
    knode->userdata = userdata;

    if( km->keylist ) // Insert at front of list
    {
        knode->next = km->keylist;
        km->keylist = knode;
    }
    else
    {
        km->keylist = knode;
    }

    return knode;
}
开发者ID:trentmillar,项目名称:snort-vc10,代码行数:44,代码来源:hi_util_kmap.c


示例8: s_config_category_init

int s_config_category_init (s_config_cat_t **cat, char *name)
{
	(*cat) = (s_config_cat_t *) s_malloc(sizeof(s_config_cat_t));
	(*cat)->name = strdup(name);
	if (s_list_init(&((*cat)->variable))) {
		goto err0;
	}
	return 0;
err0:	s_free((*cat)->name);
	s_free(*cat);
	return -1;
}
开发者ID:anarsoul,项目名称:libxynth,代码行数:12,代码来源:config.c


示例9: KMapNew

KMAP * KMapNew( void (*userfree)(void*p) )
{
    KMAP * km = (KMAP*) s_malloc( sizeof(KMAP) );
    
    if( !km ) return 0;
    
    memset(km, 0, sizeof(KMAP));  
    
    km->userfree = userfree;
    
    return km;
}
开发者ID:miettal,项目名称:armadillo420_standard,代码行数:12,代码来源:hi_util_kmap.c


示例10: s_malloc

GROUP_ *newgroup ()
{
    GROUP_
	*tmp;

    tmp = (GROUP_ *) s_malloc (sizeof (GROUP_));
    tmp->members = s_strdup (members);
    tmp->n = 0;
    tmp->value = 0.0;
    tmp->left = tmp->right = NULL;
    return tmp;
}
开发者ID:coltekin,项目名称:Gabmap,代码行数:12,代码来源:agclus.c


示例11: KMapNew

KMAP * KMapNew( KMapUserFreeFunc userfree )
{
    KMAP * km = (KMAP*) s_malloc( sizeof(KMAP) );

    if( !km ) return 0;

    memset(km, 0, sizeof(KMAP));

    km->userfree = userfree;

    return km;
}
开发者ID:trentmillar,项目名称:snort-vc10,代码行数:12,代码来源:hi_util_kmap.c


示例12:

window *window_alloc(sock *Conn)
{
    uint32_t i;
    window *Window = (window *)s_malloc(sizeof(window));
    Window->Frame = (frame **)s_malloc(sizeof(frame **) * Conn->window_size); //&&frame ??

    for (i = 0; i < Conn->window_size; i++)
    {
        Window->Frame[i] = frame_alloc(Conn);
        Window->Frame[i]->state = FRAME_EMPTY;
    }

    Window->size = Conn->window_size;
    Window->top = Conn->seq + Window->size;
    Window->bottom = Conn->seq + 1;
    Window->rr = Window->bottom;
    Window->srej = Window->bottom;
    Window->eof = FALSE;
    Window->buffsize = Conn->buffsize;
    return Window;
}
开发者ID:orionmiller,项目名称:selective_reject,代码行数:21,代码来源:libsrj.c


示例13: s_image_get_buf

int s_image_get_buf (s_surface_t *surface, s_image_t *img)
{
        s_surface_t *s;
        if (img->buf != NULL) {
		s_image_free_buf(img);
	}
	img->buf = (char *) s_malloc(img->w * img->h * surface->bytesperpixel + 1);
	s_surface_create_from_data(&s, img->w, img->h, surface->bitsperpixel, img->buf, 0);
	s_putboxrgb(s, 0, 0, img->w, img->h, img->rgba);
	s_surface_destroy(s);
	return 0;
}
开发者ID:anarsoul,项目名称:libxynth,代码行数:12,代码来源:image.c


示例14: init_pq

PQ_STATUS init_pq(priority_queue_t* ptr,priority_queuq_cmp_ptr cmp,uint size) {
	ptr->priority_queue = (void **)s_malloc(sizeof(void*)*(size+1));
	if(NULL == ptr->priority_queue) { /*分配内存失败*/
		LOG_ERROR("priority_queue malloc failed!%s","");
		return INIT_PQ_FAIL;
	}

	ptr->size = 0;
	ptr->capacity = size + 1;
	ptr->cmp = cmp;
	return INIT_PQ_OK;
}
开发者ID:a1368017681,项目名称:WebServer,代码行数:12,代码来源:priority_queue.c


示例15: lwqq_async_timer_watch

void lwqq_async_timer_watch(LwqqAsyncTimerHandle timer,unsigned int timeout_ms,LwqqAsyncTimerCallback fun,void* data)
{
    double second = (timeout_ms) / 1000.0;
    ev_timer_init(timer,timer_cb_wrap,second,second);
    LwqqAsyncTimerWrap* wrap = s_malloc(sizeof(*wrap));
    wrap->callback = fun;
    wrap->data = data;
    timer->data = wrap;
    ev_timer_start(EV_DEFAULT,timer);
    if(ev_thread_status!=THREAD_NOW_RUNNING)
        start_ev_thread();
}
开发者ID:btbxbob,项目名称:pidgin-lwqq,代码行数:12,代码来源:async.c


示例16: push_front

void push_front(deque* d, void* elem) {
	node* add = (node*) s_malloc(sizeof(node));
	add->data = elem;
	add->next = d->begin->next;
	add->prev = d->begin;								// there's dummy node, so prev must be it!
	if(d->begin->next)
		d->begin->next->prev = add;
	else
		d->end = add;
	d->begin->next = add;
	++d->size;
}
开发者ID:Doruk-Aksoy,项目名称:Lectures,代码行数:12,代码来源:Deque_t.c


示例17: r_readdir

char* r_readdir(r_dir_t *rdir)
{
	size_t len;
	char *filename;
	struct dirent *dentry;
	struct stat fstats;

	if (rdir == NULL || rdir->dir == NULL || rdir->name == NULL)
		return NULL;

	while (true) {
		if (rdir->dir != NULL && (dentry = readdir(rdir->dir)) != NULL) {
			if (STREQ(dentry->d_name, ".") || STREQ(dentry->d_name, ".."))
				continue;

			len = strlen(rdir->name) + strlen(dentry->d_name) + 2;
			filename = (char*) s_malloc(len);
			snprintf(filename, len, "%s%s%s", rdir->name,
			         rdir->name[strlen(rdir->name)-1] == '/' ? "" : "/",
			         dentry->d_name);

			if (stat(filename, &fstats) < 0)
				continue;
			if (S_ISDIR(fstats.st_mode)) {
				/* put subdirectory on the stack */
				if (rdir->stlen == rdir->stcap) {
					rdir->stcap *= 2;
					rdir->stack = (char**) s_realloc(rdir->stack,
					                                 rdir->stcap * sizeof(char*));
				}
				rdir->stack[rdir->stlen++] = filename;
				continue;
			}
			return filename;
		}
		
		if (rdir->stlen > 0) {
			/* open next subdirectory */
			closedir(rdir->dir);
			if (rdir->d != 0)
				free(rdir->name);
			rdir->name = rdir->stack[--rdir->stlen];
			rdir->d = 1;
			if ((rdir->dir = opendir(rdir->name)) == NULL)
				warn("could not open directory: %s", rdir->name);
			continue;
		}
		/* no more entries */
		break;
	}
	return NULL;
}
开发者ID:4z3,项目名称:sxiv,代码行数:52,代码来源:util.c


示例18: ga_chromosome_char_allocate

GAULFUNC boolean ga_chromosome_char_allocate(population *pop, entity *embryo)
  {
  int		i;		/* Loop variable over all chromosomes */

  if (!pop) die("Null pointer to population structure passed.");
  if (!embryo) die("Null pointer to entity structure passed.");

  if (embryo->chromosome!=NULL)
    die("This entity already contains chromosomes.");

  if ( !(embryo->chromosome = s_malloc(pop->num_chromosomes*sizeof(char *))) )
    die("Unable to allocate memory");
  if ( !(embryo->chromosome[0] = s_malloc(pop->num_chromosomes*pop->len_chromosomes*sizeof(char))) )
    die("Unable to allocate memory");

  for (i=1; i<pop->num_chromosomes; i++)
    {
    embryo->chromosome[i] = &(((char *)embryo->chromosome[i-1])[pop->len_chromosomes]);
    }

  return TRUE;
  }
开发者ID:versionzero,项目名称:gaul,代码行数:22,代码来源:ga_chromo.c


示例19: code_get_image

void code_get_image (s_hashtable_t *htable, s_xml_node_t *node, unsigned int *istyle, unsigned int *irotate, unsigned int *icount, char ***ivar)
{
	int i;
	int count;
	char **var;
	char *cntstr;
	s_xml_node_t *tmp;
	FRAME_SHAPE shape;
	FRAME_SHADOW shadow;
	FRAME_IMAGE_ROTATION rotate;
	*istyle = 0;
	*irotate = 0;
	*icount = 0;
	*ivar = NULL;
	count = atoi(s_xml_node_get_path_value(node, "count"));
	if (count == 0) {
		return;
	}
	code_get_enum(htable, s_xml_node_get_path_value(node, "rotate"), &rotate);
	code_get_style(htable, s_xml_node_get_path(node, "style"), &shape, &shadow);
	cntstr = (char *) s_malloc(sizeof(char *) * 255);
	var = (char **) s_malloc(sizeof(char **) * count);
	for (i = 0; i < count; i++) {
		sprintf(cntstr, "image%d", i);
		tmp = s_xml_node_get_path(node, cntstr);
		var[i] = strdup(tmp->value);
		tmp->dontparse = 1;
	}
	if ((tmp = s_xml_node_get_path(node, "style")) != NULL) { tmp->dontparse = 1; }
	if ((tmp = s_xml_node_get_path(node, "style/shape")) != NULL) { tmp->dontparse = 1; }
	if ((tmp = s_xml_node_get_path(node, "style/shadow")) != NULL) { tmp->dontparse = 1; }
	if ((tmp = s_xml_node_get_path(node, "count")) != NULL) { tmp->dontparse = 1; }
	if ((tmp = s_xml_node_get_path(node, "rotate")) != NULL) { tmp->dontparse = 1; }
	s_free(cntstr);
	*istyle = shape | shadow;
	*irotate = rotate;
	*icount = count;
	*ivar = var;
}
开发者ID:jetlive,项目名称:xynth,代码行数:39,代码来源:code.c


示例20: timer_new_slang

int timer_new_slang(void)
  {
  chrono_t	*t=s_malloc(sizeof(chrono_t));
  int		t_handle;

  THREAD_LOCK(chrono_table_lock);
  if (chrono_table==NULL) chrono_table=table_new();

  t_handle = table_add(chrono_table, (vpointer) t);
  THREAD_UNLOCK(chrono_table_lock);

  return (int) t_handle;
  }
开发者ID:aaasz,项目名称:SHP,代码行数:13,代码来源:timer_util.c



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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