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

C++ GC_MALLOC_ATOMIC函数代码示例

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

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



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

示例1: read_file

char* read_file(char* fname){
  FILE* f;
  char* buf = GC_MALLOC_ATOMIC(8192);
  size_t r;
  str_list_t* sl = sl_create();

  f = fopen(fname, "r");
  DFSCH_UNWIND {
    if (!f){
      dfsch_operating_system_error(dfsch_saprintf("Cannot open file %d",
                                                  fname));
    }
    
    while (!feof(f)){
      r = fread(buf, 1, 8192, f);
      if (r != 0){
        sl_nappend(sl, buf, r);
        buf = GC_MALLOC_ATOMIC(8192);
      } else {
        if (ferror(f)){
          dfsch_operating_system_error(dfsch_saprintf("Error reading file %d",
                                                      fname));
        }
      }
    }
    
  } DFSCH_PROTECT {
    fclose(f);
  } DFSCH_PROTECT_END;
  
  return sl_value(sl);
}
开发者ID:adh,项目名称:dfsch,代码行数:32,代码来源:load.c


示例2: dfsch_port_read_whole

dfsch_strbuf_t* dfsch_port_read_whole(dfsch_object_t* port){
  ssize_t ret;
  char* buf = GC_MALLOC_ATOMIC(1024);
  str_list_t* sl = sl_create();
  while ((ret = dfsch_port_read_buf(port, buf, 1024))){
    sl_nappend(sl, buf, ret);
    buf = GC_MALLOC_ATOMIC(1024);
  }
  return sl_value_strbuf(sl);
}
开发者ID:leia,项目名称:dfsch,代码行数:10,代码来源:ports.c


示例3: env_setsymbol

void env_setsymbol(ENV* env, const char* name, NODE* node)
{
	int i, l, sz;
	
	assert(env != NULL);
	assert(name != NULL);
	NODE_CHECK(node);

	l = strlen(name);
	i= env_getindex(env, name);
	if( i>= 0 )
	{
		//redefine the environment value
		NODE* oldnode;
		
		if( env->names[i] != NULL ) GC_FREE(env->names[i]);
		sz = sizeof(char) * (strlen(name)+1);
		env->names[i] = GC_MALLOC_ATOMIC(sz);
		assert(env->names[i] != NULL);
		memcpy(env->names[i], name, sz);
		env->names[i][sz-1] = '\0';
		NODE_CHECK(node);

		oldnode = env->nodes[i];
		env->nodes[i] = node;

		node_free(oldnode);
		node->refcount++;
	}
	else if( env->count < env->size )
	{
		i = env->count;
		env->count = env->count + 1;
		
		sz = sizeof(char) * (strlen(name)+1);
		env->names[i] = GC_MALLOC_ATOMIC(sizeof(char) * (strlen(name)+1));
		assert(env->names[i] != NULL);
		memcpy(env->names[i], name, sz);
		env->names[i][sz-1] = '\0';
		NODE_CHECK(node);
		
		env->nodes[i] = node;
		node->refcount++;
		//char *tmp = node_tostring(node);
		//printf("env_setsymbol: '%s'(%d) = %s\n", name, strlen(name), tmp);
		//GC_FREE(tmp);
	}
	else
	{
		printf("env_setsymbol: buffer overflow.\n");
		exit(1);
	}

	node->refcount++;
}
开发者ID:ahma88,项目名称:magro,代码行数:55,代码来源:env.c


示例4: gcAllocateAtomic

void* gcAllocateAtomic(size_t size) {
    void* m = GC_MALLOC_ATOMIC(size);
    if (!m) {
        // Force GC and try again
        GC_gcollect();
        m = GC_MALLOC_ATOMIC(size);
    }
    if (m) {
        memset(m, 0, size);
    }
    return m;
}
开发者ID:tobium,项目名称:robovm,代码行数:12,代码来源:memory.c


示例5: dfsch_straquote

char* dfsch_straquote(char *s){
  char *b = GC_MALLOC_ATOMIC(strlen(s)*2+3); // worst case, to lazy to optimize
  char *i = b;

  *i='"';
  i++;

  while (*s){
    switch (*s){
    case '"':
      i[0]='\\';
      i[1]='"';
      i+=2;
    default:
      *i = *s;
      ++i;
    }
    s++;
  }

  *i='"';
  i[1]=0;

  return b;

}
开发者ID:leia,项目名称:dfsch,代码行数:26,代码来源:util.c


示例6: dfsch_stracpy

char* dfsch_stracpy(char* x){
  char *b;
  size_t s = strlen(x)+1;
  b = GC_MALLOC_ATOMIC(s);
  strncpy(b,x,s);
  return b;
}
开发者ID:leia,项目名称:dfsch,代码行数:7,代码来源:util.c


示例7: dfsch_strancat

char* dfsch_strancat(char* a, size_t an, char* b, size_t bn){
  char* o = GC_MALLOC_ATOMIC(an + bn + 1);
  memcpy(o, a, an);
  memcpy(o + an, b, bn);
  o[an+bn] = 0;
  return o;
}
开发者ID:leia,项目名称:dfsch,代码行数:7,代码来源:util.c


示例8: dfsch_stracat

char* dfsch_stracat(char* a, char* b){
  size_t s = strlen(a)+strlen(b)+1;
  char* o = GC_MALLOC_ATOMIC(s);
  strncpy(o,a,s);
  strncat(o,b,s);
  return o;
}
开发者ID:leia,项目名称:dfsch,代码行数:7,代码来源:util.c


示例9: CORD_from_fn

CORD CORD_from_fn(CORD_fn fn, void * client_data, size_t len)
{
    if (len <= 0) return(0);
    if (len <= SHORT_LIMIT) {
        register char * result;
        register size_t i;
        char buf[SHORT_LIMIT+1];
        register char c;

        for (i = 0; i < len; i++) {
            c = (*fn)(i, client_data);
            if (c == '\0') goto gen_case;
            buf[i] = c;
        }

        result = GC_MALLOC_ATOMIC(len+1);
        if (result == 0) OUT_OF_MEMORY;
        memcpy(result, buf, len);
        result[len] = '\0';
        return((CORD) result);
    }
  gen_case:
    {
        register struct Function * result;

        result = GC_NEW(struct Function);
        if (result == 0) OUT_OF_MEMORY;
        result->header = FN_HDR;
        /* depth is already 0 */
        result->len = len;
        result->fn = fn;
        result->client_data = client_data;
        return((CORD) result);
    }
}
开发者ID:8l,项目名称:lllm,代码行数:35,代码来源:cordbscs.c


示例10: gcAllocateAtomic

void* gcAllocateAtomic(jint size) {
    void* m = GC_MALLOC_ATOMIC(size);
    if (m) {
        memset(m, 0, size);
    }
    return m;
}
开发者ID:TimurTarasenko,项目名称:robovm,代码行数:7,代码来源:memory.c


示例11: alloc_perm_string

//const char *str_dup( const char *str ) {
// permAlloc default: FALSE
const char *str_dup( const char *str, const bool permAlloc ) {
  if (fBootDb || permAlloc )
    return alloc_perm_string(str); // at boot time, we can safely allocate each string permanently.

  nStrDup++;
  char *str_new;

  if ( str[0] == '\0' ) {
    nStrDupEmpty++;

    return &str_empty[0];
  }

  void* dummy = GC_base((void*)str);

  if ( GC_base((void*)str) != NULL ) { // Since strings in the heap cannot be changed, it is ok just to return the pointer.
    nStrDupGC++;

    return str;
  }
  else {
    nStrDupNoGC++;
    sStrDupNoGC += strlen(str)+1;

    str_new = (char *) GC_MALLOC_ATOMIC( strlen(str) + 1 );
    strcpy( str_new, str );
    return str_new;
  }
}
开发者ID:SinaC,项目名称:OldMud,代码行数:31,代码来源:string_space.C


示例12: mono_gc_alloc_array

void *
mono_gc_alloc_array (MonoVTable *vtable, size_t size, uintptr_t max_length, uintptr_t bounds_size)
{
	MonoArray *obj;

	if (!vtable->klass->has_references) {
		obj = GC_MALLOC_ATOMIC (size);

		obj->obj.vtable = vtable;
		obj->obj.synchronisation = NULL;

		memset ((char *) obj + sizeof (MonoObject), 0, size - sizeof (MonoObject));
	} else if (vtable->gc_descr != GC_NO_DESCRIPTOR) {
		obj = GC_GCJ_MALLOC (size, vtable);
	} else {
		obj = GC_MALLOC (size);

		obj->obj.vtable = vtable;
	}

	obj->max_length = max_length;

	if (bounds_size)
		obj->bounds = (MonoArrayBounds *) ((char *) obj + size - bounds_size);

	if (G_UNLIKELY (alloc_events))
		mono_profiler_allocation (&obj->obj);

	return obj;
}
开发者ID:simudream,项目名称:mono,代码行数:30,代码来源:boehm-gc.c


示例13: decrypt_record

int decrypt_record(char* ibuf, size_t ilen, char**obuf, size_t *olen){
  int i;
  uint8_t keybuf[16];
  uint8_t hmacbuf[32];

  if (ilen < 48){
    return 0;
  }

  calculate_hmac(hmac_key, ibuf, ilen - 32, hmacbuf);
  if (memcmp(hmacbuf, ibuf + ilen - 32, 32) != 0){
    return 0;
  }
  
  *olen = ilen - 48;
  *obuf = GC_MALLOC_ATOMIC((*olen) + 1);

  memcpy(keybuf, ibuf, 16);

  for (i = 0; i < ilen - 48; i++){
    if ((i % 16) == 0){
      aes_encrypt(&aes, keybuf, keybuf);
    }

    (*obuf)[i] = ibuf[i + 16] ^ keybuf[i % 16];
  }
  
  (*obuf)[*olen] = 0;

  return 1;
}
开发者ID:adh,项目名称:pwtool,代码行数:31,代码来源:encryption.c


示例14: memcpy

static CordRep *CORD_from_fn_inner(CORD_fn fn, void * client_data, size_t len)
{
    if (len == 0) return(0);
    if (len <= SHORT_LIMIT) {
        char * result;
        size_t i;
        char buf[SHORT_LIMIT+1];

        for (i = 0; i < len; i++) {
            char c = (*fn)(i, client_data);

            if (c == '\0') goto gen_case;
            buf[i] = c;
        }

        result = (char *)GC_MALLOC_ATOMIC(len + 1);
        if (result == 0) OUT_OF_MEMORY;
        memcpy(result, buf, len);
        result[len] = '\0';
        return (CordRep *)result;
    }
  gen_case:
    {
        struct Function * result = GC_NEW(struct Function);

        if (NULL == result) OUT_OF_MEMORY;
        result->header = FN_HDR;
        /* depth is already 0 */
        result->len = (word)len;
        result->fn = fn;
        GC_PTR_STORE_AND_DIRTY(&result->client_data, client_data);
        return (CordRep *)result;
    }
}
开发者ID:Hamayama,项目名称:Gauche,代码行数:34,代码来源:cordbscs.c


示例15: mono_gc_alloc_obj

void *
mono_gc_alloc_obj (MonoVTable *vtable, size_t size)
{
	MonoObject *obj;

	if (!vtable->klass->has_references) {
		obj = GC_MALLOC_ATOMIC (size);

		obj->vtable = vtable;
		obj->synchronisation = NULL;

		memset ((char *) obj + sizeof (MonoObject), 0, size - sizeof (MonoObject));
	} else if (vtable->gc_descr != GC_NO_DESCRIPTOR) {
		obj = GC_GCJ_MALLOC (size, vtable);
	} else {
		obj = GC_MALLOC (size);

		obj->vtable = vtable;
	}

	if (G_UNLIKELY (alloc_events))
		mono_profiler_allocation (obj);

	return obj;
}
开发者ID:simudream,项目名称:mono,代码行数:25,代码来源:boehm-gc.c


示例16: function_node_toenvstring

char* function_node_toenvstring(FUNCTION_NODE* fnode)
{
	int i, nparam;
	int isbin;
	char* buf, *tmp;
	const char *namestr;

	namestr = function_node_getnamestr(fnode);
	buf = (char*)GC_MALLOC_ATOMIC(sizeof(char*) * 255);
	nparam = fnode->node.parents->count;
    isbin = function_node_isbinary(fnode);
	if( isbin )
	{
		if( nparam > 1 )
		{
			sprintf(buf, "(%s %s %s)", 
				node_toenvstring(fnode->node.parents->items[0]),
				namestr,
				node_toenvstring(fnode->node.parents->items[1])
			);
		}
		else
		{
			sprintf(buf, "%s %s", 
				node_toenvstring(fnode->node.parents->items[0]),
				namestr
			);
		}
	}
	else if( fnode->name == F_MEAN  )
	{
		ARRAY_NODE* array = (ARRAY_NODE*)fnode->node.parents->items[0];
		sprintf(buf, "env_mean(%s, %d)", 
			array_node_toenvstring(array),
			array_node_getsize(array)
		);
		return buf;
	}
	else if( fnode->name == F_ILOGIT  )
	{
		char* tpl = "1.0 / (1.0+exp(-(%s)))";
		char* val = node_toenvstring(fnode->node.parents->items[0]);
		sprintf(buf, tpl, val);
		return buf;
	}
	else
	{
		sprintf(buf, "env_%s(", namestr);
        for( i = 0 ; i < nparam ; i++ )
        {
			tmp = node_toenvstring(fnode->node.parents->items[i]);
            strcat(buf, tmp);
            if( i < nparam-1 )
				strcat(buf, ",");
        }
	}

	return buf;	
}
开发者ID:ahma88,项目名称:magro,代码行数:59,代码来源:function_node.c


示例17: xmalloc_atomic

void* xmalloc_atomic(size_t s) {
    void *ptr = GC_MALLOC_ATOMIC(s);
    if (!ptr) {
        perror("xmalloc_atomic");
        exit(1);
    }
    return ptr;
}
开发者ID:skarb,项目名称:skarb,代码行数:8,代码来源:xalloc.c


示例18: mktree

struct treenode * mktree(int i) {
  struct treenode * r = GC_MALLOC(sizeof(struct treenode));
  if (0 == i) return 0;
  if (1 == i) r = GC_MALLOC_ATOMIC(sizeof(struct treenode));
  r -> x = mktree(i-1);
  r -> y = mktree(i-1);
  return r;
}
开发者ID:IntegerCompany,项目名称:linaro-android-gcc,代码行数:8,代码来源:trace_test.c


示例19: regex_get_error

char* regex_get_error(int errcode, const regex_t *preg){
  size_t len;
  char* buf;
  len = regerror(errcode, preg, NULL, 0);
  buf = GC_MALLOC_ATOMIC(len);
  regerror(errcode, preg, buf, len);
  return buf;
}
开发者ID:adh,项目名称:dfsch,代码行数:8,代码来源:posix-regex.c


示例20: duck_malloc_atomic

value duck_malloc_atomic(size_t n)
{
#ifdef USE_BOEHM
    return GC_MALLOC_ATOMIC(n);
#else
	return malloc(n);
#endif
}
开发者ID:cpehle,项目名称:duck,代码行数:8,代码来源:runtime.c



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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