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


C++ GC_malloc函数代码示例

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


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

示例1: ParamPaths_init

void ParamPaths_init(void) {
  register int i0, i1;
  _mid = _register_module(&ParamPaths_md.md, &ParamPaths__NewFilesDesc_td.td);
  {
    char *_mem, *_var;
    _mem = GC_malloc(_not_zero(20)+8);
    if (!_mem) _new_failed(_P(18198));
    _var = _mem+8;
    ((_Type*)_var)[-1] = &ParamPaths__PathsSectionDesc_td.td;
    i0 = (int)_var;
  }
  ParamPaths__paths = (void*)i0;
  i1 = (int)ParamPaths__paths;
  i0 = i1 + 16;
  *(unsigned char*)i0 = 0;
  i1 = (int)ParamPaths__paths;
  i0 = i1 + 12;
  *(void**)i0 = (void*)0;
  {
    char *_mem, *_var;
    _mem = GC_malloc(_not_zero(20)+8);
    if (!_mem) _new_failed(_P(18272));
    _var = _mem+8;
    ((_Type*)_var)[-1] = &ParamPaths__NewFilesDesc_td.td;
    i0 = (int)_var;
  }
  ParamPaths__newFiles = (void*)i0;
  i0 = (int)ParamPaths__paths;
  i1 = i0 + 16;
  *(unsigned char*)i1 = 0;
  i0 = (int)ParamPaths__newFiles;
  i1 = i0 + 12;
  *(void**)i1 = (void*)0;
}
开发者ID:Classic-Tools,项目名称:ooc-gsa,代码行数:34,代码来源:ParamPaths.c

示例2: lstrvec_alloc

lstrvec* 
lstrvec_alloc(int size)
{
    lstrvec* vec = GC_malloc(sizeof(lstrvec));
    vec->size = size;
    if (size != 0)
        vec->xs   = GC_malloc(size * sizeof(char*));
    return vec;
}
开发者ID:NatTuck,项目名称:pocl-0.7x,代码行数:9,代码来源:lstring.c

示例3: regmatch_sub_anytime

static int
regmatch_sub_anytime(struct MatchingContext2 *c, Regex *regex,
		     regexchar * pat2,
		     char *str, char *end_p, int iter_limit, int firstp)
{
    switch (c->label) {
    case 1:
	goto label1;
    case 2:
	goto label2;
    case 3:
	goto label3;
    }
    c->ctx = GC_malloc(sizeof(struct MatchingContext1));
    c->ctx2 = GC_malloc(sizeof(struct MatchingContext2));
    c->ctx->label = 0;
    c->regex = regex;
    c->n_any = 0;
    c->str = str;
    c->firstp = firstp;
    for (;;) {
	c->ctx->label = 0;
	while (regmatch_iter(c->ctx, c->regex->re, c->str, end_p, c->firstp)) {
	    c->n_any = c->ctx->lastpos - c->str;
	    if (c->n_any <= 0)
		continue;
	    c->firstp = 0;
	    if (RE_MODE(pat2) == RE_ENDMARK) {
		c->lastpos = c->str + c->n_any;
		YIELD(1, c, 1);
	    }
	    else if (regmatch(pat2, c->str + c->n_any, end_p,
			      c->firstp, &c->lastpos) == 1) {
		YIELD(1, c, 2);
	    }
	    if (iter_limit == 1)
		continue;
	    c->ctx2->label = 0;
	    while (regmatch_sub_anytime(c->ctx2, regex, pat2,
					c->str + c->n_any, end_p,
					iter_limit - 1, c->firstp)) {

		c->lastpos = c->ctx2->lastpos;
		YIELD(1, c, 3);
	    }
	}
	if (c->regex->alt_regex == NULL)
	    break;
	c->regex = c->regex->alt_regex;
    }
    return 0;
}
开发者ID:fiery-,项目名称:w3m,代码行数:52,代码来源:regex.c

示例4: alloc_tree_node

TreeNode*
alloc_tree_node(int type)
{
    TreeNode* tn = GC_malloc(sizeof(TreeNode));
    tn->type = type;
    return tn;
}
开发者ID:NatTuck,项目名称:snow-proto,代码行数:7,代码来源:ast.c

示例5: strlen

/*
 * GC strdup()
 */
extern char *GC_strdup(const char *str)
{
    size_t len = strlen(str);
    char *copy = (char *)GC_malloc(len+1);
    strcpy(copy, str);
    return copy;
}
开发者ID:GJDuck,项目名称:SMCHR,代码行数:10,代码来源:gc.c

示例6: nearest_power

static struct stack_block *mem_block_alloc(size_t min_size)
{
	struct stack_block *block;
	size_t prev_size, alloc_size;

	prev_size = current_block == NULL ? 0 : current_block->size;
	alloc_size = nearest_power(prev_size + min_size);

#ifndef USE_GC
	block = malloc(SIZEOF_MEMBLOCK + alloc_size);
#else
	block = GC_malloc(SIZEOF_MEMBLOCK + alloc_size);
#endif
	if (unlikely(block == NULL)) {
		if (outofmem) {
			if (min_size > outofmem_area.block.left)
				abort();
			return &outofmem_area.block;
		}
		outofmem = TRUE;
		i_panic("data stack: Out of memory when allocating %"
			PRIuSIZE_T" bytes", alloc_size + SIZEOF_MEMBLOCK);
	}
	block->size = alloc_size;
	block->left = 0;
	block->lowwater = block->size;
	block->next = NULL;

#ifdef DEBUG
	memset(STACK_BLOCK_DATA(block), CLEAR_CHR, alloc_size);
#endif
	return block;
}
开发者ID:Distrotech,项目名称:dovecot,代码行数:33,代码来源:data-stack.c

示例7: i_panic

static void *pool_system_malloc(pool_t pool ATTR_UNUSED, size_t size)
{
	void *mem;
#ifdef DEBUG
	int old_errno = errno;
#endif

	if (unlikely(size == 0 || size > SSIZE_T_MAX))
		i_panic("Trying to allocate %"PRIuSIZE_T" bytes", size);

#ifndef USE_GC
	mem = calloc(size, 1);
#else
	mem = GC_malloc(size);
#endif
	if (unlikely(mem == NULL)) {
		i_fatal_status(FATAL_OUTOFMEM, "pool_system_malloc(%"PRIuSIZE_T
			       "): Out of memory", size);
	}
#ifdef DEBUG
	/* we rely on errno not changing. it shouldn't. */
	i_assert(errno == old_errno);
#endif
	return mem;
}
开发者ID:manuelm,项目名称:dovecot,代码行数:25,代码来源:mempool-system.c

示例8: alloc_value

static value_t*
alloc_value (ptable_t *ptable, size_t size)
{
	value_t *v = GC_malloc (size);
	v->ptable = ptable;
	return v;
}
开发者ID:Victorlee1988,项目名称:clojurec,代码行数:7,代码来源:preamble.c

示例9: ParamPaths__ParsePatterns_PathList_NewPath

ParamPaths__Path ParamPaths__ParsePatterns_PathList_NewPath(unsigned char* str, int str_0d) {
  register int i0, i1, i2;
  {
    char *_mem, *_var;
    _mem = GC_malloc(_not_zero(8)+8);
    if (!_mem) _new_failed(_P(6224));
    _var = _mem+8;
    ((_Type*)_var)[-1] = &ParamPaths__PathDesc_td.td;
    i0 = (int)_var;
  }
  i2 = Strings__Length((const unsigned char*)(int)str, str_0d);
  i1 = i0 + 4;
  i2++;
  {
    char *_mem, *_var;
    int* _dim_ptr;
    if(i2 < 0) _invalid_length(i2, _P(6281));
    _mem = GC_malloc_atomic(_not_zero(i2*1)+8);
    if (!_mem) _new_failed(_P(6244));
    _var = _mem+8;
    _dim_ptr = (void*)(_var-4);
    *(--_dim_ptr) = i2;
    i2 = (int)_var;
  }
  *(void**)i1 = (void*)i2;
  i1 = (int)*(void**)i1;
  i2 = *(int*)(i1-8);
  _string_copy(i1, (int)str, i2);
  *(void**)i0 = (void*)0;
  return (void*)i0;
}
开发者ID:Classic-Tools,项目名称:ooc-gsa,代码行数:31,代码来源:ParamPaths.c

示例10: switch

scm *run_lisp(struct sexp a_sexp) {
  switch (a_sexp.type) {
  case LIST:;
    // Get the first element (which should be a symbol representing a function) and evaluate it
    scm *callee = run_lisp(a_sexp.list[0]);
    assert(callee->type == SCM_FN);
    
    scm *args = NULL;
    struct sexp *remaining = a_sexp.list + 1;

    while (remaining->type != END_OF_LIST) {
      args = append(args, run_lisp(*remaining));
      remaining++;
    }
    
    return callee->fn(args);
  case SYMBOL:;
    char *name = a_sexp.symbol;
    if (strcmp(name, "+") == 0) {
      return &_plus_scm;
    }
    assert(0 && "Stuff ain't implemented yet!");
    break;
  case INTEGER:;
    scm *val = GC_malloc(sizeof(scm));
    val->type = SCM_INT;
    val->integer = a_sexp.integer;

    return val;
  default:
    assert(0 && "Whoops...");
  }
}
开发者ID:mystor,项目名称:simple-lisp-parser-in-c,代码行数:33,代码来源:runtime.c

示例11: ss_malloc

ss_INLINE
void* ss_malloc(size_t s)
{
  ss_malloc_bytes += s;
  ss_malloc_objects ++;
  return GC_malloc(s);
}
开发者ID:kstephens,项目名称:ss,代码行数:7,代码来源:memory.c

示例12: sizeof

void *api_call_method(int numargs, void *obj, void *initptr, va_list vl)
{
    ffi_cif cif;
    ffi_type *args[numargs + 1];
    void *values[numargs + 1];
    void **val_heap = (void**)GC_malloc((numargs + 1) * sizeof(void*)); /*new void*[numargs + 1];*/
    void *rv;
    args[0] = &ffi_type_pointer;
    values[0] = &val_heap[0];
    for (int i = 0; i < numargs; i++)
    {
        args[i + 1] = &ffi_type_pointer;
        values[i + 1] = (void*)&val_heap[i + 1];
    }
    int rc = ffi_prep_cif(&cif, FFI_DEFAULT_ABI, numargs + 1, &ffi_type_pointer, args);
    assert(rc == FFI_OK);
    val_heap[0] = (void*)obj;
    for (int i = 0; i < numargs; i++)
    {
        val_heap[i + 1] = va_arg(vl, void*);
    }
    ffi_call(&cif, (void(*)())initptr, &rv, values);
    va_end(vl);
    GC_free(val_heap);
    /*delete[] val_heap;*/
    return rv;
}
开发者ID:tmiw,项目名称:kite-llvm,代码行数:27,代码来源:api.cpp

示例13: START_TEST

END_TEST


START_TEST(test_message_send) {
  message * msg;
  int * sock = GC_malloc(sizeof(int) * 2);
  socketpair(AF_UNIX, SOCK_STREAM, 0, sock);
  msg = message_create_echo(MESSAGE_TYPE_REQUEST, "hey");
  message_send(sock[0], msg);
  char * header_buf = GC_malloc(8);
  char * data = GC_malloc(7);
  ck_assert_int_eq(recv(sock[1], header_buf, 8, MSG_DONTWAIT), 8);
  ck_assert_int_eq(memcmp(header_buf, "\x00\x00\x00\x07\xfb\x65\x78\xa3", 8), 0);
  ck_assert_int_eq(recv(sock[1], data, 7, MSG_DONTWAIT), 7);
  ck_assert_int_eq(memcmp(data, "\x93\x00\x01\xa3hey", 7), 0);
}
开发者ID:NightBlues,项目名称:cbot,代码行数:16,代码来源:check_messaging.c

示例14: merge_caps

sinfo_t __init_new_thread_stack
   (caps_t c, int len,void *(*f)(void *) , 
    void *targ,int arg_len) {
  len = merge_caps(c,len); // sum caps
 // it should be at least 16 or we'll be
  ssinfo_t ss = __get_stack_size(len,arg_len,stack_space);
  sinfo_t i = (sinfo_t) GC_malloc(ss.real_size);
  i->tid = _next_tid();
  i->thread = f;
  i->info = ss;
  i->h = create_hashtable(25);
  
//  fprintf(stderr,"\nthread_malloc: %p", i);

  memcpy(i+1,targ,arg_len);
  struct _XTreeHandle *r = (struct _XTreeHandle *)
                        (((char *)(i+1)) + arg_len);
  // fill-in the new tree and transfer capabilities
  __treecopy(c,r,len,i->tid,&i->h);

  // set stack guard page so as to handle, page faults.
  // Here we simply quit.
//  char *guard = (char *) ALIGN_PG(((char *) i) + ss.end_offset);

//  if(mprotect(guard,1024,1))
//    errquit("__init_new_thread: mprotect failed");
 
   //i->info.end_offset = (unsigned long long)guard -
 // 	 							   (unsigned long long)i;
  //assert(i->info.end_offset+1024 <= i->info.real_size);
  return i;
}
开发者ID:pgerakios,项目名称:Concurrent-Cyclone-with-inference,代码行数:32,代码来源:runtime_stack.c

示例15: GC_local_malloc

GC_PTR GC_local_malloc(size_t bytes)
{
    if (EXPECT(!SMALL_ENOUGH(bytes),0)) {
        return(GC_malloc(bytes));
    } else {
	int index = INDEX_FROM_BYTES(bytes);
	ptr_t * my_fl;
	ptr_t my_entry;
#	if defined(REDIRECT_MALLOC) && !defined(USE_PTHREAD_SPECIFIC)
	GC_key_t k = GC_thread_key;
#	endif
	void * tsd;

#	if defined(REDIRECT_MALLOC) && !defined(USE_PTHREAD_SPECIFIC)
	    if (EXPECT(0 == k, 0)) {
		/* This can happen if we get called when the world is	*/
		/* being initialized.  Whether we can actually complete	*/
		/* the initialization then is unclear.			*/
		GC_init_parallel();
		k = GC_thread_key;
	    }
#	endif
	tsd = GC_getspecific(GC_thread_key);
#	ifdef GC_ASSERTIONS
	  LOCK();
	  GC_ASSERT(tsd == (void *)GC_lookup_thread(pthread_self()));
	  UNLOCK();
#	endif
	my_fl = ((GC_thread)tsd) -> normal_freelists + index;
	my_entry = *my_fl;
	if (EXPECT((word)my_entry >= HBLKSIZE, 1)) {
	    ptr_t next = obj_link(my_entry);
	    GC_PTR result = (GC_PTR)my_entry;
	    *my_fl = next;
	    obj_link(my_entry) = 0;
	    PREFETCH_FOR_WRITE(next);
	    return result;
	} else if ((word)my_entry - 1 < DIRECT_GRANULES) {
	    *my_fl = my_entry + index + 1;
            return GC_malloc(bytes);
	} else {
	    GC_generic_malloc_many(BYTES_FROM_INDEX(index), NORMAL, my_fl);
	    if (*my_fl == 0) return GC_oom_fn(bytes);
	    return GC_local_malloc(bytes);
	}
    }
}
开发者ID:fenghaitao,项目名称:Harpoon,代码行数:47,代码来源:pthread_support.c


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