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


C++ check_mem函数代码示例

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


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

示例1: malloc

Stats *Stats_recreate(double sum,
                      double sumsq,
                      unsigned long n,
                      double min,
                      double max
                     )
{
  Stats *st = malloc(sizeof(Stats));
  check_mem(st);

  st->sum = sum;
  st->sumsq = sumsq;
  st->n = n;
  st->min = min;
  st->max = max;

  return st;

error:
  return NULL;
}
开发者ID:shterrett,项目名称:learn-c-the-hard-way,代码行数:21,代码来源:stats.c

示例2: test_check

int test_check(char *file_name)
{
  FILE *input = NULL;
  char *block = NULL;

  block = malloc(100);
  check_mem(block);

  input = fopen(file_name, "r");
  check(input, "Failed to open %s", file_name);

  free(block);
  fclose(input);

  return 0;

error:
  if(block) free(block);
  if(input) fclose(input);
  return -1;
}
开发者ID:toastynerd,项目名称:LCTHW,代码行数:21,代码来源:ex20.c

示例3: test_sentinel

int test_sentinel(int code)
{
  char *temp = malloc(100);
  check_mem(temp);

  switch(code)
  {
    case 1:
      log_info("it worked");
      break;
    default:
      sentinel("I shouldn't run");
  }

  free(temp);
  return 0;

error:
  if(temp) free(temp);
  return -1;
}
开发者ID:toastynerd,项目名称:LCTHW,代码行数:21,代码来源:ex20.c

示例4: Renderer_createTexture

int  Renderer_createTexture( const char *pTFile, bool pMipmaps ) {
    Texture *t = NULL;

    if( renderer && TextureArray_checkSize( &renderer->mTextures ) ) {
        t = Texture_new();
        check_mem( t );

        // texture creation from file
        check( Texture_loadFromFile( t, pTFile, pMipmaps ), "Error in texture creation.\n" );

        // storage
        int index = renderer->mTextures.cpt++;
        renderer->mTextures.data[index] = t;

        return index;
    }

error:
    Texture_destroy( t );
    return -1;
}
开发者ID:Adrian-Revk,项目名称:Byte,代码行数:21,代码来源:renderer.c

示例5: Filter_add

int Filter_add(StateEvent state, filter_cb cb, bstring load_path, tns_value_t *config)
{
    darray_t *filters = Filter_lookup_create(state);
    check(filters != NULL, "Invalid filter state: %d given for filter %s",
            state, bdata(load_path));

    Filter *filter = darray_new(filters);
    check_mem(filter);

    filter->state = state;
    filter->cb = cb;
    filter->load_path = bstrcpy(load_path);
    filter->config = config;

    darray_attach(filters, filter);
    darray_push(filters, filter);

    return 0;
error:
    return -1;
}
开发者ID:304471720,项目名称:mongrel2,代码行数:21,代码来源:filter.c

示例6: List_unshift

void List_unshift(List *list, void *value)
{
    ListNode *node = calloc(1, sizeof(ListNode));
    check_mem(node);

    node->value = value;

    if(list->first == NULL) {
        list->first = node;
        list->last = node;
    } else {
        node->next = list->first;
        list->first->prev = node;
        list->first = node;
    }

    list->count++;

error:
    return;
}
开发者ID:shackijj,项目名称:lcthw,代码行数:21,代码来源:list.c

示例7: Renderer_createShader

int  Renderer_createShader( const char *pVFile, const char *pFFile ) {
    Shader *s = NULL;

    if( renderer && ShaderArray_checkSize( &renderer->mShaders ) ) {
        s = Shader_new();
        check_mem( s );

        // shader creation and linking
        check( Shader_buildFromFile( s, pVFile, pFFile ), "Error in shader creation.\n" );

        // storage
        int index = renderer->mShaders.cpt++;
        renderer->mShaders.data[index] = s;

        return index;
    }

error:
    Shader_destroy( s );
    return -1;
}
开发者ID:Adrian-Revk,项目名称:Byte,代码行数:21,代码来源:renderer.c

示例8: cpu_count

CpuTimes *cpu_times_percent(bool percpu, CpuTimes *prev_times) {
  CpuTimes *current = NULL;
  CpuTimes *t;
  int i, ncpus = percpu ? cpu_count(1) : 1;
  CpuTimes *ret;
  check(prev_times, "Need a reference point. prev_times can't be NULL");
  current = cpu_times(percpu);
  check(current, "Couldn't obtain CPU times");
  ret = (CpuTimes *)calloc(ncpus, sizeof(CpuTimes));
  check_mem(ret);
  for (i = 0; i < ncpus; i++) {
    t = calculate_cpu_times_percentage(prev_times + i, current + i);
    *(ret + i) = *t;
    free(t);
  }
  free(current);
  return ret;
error:
  free(current);
  return NULL;
}
开发者ID:nibrahim,项目名称:cpslib,代码行数:21,代码来源:pslib_linux.c

示例9: http_receive_payload

int http_receive_payload(int sockfd, char **payload, int content_length) {
    *payload = NULL;
    ssize_t recv_size = 0;
    *payload = (char *)calloc(sizeof(char), content_length + 1);
    check_mem(payload);

    recv_size = read_all(sockfd, *payload, content_length);
    debug("%s", *payload);

    if (recv_size == content_length) {
        debug("Read complete Http payload.");
    } else if (recv_size == 0) {
        log_err("End of TCP stream.");
            return ERR_EOF;
    } else {
        log_err("Error while reading TCP stream.");
         // TODO handle
        exit(-1);
    }
    return HTTP_SUCCESS;
}
开发者ID:hyrise,项目名称:dispatcher,代码行数:21,代码来源:http.c

示例10: qip_ast_freturn_copy

// Copies a node and its children.
//
// node - The node to copy.
// ret  - A pointer to where the new copy should be returned to.
//
// Returns 0 if successful, otherwise returns -1.
int qip_ast_freturn_copy(qip_ast_node *node, qip_ast_node **ret)
{
    int rc;
    check(node != NULL, "Node required");
    check(ret != NULL, "Return pointer required");

    qip_ast_node *clone = qip_ast_freturn_create(NULL);
    check_mem(clone);

    rc = qip_ast_node_copy(node->freturn.value, &clone->freturn.value);
    check(rc == 0, "Unable to copy return value");
    if(clone->freturn.value) clone->freturn.value->parent = clone;
    
    *ret = clone;
    return 0;

error:
    qip_ast_node_free(clone);
    *ret = NULL;
    return -1;
}
开发者ID:dasfaha,项目名称:sky,代码行数:27,代码来源:freturn.c

示例11: test_check

int test_check(char *file_name)
{
    FILE *input = NULL;
    char *block = NULL;

    block = malloc(100);
    check_mem(block); // should work

    input = fopen(file_name, "r");
    check(input, "Failed to open %s", file_name);

    free(block);
    fclose(input);
    return 0;

error:
    printf("[goto error] at test_check\n");
    if(block) free(block);
    if(input) fclose(input);
    return -1;
}
开发者ID:QingyunLiu,项目名称:my-nodejs-learn,代码行数:21,代码来源:ex20.c

示例12: check

static inline DArray *Hashmap_find_bucket(Hashmap *map, void *key, int create, uint32_t *hash_out)
{//caller fn will include 1 or 0 for int create true or false
    uint32_t hash = map->hash(key);
    int bucket_n = hash % DEFAULT_NUMBER_OF_BUCKETS;//finds bucket, will always find a bucket no matter how big
    check(bucket_n >= 0, "Invalid bucket found: %d", bucket_n);
    *hash_out = hash; //store it for the return so caller can use it. I forget how caller is supposed to use this

    DArray *bucket = DArray_get(map->buckets, bucket_n);

    if(!bucket && create) {//creates bucket if none found
        //new bucket, set it up
        bucket = DArray_create(sizeof(void *), DEFAULT_NUMBER_OF_BUCKETS);
        check_mem(bucket);
        DArray_set(map->buckets, bucket_n, bucket);
    }

    return bucket;

error:
    return NULL;
}
开发者ID:BMJHayward,项目名称:liblcthw,代码行数:21,代码来源:hashmap.c

示例13: create_node

Node_T create_node(Node_T father, SuffixTreeIndex_T start, SuffixTreeIndex_T end,
                   SuffixTreeIndex_T position)
{
   /*Allocate a node.*/
   Node_T node   = malloc(sizeof(struct Node_T));
   check_mem(node);

   node->left_son             = NULL;
   node->right_sibling        = NULL;
   node->left_sibling         = NULL;
   node->suffix_link          = NULL;
   node->father               = father;
   node->path_position        = position;
   node->edge_label_start     = start;
   node->edge_label_end       = end;
   return node;

error:
   if(node) free(node);
   return NULL;
}
开发者ID:mckinsel,项目名称:libpalindrome,代码行数:21,代码来源:suffix_tree.c

示例14: qip_ast_block_add_expr

// Appends an expression to the end of the block.
//
// block - The block to append the expression to.
// expr  - The expression to append.
//
// Returns 0 if successful, otherwise returns -1.
int qip_ast_block_add_expr(struct qip_ast_node *block, struct qip_ast_node *expr)
{
    // Validate.
    check(block != NULL, "Block is required");
    check(block->type == QIP_AST_TYPE_BLOCK, "Block node is invalid type: %d", block->type);
    check(expr != NULL, "Expression is required");
    
    // Append expression to block.
    block->block.expr_count++;
    block->block.exprs = realloc(block->block.exprs, sizeof(qip_ast_node*) * block->block.expr_count);
    check_mem(block->block.exprs);
    block->block.exprs[block->block.expr_count-1] = expr;
    
    // Assign parent reference to expression.
    expr->parent = block;
    
    return 0;

error:
    return -1;
}
开发者ID:dasfaha,项目名称:sky,代码行数:27,代码来源:block.c

示例15: lapack_dsteqr

void lapack_dsteqr(int nn, int ldz, dreal *alph, dreal *beta, dreal *zz)
{
  int   nwork, info;
  char  compz = 'I';
  dreal *work = NULL;
  
  nwork = (1 >= 2*nn-2) ? 1 : 2*nn-2;
  
  work = (dreal *) calloc(nwork, sizeof(dreal));
  check_mem(work, "work");
  
  dsteqr_(&compz, &nn, alph, beta, zz, &ldz, work, &info);
  
  freeup(work);
  
  return;
  
 error:
  if(work) freeup(work);
  abort();
}
开发者ID:yigao1983,项目名称:TDDMRG,代码行数:21,代码来源:lapack.c


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