您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ CALLOCATE函数代码示例

51自学网 2021-06-01 19:56:32
  C++
这篇教程C++ CALLOCATE函数代码示例写得很实用,希望能帮到您。

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

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

示例1: S_ormatcher_init2

static ORMatcher*S_ormatcher_init2(ORMatcher *self, ORMatcherIVARS *ivars, Vector *children,                  Similarity *sim) {    // Init.    PolyMatcher_init((PolyMatcher*)self, children, sim);    ivars->size = 0;    // Derive.    ivars->max_size = (uint32_t)Vec_Get_Size(children);    // Allocate.    ivars->heap = (HeapedMatcherDoc**)CALLOCATE(ivars->max_size + 1, sizeof(HeapedMatcherDoc*));    // Create a pool of HMDs.  Encourage CPU cache hits by using a single    // allocation for all of them.    size_t amount_to_malloc = (ivars->max_size + 1) * sizeof(HeapedMatcherDoc);    ivars->blob = (char*)MALLOCATE(amount_to_malloc);    ivars->pool = (HeapedMatcherDoc**)CALLOCATE(ivars->max_size + 1, sizeof(HeapedMatcherDoc*));    for (uint32_t i = 1; i <= ivars->max_size; i++) {        size_t offset = i * sizeof(HeapedMatcherDoc);        HeapedMatcherDoc *hmd = (HeapedMatcherDoc*)(ivars->blob + offset);        ivars->pool[i] = hmd;    }    // Prime queue.    for (uint32_t i = 0; i < ivars->max_size; i++) {        Matcher *matcher = (Matcher*)Vec_Fetch(children, i);        if (matcher) {            S_add_element(self, ivars, (Matcher*)INCREF(matcher), 0);        }    }    return self;}
开发者ID:apache,项目名称:lucy,代码行数:34,


示例2: S_parse_arguments

/* Parse command line arguments. */static voidS_parse_arguments(int argc, char **argv, CFCArgs *args) {    int i;    memset(args, 0, sizeof(CFCArgs));    args->source_dirs  = (char**)CALLOCATE(1, sizeof(char*));    args->include_dirs = (char**)CALLOCATE(1, sizeof(char*));    args->parcels      = (char**)CALLOCATE(1, sizeof(char*));    for (i = 1; i < argc; i++) {        char *arg = argv[i];        if (S_parse_string_argument(arg, "--dest", &args->dest)) {            continue;        }        if (S_parse_string_argument(arg, "--header", &args->header_filename)) {            continue;        }        if (S_parse_string_argument(arg, "--footer", &args->footer_filename)) {            continue;        }        if (S_parse_string_array_argument(arg, "--source",                                          &args->num_source_dirs,                                          &args->source_dirs)           ) {            continue;        }        if (S_parse_string_array_argument(arg, "--include",                                          &args->num_include_dirs,                                          &args->include_dirs)           ) {            continue;        }        if (S_parse_string_array_argument(arg, "--parcel",                                          &args->num_parcels,                                          &args->parcels)           ) {            continue;        }        fprintf(stderr, "Invalid argument '%s'/n", arg);        exit(EXIT_FAILURE);    }    if (!args->dest) {        fprintf(stderr, "Mandatory argument --dest missing/n");        exit(EXIT_FAILURE);    }}
开发者ID:leckie711,项目名称:lucy-clownfish,代码行数:50,


示例3: test_bigend_f32

static voidtest_bigend_f32(TestBatchRunner *runner) {    float    source[]  = { -1.3f, 0.0f, 100.2f };    size_t   count     = 3;    size_t   amount    = (count + 1) * sizeof(float);    uint8_t *allocated = (uint8_t*)CALLOCATE(amount, sizeof(uint8_t));    uint8_t *encoded   = allocated + 1; // Intentionally misaligned.    uint8_t *target    = encoded;    for (size_t i = 0; i < count; i++) {        NumUtil_encode_bigend_f32(source[i], &target);        target += sizeof(float);    }    target = encoded;    for (size_t i = 0; i < count; i++) {        float got = NumUtil_decode_bigend_f32(target);        TEST_TRUE(runner, got == source[i], "bigend f32");        target += sizeof(float);    }    target = encoded;    NumUtil_encode_bigend_f32(-2.0f, &target);    TEST_INT_EQ(runner, (encoded[0] & 0x80), 0x80,                "Truly big-endian (IEEE 754 sign bit set for negative number)");    TEST_INT_EQ(runner, encoded[0], 0xC0,                "IEEE 754 representation of -2.0f, byte 0");    for (size_t i = 1; i < sizeof(float); i++) {        TEST_INT_EQ(runner, encoded[i], 0,                    "IEEE 754 representation of -2.0f, byte %d", (int)i);    }    FREEMEM(allocated);}
开发者ID:theory,项目名称:lucy,代码行数:33,


示例4: test_bigend_u32

static voidtest_bigend_u32(TestBatchRunner *runner) {    size_t    count     = 32;    uint64_t *ints      = TestUtils_random_u64s(NULL, count, 0, UINT64_C(1) + UINT32_MAX);    size_t    amount    = (count + 1) * sizeof(uint32_t);    char     *allocated = (char*)CALLOCATE(amount, sizeof(char));    char     *encoded   = allocated + 1; // Intentionally misaligned.    char     *target    = encoded;    for (size_t i = 0; i < count; i++) {        NumUtil_encode_bigend_u32((uint32_t)ints[i], &target);        target += sizeof(uint32_t);    }    target = encoded;    for (size_t i = 0; i < count; i++) {        uint32_t got = NumUtil_decode_bigend_u32(target);        TEST_INT_EQ(runner, got, (long)ints[i], "bigend u32");        target += sizeof(uint32_t);    }    target = encoded;    NumUtil_encode_bigend_u32(1, &target);    TEST_INT_EQ(runner, encoded[0], 0, "Truly big-endian u32");    TEST_INT_EQ(runner, encoded[3], 1, "Truly big-endian u32");    FREEMEM(allocated);    FREEMEM(ints);}
开发者ID:theory,项目名称:lucy,代码行数:28,


示例5: Hash_init

Hash*Hash_init(Hash *self, uint32_t capacity) {    // Allocate enough space to hold the requested number of elements without    // triggering a rebuild.    uint32_t requested_capacity = capacity < I32_MAX ? capacity : I32_MAX;    uint32_t threshold;    capacity = 16;    while (1) {        threshold = (capacity / 3) * 2;        if (threshold > requested_capacity) {            break;        }        capacity *= 2;    }    // Init.    self->size         = 0;    self->iter_tick    = -1;    // Derive.    self->capacity     = capacity;    self->entries      = (HashEntry*)CALLOCATE(capacity, sizeof(HashEntry));    self->threshold    = threshold;    return self;}
开发者ID:pavansondur,项目名称:lucy,代码行数:26,


示例6: test_bigend_u64

static voidtest_bigend_u64(TestBatch *batch) {    size_t    count     = 32;    uint64_t *ints      = TestUtils_random_u64s(NULL, count, 0, U64_MAX);    size_t    amount    = (count + 1) * sizeof(uint64_t);    char     *allocated = (char*)CALLOCATE(amount, sizeof(char));    char     *encoded   = allocated + 1; // Intentionally misaligned.    char     *target    = encoded;    for (size_t i = 0; i < count; i++) {        NumUtil_encode_bigend_u64(ints[i], &target);        target += sizeof(uint64_t);    }    target = encoded;    for (size_t i = 0; i < count; i++) {        uint64_t got = NumUtil_decode_bigend_u64(target);        TEST_TRUE(batch, got == ints[i], "bigend u64");        target += sizeof(uint64_t);    }    target = encoded;    NumUtil_encode_bigend_u64(1, &target);    TEST_INT_EQ(batch, encoded[0], 0, "Truly big-endian");    TEST_INT_EQ(batch, encoded[7], 1, "Truly big-endian");    FREEMEM(allocated);    FREEMEM(ints);}
开发者ID:pavansondur,项目名称:lucy,代码行数:28,


示例7: create_db_conn

int create_db_conn (void){	int i;	/* allocate more slots if we need them */	if (dbConnAlloc == dbConnUsed) {		i = dbConnAlloc;		dbConnAlloc += 10;		if (!dbConnList) {			dbConnList = CALLOCATE(dbConnAlloc, db_t, TAG_DB, "create_db_conn");		} else {			pthread_mutex_lock(db_mut);			dbConnList = RESIZE(dbConnList, dbConnAlloc, db_t, TAG_DB, "create_db_conn");			pthread_mutex_unlock(db_mut);		}		while (i < dbConnAlloc) {			dbConnList[i++].flags = DB_FLAG_EMPTY;		}	}	for (i = 0;  i < dbConnAlloc;  i++) {		if (dbConnList[i].flags & DB_FLAG_EMPTY) {			dbConnList[i].flags = 0;			dbConnList[i].type = &no_db;			dbConnUsed++;			return i + 1;		}	}	fatal("dbConnAlloc != dbConnUsed, but no empty slots");}
开发者ID:BPotato,项目名称:fluffos,代码行数:31,


示例8: SegReader_offsets

I32Array*SegReader_offsets(SegReader *self){    i32_t *ints = CALLOCATE(1, i32_t);    UNUSED_VAR(self);    return I32Arr_new_steal(ints, 1);}
开发者ID:robertkrimen,项目名称:Search-Kino03,代码行数:7,


示例9: S_write_class_pod

static CFCPerlPodFile*S_write_class_pod(CFCPerl *self) {    CFCPerlClass **registry  = CFCPerlClass_registry();    size_t num_registered = 0;    while (registry[num_registered] != NULL) { num_registered++; }    CFCPerlPodFile *pod_files        = (CFCPerlPodFile*)CALLOCATE(num_registered + 1,                                     sizeof(CFCPerlPodFile));    size_t count = 0;    // Generate POD, but don't write.  That way, if there's an error while    // generating pod, we leak memory but don't clutter up the file system.    for (size_t i = 0; i < num_registered; i++) {        const char *class_name = CFCPerlClass_get_class_name(registry[i]);        char *raw_pod = CFCPerlClass_create_pod(registry[i]);        if (!raw_pod) { continue; }        char *pod = CFCUtil_sprintf("%s/n%s%s", self->pod_header, raw_pod,                                    self->pod_footer);        char *pod_path = CFCUtil_sprintf("%s" CHY_DIR_SEP "%s.pod",                                         self->lib_dir, class_name);        S_replace_double_colons(pod_path, CHY_DIR_SEP_CHAR);        pod_files[count].contents = pod;        pod_files[count].path     = pod_path;        count++;        FREEMEM(raw_pod);    }    pod_files[count].contents = NULL;    pod_files[count].path     = NULL;    return pod_files;}
开发者ID:rlugojr,项目名称:lucy-clownfish,代码行数:33,


示例10: test_u1

static voidtest_u1(TestBatch *batch) {    size_t    count   = 64;    uint64_t *ints    = TestUtils_random_u64s(NULL, count, 0, 2);    size_t    amount  = count / 8;    uint8_t  *bits    = (uint8_t*)CALLOCATE(amount, sizeof(uint8_t));    for (size_t i = 0; i < count; i++) {        if (ints[i]) { NumUtil_u1set(bits, i); }    }    for (size_t i = 0; i < count; i++) {        TEST_INT_EQ(batch, NumUtil_u1get(bits, i), (long)ints[i],                    "u1 set/get");    }    for (size_t i = 0; i < count; i++) {        NumUtil_u1flip(bits, i);    }    for (size_t i = 0; i < count; i++) {        TEST_INT_EQ(batch, NumUtil_u1get(bits, i), !ints[i], "u1 flip");    }    FREEMEM(bits);    FREEMEM(ints);}
开发者ID:pavansondur,项目名称:lucy,代码行数:25,


示例11: pcre_match_single

static int pcre_match_single(svalue_t *str, svalue_t *pattern){	pcre_t *run;	int ret;	run = CALLOCATE(1, pcre_t, TAG_TEMPORARY, "pcre_match_single : run");	run->ovector = NULL;	run->ovecsize = 0;	assign_svalue_no_free(&run->pattern, pattern);	run->subject  = str->u.string;	run->s_length = SVALUE_STRLEN(str);	if(pcre_magic(run) < 0)	{		error("PCRE compilation failed at offset %d: %s/n", run->erroffset,				run->error);		pcre_free_memory(run);		return 0;	}	ret = pcre_query_match(run);	/* Free memory */	pcre_free_memory(run);	return ret;}
开发者ID:BPotato,项目名称:fluffos,代码行数:27,


示例12: test_bigend_f64

static voidtest_bigend_f64(TestBatch *batch) {    double   source[]  = { -1.3, 0.0, 100.2 };    size_t   count     = 3;    size_t   amount    = (count + 1) * sizeof(double);    uint8_t *allocated = (uint8_t*)CALLOCATE(amount, sizeof(uint8_t));    uint8_t *encoded   = allocated + 1; // Intentionally misaligned.    uint8_t *target    = encoded;    for (size_t i = 0; i < count; i++) {        NumUtil_encode_bigend_f64(source[i], &target);        target += sizeof(double);    }    target = encoded;    for (size_t i = 0; i < count; i++) {        double got = NumUtil_decode_bigend_f64(target);        TEST_TRUE(batch, got == source[i], "bigend f64");        target += sizeof(double);    }    target = encoded;    NumUtil_encode_bigend_f64(-2.0, &target);    TEST_INT_EQ(batch, (encoded[0] & 0x80), 0x80,                "Truly big-endian (IEEE 754 sign bit set for negative number)");    TEST_INT_EQ(batch, encoded[0], 0xC0,                "IEEE 754 representation of -2.0, byte 0");    for (size_t i = 1; i < sizeof(double); i++) {        TEST_INT_EQ(batch, encoded[i], 0,                    "IEEE 754 representation of -2.0, byte %d", (int)i);    }    FREEMEM(allocated);}
开发者ID:pavansondur,项目名称:lucy,代码行数:33,


示例13: test_c32

static voidtest_c32(TestBatch *batch) {    uint64_t  mins[]   = { 0,   0x4000 - 100, (uint32_t)I32_MAX - 100, U32_MAX - 10 };    uint64_t  limits[] = { 500, 0x4000 + 100, (uint32_t)I32_MAX + 100, U32_MAX      };    uint32_t  set_num;    uint32_t  num_sets  = sizeof(mins) / sizeof(uint64_t);    size_t    count     = 64;    uint64_t *ints      = NULL;    size_t    amount    = count * C32_MAX_BYTES;    char     *encoded   = (char*)CALLOCATE(amount, sizeof(char));    char     *target    = encoded;    char     *limit     = target + amount;    for (set_num = 0; set_num < num_sets; set_num++) {        char *skip;        ints = TestUtils_random_u64s(ints, count,                                     mins[set_num], limits[set_num]);        target = encoded;        for (size_t i = 0; i < count; i++) {            NumUtil_encode_c32((uint32_t)ints[i], &target);        }        target = encoded;        skip   = encoded;        for (size_t i = 0; i < count; i++) {            TEST_INT_EQ(batch, NumUtil_decode_c32(&target), (long)ints[i],                        "c32 %lu", (long)ints[i]);            NumUtil_skip_cint(&skip);            if (target > limit) { THROW(ERR, "overrun"); }        }        TEST_TRUE(batch, skip == target, "skip %lu == %lu",                  (unsigned long)skip, (unsigned long)target);        target = encoded;        for (size_t i = 0; i < count; i++) {            NumUtil_encode_padded_c32((uint32_t)ints[i], &target);        }        TEST_TRUE(batch, target == limit,                  "padded c32 uses 5 bytes (%lu == %lu)", (unsigned long)target,                  (unsigned long)limit);        target = encoded;        skip   = encoded;        for (size_t i = 0; i < count; i++) {            TEST_INT_EQ(batch, NumUtil_decode_c32(&target), (long)ints[i],                        "padded c32 %lu", (long)ints[i]);            NumUtil_skip_cint(&skip);            if (target > limit) { THROW(ERR, "overrun"); }        }        TEST_TRUE(batch, skip == target, "skip padded %lu == %lu",                  (unsigned long)skip, (unsigned long)target);    }    target = encoded;    NumUtil_encode_c32(U32_MAX, &target);    target = encoded;    TEST_INT_EQ(batch, NumUtil_decode_c32(&target), U32_MAX, "c32 U32_MAX");    FREEMEM(encoded);    FREEMEM(ints);}
开发者ID:pavansondur,项目名称:lucy,代码行数:59,


示例14: TestUtils_random_f64s

double*TestUtils_random_f64s(double *buf, size_t count) {    double *f64s = buf ? buf : (double*)CALLOCATE(count, sizeof(double));    for (size_t i = 0; i < count; i++) {        uint64_t num = TestUtils_random_u64();        f64s[i] = U64_TO_DOUBLE(num) / UINT64_MAX;    }    return f64s;}
开发者ID:kstarsinic,项目名称:lucy,代码行数:9,


示例15: CFCC_write_man_pages

voidCFCC_write_man_pages(CFCC *self) {    CFCHierarchy  *hierarchy = self->hierarchy;    CFCClass     **ordered   = CFCHierarchy_ordered_classes(hierarchy);    size_t num_classes = 0;    for (size_t i = 0; ordered[i] != NULL; i++) {        CFCClass *klass = ordered[i];        if (!CFCClass_included(klass)) { ++num_classes; }    }    char **man_pages = (char**)CALLOCATE(num_classes, sizeof(char*));    // Generate man pages, but don't write.  That way, if there's an error    // while generating the pages, we leak memory but don't clutter up the file     // system.    for (size_t i = 0, j = 0; ordered[i] != NULL; i++) {        CFCClass *klass = ordered[i];        if (CFCClass_included(klass)) { continue; }        char *man_page = CFCCMan_create_man_page(klass);        man_pages[j++] = man_page;    }    const char *dest = CFCHierarchy_get_dest(hierarchy);    char *man3_path        = CFCUtil_sprintf("%s" CHY_DIR_SEP "man" CHY_DIR_SEP "man3", dest);    if (!CFCUtil_is_dir(man3_path)) {        CFCUtil_make_path(man3_path);        if (!CFCUtil_is_dir(man3_path)) {            CFCUtil_die("Can't make path %s", man3_path);        }    }    // Write out any man pages that have changed.    for (size_t i = 0, j = 0; ordered[i] != NULL; i++) {        CFCClass *klass = ordered[i];        if (CFCClass_included(klass)) { continue; }        char *raw_man_page = man_pages[j++];        if (!raw_man_page) { continue; }        char *man_page = CFCUtil_sprintf("%s%s%s", self->man_header,                                         raw_man_page, self->man_footer);        const char *full_struct_sym = CFCClass_full_struct_sym(klass);        char *filename = CFCUtil_sprintf("%s" CHY_DIR_SEP "%s.3", man3_path,                                         full_struct_sym);        CFCUtil_write_if_changed(filename, man_page, strlen(man_page));        FREEMEM(filename);        FREEMEM(man_page);        FREEMEM(raw_man_page);    }    FREEMEM(man3_path);    FREEMEM(man_pages);    FREEMEM(ordered);}
开发者ID:leckie711,项目名称:lucy-clownfish,代码行数:56,


示例16: TestUtils_random_u64s

uint64_t*TestUtils_random_u64s(uint64_t *buf, size_t count, uint64_t min,                      uint64_t limit) {    uint64_t  range = min < limit ? limit - min : 0;    uint64_t *ints = buf ? buf : (uint64_t*)CALLOCATE(count, sizeof(uint64_t));    for (size_t i = 0; i < count; i++) {        ints[i] = min + TestUtils_random_u64() % range;    }    return ints;}
开发者ID:kstarsinic,项目名称:lucy,代码行数:10,


示例17: VA_init

VArray*VA_init(VArray *self, uint32_t capacity) {    // Init.    self->size = 0;    // Assign.    self->cap = capacity;    // Derive.    self->elems = (Obj**)CALLOCATE(capacity, sizeof(Obj*));    return self;}
开发者ID:timwilkens,项目名称:lucy-clownfish,代码行数:13,


示例18: S_parse_cf_files

static voidS_parse_cf_files(CFCHierarchy *self, const char *source_dir, int is_included) {    CFCFindFilesContext context;    context.ext       = ".cfh";    context.paths     = (char**)CALLOCATE(1, sizeof(char*));    context.num_paths = 0;    CFCUtil_walk(source_dir, S_find_files, &context);    // Process any file that has at least one class declaration.    for (int i = 0; context.paths[i] != NULL; i++) {        // Derive the name of the class that owns the module file.        char *source_path = context.paths[i];        char *path_part = S_extract_path_part(source_path, source_dir, ".cfh");        // Ignore hidden files.        if (path_part[0] == '.'            || strstr(path_part, CHY_DIR_SEP ".") != NULL) {            continue;        }        CFCFileSpec *file_spec = CFCFileSpec_new(source_dir, path_part, ".cfh",                                                 is_included);        // Slurp and parse file.        size_t unused;        char *content = CFCUtil_slurp_text(source_path, &unused);        CFCFile *file = CFCParser_parse_file(self->parser, content, file_spec);        FREEMEM(content);        if (!file) {            int lineno = CFCParser_get_lineno(self->parser);            CFCUtil_die("%s:%d: parser error", source_path, lineno);        }        // Make sure path_part is unique because the name of the generated        // C header is derived from it.        CFCFile *existing = S_fetch_file(self, path_part);        if (existing) {            CFCUtil_die("File %s.cfh found twice in %s and %s",                        path_part, CFCFile_get_source_dir(existing),                        source_dir);        }        S_add_file(self, file);        CFCBase_decref((CFCBase*)file);        CFCBase_decref((CFCBase*)file_spec);        FREEMEM(path_part);    }    CFCUtil_free_string_array(context.paths);}
开发者ID:apache,项目名称:lucy-clownfish,代码行数:51,


示例19: CFCHierarchy_init

CFCHierarchy*CFCHierarchy_init(CFCHierarchy *self, const char *dest) {    if (!dest || !strlen(dest)) {        CFCUtil_die("'dest' is required");    }    self->sources      = (char**)CALLOCATE(1, sizeof(char*));    self->num_sources  = 0;    self->includes     = (char**)CALLOCATE(1, sizeof(char*));    self->num_includes = 0;    self->prereqs      = (char**)CALLOCATE(1, sizeof(char*));    self->num_prereqs  = 0;    self->dest         = CFCUtil_strdup(dest);    self->trees        = (CFCClass**)CALLOCATE(1, sizeof(CFCClass*));    self->num_trees    = 0;    self->files        = (CFCFile**)CALLOCATE(1, sizeof(CFCFile*));    self->num_files    = 0;    self->parser       = CFCParser_new();    self->inc_dest = CFCUtil_sprintf("%s" CHY_DIR_SEP "include", self->dest);    self->src_dest = CFCUtil_sprintf("%s" CHY_DIR_SEP "source", self->dest);    return self;}
开发者ID:apache,项目名称:lucy-clownfish,代码行数:23,


示例20: BitVec_init

BitVector*BitVec_init(BitVector *self, uint32_t capacity) {    const uint32_t byte_size = (uint32_t)ceil(capacity / 8.0);    // Derive.    self->bits = capacity                 ? (uint8_t*)CALLOCATE(byte_size, sizeof(uint8_t))                 : NULL;    // Assign.    self->cap = byte_size * 8;    return self;}
开发者ID:pavansondur,项目名称:lucy,代码行数:14,


示例21: BitVec_init

BitVector*BitVec_init(BitVector *self, size_t capacity) {    BitVectorIVARS *const ivars = BitVec_IVARS(self);    const size_t byte_size = SI_octet_size(capacity);    // Derive.    ivars->bits = capacity                 ? (uint8_t*)CALLOCATE(byte_size, sizeof(uint8_t))                 : NULL;    // Assign.    ivars->cap = byte_size * 8;    return self;}
开发者ID:unlobe,项目名称:lucy,代码行数:15,


示例22: test_u4

static voidtest_u4(TestBatch *batch) {    size_t    count = 128;    uint64_t *ints  = TestUtils_random_u64s(NULL, count, 0, 16);    uint8_t  *bits  = (uint8_t*)CALLOCATE((count / 2), sizeof(uint8_t));    for (size_t i = 0; i < count; i++) {        NumUtil_u4set(bits, i, (uint8_t)ints[i]);    }    for (size_t i = 0; i < count; i++) {        TEST_INT_EQ(batch, NumUtil_u4get(bits, i), (long)ints[i], "u4");    }    FREEMEM(bits);    FREEMEM(ints);}
开发者ID:pavansondur,项目名称:lucy,代码行数:16,


示例23: test_u2

static voidtest_u2(TestBatchRunner *runner) {    size_t    count = 32;    uint64_t *ints = TestUtils_random_u64s(NULL, count, 0, 4);    uint8_t  *bits = (uint8_t*)CALLOCATE((count / 4), sizeof(uint8_t));    for (size_t i = 0; i < count; i++) {        NumUtil_u2set(bits, i, (uint8_t)ints[i]);    }    for (size_t i = 0; i < count; i++) {        TEST_INT_EQ(runner, NumUtil_u2get(bits, i), (long)ints[i], "u2");    }    FREEMEM(bits);    FREEMEM(ints);}
开发者ID:theory,项目名称:lucy,代码行数:16,


示例24: S_lazy_init_method_bindings

static voidS_lazy_init_method_bindings(CFCGoClass *self) {    if (self->method_bindings) {        return;    }    CFCUTIL_NULL_CHECK(self->client);    size_t        num_bound     = 0;    CFCMethod   **fresh_methods = CFCClass_fresh_methods(self->client);    CFCGoMethod **bound        = (CFCGoMethod**)CALLOCATE(1, sizeof(CFCGoMethod*));     // Iterate over the class's fresh methods.    for (size_t i = 0; fresh_methods[i] != NULL; i++) {        CFCMethod *method = fresh_methods[i];        // Skip methods which have been explicitly excluded.        if (CFCMethod_excluded_from_host(method)) {            continue;        }        // Skip methods that shouldn't be bound.        if (!CFCMethod_can_be_bound(method)) {            continue;        }        // Only include novel methods.        if (!CFCMethod_novel(method)) {            continue;        }        const char *sym = CFCMethod_get_name(method);        if (!CFCClass_fresh_method(self->client, sym)) {            continue;        }        /* Create the binding, add it to the array.         */        CFCGoMethod *meth_binding = CFCGoMethod_new(method);        size_t size = (num_bound + 2) * sizeof(CFCGoMethod*);        bound = (CFCGoMethod**)REALLOCATE(bound, size);        bound[num_bound] = meth_binding;        num_bound++;        bound[num_bound] = NULL;    }    self->method_bindings = bound;    self->num_bound       = num_bound;}
开发者ID:nkurz,项目名称:lucy-clownfish,代码行数:47,


示例25: f_pcre_extract

void f_pcre_extract(void){	pcre_t *run;	array_t *ret;	run = CALLOCATE(1, pcre_t, TAG_TEMPORARY, "f_pcre_extract : run");	assign_svalue_no_free(&run->pattern, sp);	run->subject  = (sp - 1)->u.string;	run->s_length = SVALUE_STRLEN(sp - 1);	run->ovector = NULL;	run->ovecsize = 0;	if(pcre_magic(run) < 0)	{		error("PCRE compilation failed at offset %d: %s/n", run->erroffset,				run->error);		pop_2_elems();		pcre_free_memory(run);		return;	}	/* Pop the 2 arguments from the stack */	if (run->rc < 0) /* No match. could do handling of matching errors if wanted */	{		pop_2_elems();		pcre_free_memory(run);		push_refed_array(&the_null_array);		return;	}	else if (run->rc > (run->ovecsize/3 - 1))	{		pop_2_elems();		pcre_free_memory(run);		error("Too many substrings./n");		return;	}	ret = pcre_get_substrings(run);	pop_2_elems();	push_refed_array(ret);	pcre_free_memory(run);	return;}
开发者ID:BPotato,项目名称:fluffos,代码行数:47,


示例26: more_lpc_sockets

/* * Get more LPC sockets structures if we run out */static int more_lpc_sockets(){    int i;    max_lpc_socks += 10;    if (!lpc_socks)        lpc_socks = CALLOCATE(10, lpc_socket_t, TAG_SOCKETS, "more_lpc_sockets");    else        lpc_socks = RESIZE(lpc_socks, max_lpc_socks, lpc_socket_t, TAG_SOCKETS, "more_lpc_sockets");    i = max_lpc_socks;    while (--i >= max_lpc_socks - 10)        clear_socket(i, 0);    return max_lpc_socks - 10;}
开发者ID:Hobbitron,项目名称:tmi2_fluffos_v3,代码行数:20,


示例27: CFCParcel_register

voidCFCParcel_register(CFCParcel *self) {    CFCParcel *existing = CFCParcel_fetch(self->name);    if (existing) {        CFCUtil_die("Parcel '%s' already registered", self->name);    }    if (!num_registered) {        // Init default parcel as first.        registry = (CFCParcel**)CALLOCATE(3, sizeof(CFCParcel*));        CFCParcel *def = CFCParcel_default_parcel();        registry[0] = (CFCParcel*)CFCBase_incref((CFCBase*)def);        num_registered++;    }    size_t size = (num_registered + 2) * sizeof(CFCParcel*);    registry = (CFCParcel**)REALLOCATE(registry, size);    registry[num_registered++] = (CFCParcel*)CFCBase_incref((CFCBase*)self);    registry[num_registered]   = NULL;}
开发者ID:pavansondur,项目名称:lucy,代码行数:18,


示例28: test_c64

static voidtest_c64(TestBatch *batch) {    uint64_t  mins[]    = { 0,   0x4000 - 100, (uint64_t)U32_MAX - 100,  U64_MAX - 10 };    uint64_t  limits[]  = { 500, 0x4000 + 100, (uint64_t)U32_MAX + 1000, U64_MAX      };    uint32_t  set_num;    uint32_t  num_sets  = sizeof(mins) / sizeof(uint64_t);    size_t    count     = 64;    uint64_t *ints      = NULL;    size_t    amount    = count * C64_MAX_BYTES;    char     *encoded   = (char*)CALLOCATE(amount, sizeof(char));    char     *target    = encoded;    char     *limit     = target + amount;    for (set_num = 0; set_num < num_sets; set_num++) {        char *skip;        ints = TestUtils_random_u64s(ints, count,                                     mins[set_num], limits[set_num]);        target = encoded;        for (size_t i = 0; i < count; i++) {            NumUtil_encode_c64(ints[i], &target);        }        target = encoded;        skip   = encoded;        for (size_t i = 0; i < count; i++) {            uint64_t got = NumUtil_decode_c64(&target);            TEST_TRUE(batch, got == ints[i],                      "c64 %" U64P " == %" U64P, got, ints[i]);            if (target > limit) { THROW(ERR, "overrun"); }            NumUtil_skip_cint(&skip);        }        TEST_TRUE(batch, skip == target, "skip %lu == %lu",                  (unsigned long)skip, (unsigned long)target);    }    target = encoded;    NumUtil_encode_c64(U64_MAX, &target);    target = encoded;    uint64_t got = NumUtil_decode_c64(&target);    TEST_TRUE(batch, got == U64_MAX, "c64 U64_MAX");    FREEMEM(encoded);    FREEMEM(ints);}
开发者ID:pavansondur,项目名称:lucy,代码行数:44,


示例29: S_find_doc_files

static voidS_find_doc_files(const char *source_dir) {    CFCFindFilesContext context;    context.ext       = ".md";    context.paths     = (char**)CALLOCATE(1, sizeof(char*));    context.num_paths = 0;    CFCUtil_walk(source_dir, S_find_files, &context);    for (int i = 0; context.paths[i] != NULL; i++) {        char *path = context.paths[i];        char *path_part = S_extract_path_part(path, source_dir, ".md");        CFCDocument *doc = CFCDocument_create(path, path_part);        CFCBase_decref((CFCBase*)doc);        FREEMEM(path_part);    }    CFCUtil_free_string_array(context.paths);}
开发者ID:apache,项目名称:lucy-clownfish,代码行数:19,


示例30: DelWriter_Generate_Doc_Map_IMP

I32Array*DelWriter_Generate_Doc_Map_IMP(DeletionsWriter *self, Matcher *deletions,                               int32_t doc_max, int32_t offset) {    int32_t *doc_map = (int32_t*)CALLOCATE(doc_max + 1, sizeof(int32_t));    int32_t  next_deletion = deletions ? Matcher_Next(deletions) : INT32_MAX;    UNUSED_VAR(self);    // 0 for a deleted doc, a new number otherwise    for (int32_t i = 1, new_doc_id = 1; i <= doc_max; i++) {        if (i == next_deletion) {            next_deletion = Matcher_Next(deletions);        }        else {            doc_map[i] = offset + new_doc_id++;        }    }    return I32Arr_new_steal(doc_map, doc_max + 1);}
开发者ID:github188,项目名称:SimpleCode,代码行数:19,



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


C++ CALLOC_STRUCT函数代码示例
C++ CALLOC函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。