本文整理汇总了C++中ARRLEN函数的典型用法代码示例。如果您正苦于以下问题:C++ ARRLEN函数的具体用法?C++ ARRLEN怎么用?C++ ARRLEN使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ARRLEN函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: verifyDatabase
bool MapDatabasePostgreSQL::saveBlock(const v3s16 &pos, const std::string &data)
{
// Verify if we don't overflow the platform integer with the mapblock size
if (data.size() > INT_MAX) {
errorstream << "Database_PostgreSQL::saveBlock: Data truncation! "
<< "data.size() over 0xFFFFFFFF (== " << data.size()
<< ")" << std::endl;
return false;
}
verifyDatabase();
s32 x, y, z;
x = htonl(pos.X);
y = htonl(pos.Y);
z = htonl(pos.Z);
const void *args[] = { &x, &y, &z, data.c_str() };
const int argLen[] = {
sizeof(x), sizeof(y), sizeof(z), (int)data.size()
};
const int argFmt[] = { 1, 1, 1, 1 };
if (getPGVersion() < 90500) {
execPrepared("write_block_update", ARRLEN(args), args, argLen, argFmt);
execPrepared("write_block_insert", ARRLEN(args), args, argLen, argFmt);
} else {
execPrepared("write_block", ARRLEN(args), args, argLen, argFmt);
}
return true;
}
示例2: test
static void test(struct socket_server *ss) {
pthread_t pid;
pthread_create(&pid, NULL, _poll, ss);
int i = 0;
int connid = socket_server_connect(ss, 400, "127.0.0.1", 8888);
getc(stdin);
socket_server_start(ss, 401, connid);
char* tmp[3] = { "hello", "world", "wong" };
int cnt = ARRLEN(tmp);
char* contents[ARRLEN(tmp)];
for (i = 0; i < cnt; ++i)
{
contents[i] = malloc(strlen(tmp[i]) + 1);
memcpy(contents[i], tmp[i], strlen(tmp[i]));
}
for (i = 0; i < cnt; ++i)
{
socket_server_send(ss, connid, contents[i], strlen(contents[i]));
getc(stdin);
}
printf("done\n");
pthread_join(pid, NULL);
}
示例3: updateMemory
int updateMemory(void)
{
#define ARRLEN(X) (sizeof(X) / sizeof(X[0]))
long pagesize; /* using a long promotes the arithmetic */
size_t len;
{
static int mib[] = {CTL_HW, HW_PHYSMEM};
len = sizeof(Total);
sysctl(mib, ARRLEN(mib), &Total, &len, NULL, 0);
Total >>= 10;
}
{
struct uvmexp x;
static int mib[] = {CTL_VM, VM_UVMEXP};
len = sizeof(x);
STotal = SUsed = SFree = -1;
pagesize = 1;
if(-1 < sysctl(mib, ARRLEN(mib), &x, &len, NULL, 0))
{
pagesize = x.pagesize;
STotal = (pagesize * x.swpages) >> 10;
SUsed = (pagesize * x.swpginuse) >> 10;
SFree = STotal - SUsed;
}
}
示例4: test_nghttp2_hd_deflate_bound
void test_nghttp2_hd_deflate_bound(void) {
nghttp2_hd_deflater deflater;
nghttp2_nv nva[] = {MAKE_NV(":method", "GET"), MAKE_NV("alpha", "bravo")};
nghttp2_bufs bufs;
size_t bound, bound2;
nghttp2_mem *mem;
mem = nghttp2_mem_default();
frame_pack_bufs_init(&bufs);
nghttp2_hd_deflate_init(&deflater, mem);
bound = nghttp2_hd_deflate_bound(&deflater, nva, ARRLEN(nva));
CU_ASSERT(12 + 6 * 2 * 2 + nva[0].namelen + nva[0].valuelen + nva[1].namelen +
nva[1].valuelen ==
bound);
nghttp2_hd_deflate_hd_bufs(&deflater, &bufs, nva, ARRLEN(nva));
CU_ASSERT(bound > (size_t)nghttp2_bufs_len(&bufs));
bound2 = nghttp2_hd_deflate_bound(&deflater, nva, ARRLEN(nva));
CU_ASSERT(bound == bound2);
nghttp2_bufs_free(&bufs);
nghttp2_hd_deflate_free(&deflater);
}
示例5: main
int main(void)
{
int A[] = {6, 2, 4, 3, 5, 1};
int i = 0;
clock_t begin, end;
printf("Tal før sortering:\n ");
for(i = 0; i < ARRLEN(A); i++)
printf("%d ", A[i]);
printf("\n");
begin = clock();
MergeSort(A, 0, ARRLEN(A) - 1);
end = clock();
printf("Tal efter sortering:\n ");
for(i = 0; i < ARRLEN(A); i++)
printf("%d ", A[i]);
printf("\n");
printf("Kørselstid = %f\n", (double)(end - begin) / CLOCKS_PER_SEC);
}
示例6: generateOFFSIVAL
static int generateOFFSIVAL(OFFSIVALARR *oivr,
int d_min, int d_max,
const ResultSet *rsp)
/**< Collect position intervals for the top scoring results of
* the largest fragment.
* Array of results must have been sorted by rsr[i].swatscor.
*/
{
int errcode;
struct SETUPOFFSIVALARG_ arg;
resultSetGetNumberOfResultsInSegment(0, rsp);
ARRLEN(*oivr) = (size_t) 0;
if (resultSetGetNumberOfResultsInSegment(0, rsp) < 1)
return ERRCODE_SUCCESS;
arg.dmin = (SEQLEN_t) (d_min < 0)? 0: d_min;
arg.dmax = (SEQLEN_t) (d_max < 0)? 0: d_max;
if (arg.dmin > arg.dmax)
return ERRCODE_ASSERT;
arg.oivr = *oivr;
arg.max_rank = 0;
if ((errcode = resultSetDo(&arg, setupOFFSIVALcbf, rsp)))
return errcode;
*oivr = arg.oivr;
/* sort intervals by sequence and lower limit */
qsort(*oivr, ARRLEN(*oivr), sizeof(OFFSIVAL), cmpOFFSIVAL);
return ERRCODE_SUCCESS;
}
示例7: resetPairs
static void resetPairs(ResultPairs *p)
{
ARRLEN(p->mpr) = 0;
ARRLEN(p->ivr) = 0;
p->status = 0;
p->n_proper = 0;
p->n_within = 0;
}
示例8: size_readable
void size_readable(float *size, const char **unit)
{
const char *units[] = { "", "K", "M", "G" };
int i;
for (i = 0; i < ARRLEN(units) && *size > 1024.0; i++)
*size /= 1024.0;
*unit = units[MIN(i, ARRLEN(units) - 1)];
}
示例9: resultSetBlankPairs
void resultSetBlankPairs(ResultPairs *p)
{
if ((p)) {
ARRLEN(p->ivr) = 0;
ARRLEN(p->mpr) = 0;
p->status = 0;
p->n_proper = 0;
p->n_within = 0;
p->dmin = 0;
p->dmax = 0;
}
}
示例10: run_nghttp2_hd
static void run_nghttp2_hd(void) {
nghttp2_hd_deflater deflater;
nghttp2_hd_inflater inflater;
nghttp2_bufs bufs;
int rv;
nghttp2_nv nva1[] = {
MAKE_NV(":scheme", "https"), MAKE_NV(":authority", "example.org"),
MAKE_NV(":path", "/slashdot"),
MAKE_NV("accept-encoding", "gzip, deflate"), MAKE_NV("foo", "bar")};
nghttp2_nv nva2[] = {
MAKE_NV(":scheme", "https"), MAKE_NV(":authority", "example.org"),
MAKE_NV(":path", "/style.css"), MAKE_NV("cookie", "nghttp2=FTW"),
MAKE_NV("foo", "bar2")};
rv = frame_pack_bufs_init(&bufs);
if (rv != 0) {
return;
}
rv = nghttp2_hd_deflate_init(&deflater, nghttp2_mem_fm());
if (rv != 0) {
goto deflate_init_fail;
}
rv = nghttp2_hd_inflate_init(&inflater, nghttp2_mem_fm());
if (rv != 0) {
goto inflate_init_fail;
}
rv = deflate_inflate(&deflater, &inflater, &bufs, nva1, ARRLEN(nva1),
nghttp2_mem_fm());
if (rv != 0) {
goto deflate_hd_fail;
}
rv = deflate_inflate(&deflater, &inflater, &bufs, nva2, ARRLEN(nva2),
nghttp2_mem_fm());
if (rv != 0) {
goto deflate_hd_fail;
}
deflate_hd_fail:
nghttp2_hd_inflate_free(&inflater);
inflate_init_fail:
nghttp2_hd_deflate_free(&deflater);
deflate_init_fail:
nghttp2_bufs_free(&bufs);
}
示例11: flagOutPairsWithDoubleFragments
static int flagOutPairsWithDoubleFragments(const ResultPairs *pairp,
const ResultSet *rsrp,
const ResultSet *rsmp)
{
int errcode;
MATEPAIRARR mpr = pairp->mpr;
size_t npairs = ARRLEN(pairp->mpr);
MAPFLG_t const mask = MAPFLG_PROPER | MAPFLG_WITHIN | MAPFLG_INVALID;
MAPFLG_t const properflg = MAPFLG_PROPER | MAPFLG_WITHIN;
int nn, i, j;
short qsegnoA, qsegnoB;
if (npairs > INT_MAX)
return ERRCODE_OVERFLOW;
nn = (int) npairs;
if ((errcode = resultSetGetNumberOfSegments(NULL, &qsegnoA, rsrp)))
return errcode;
if ((errcode = resultSetGetNumberOfSegments(NULL, &qsegnoB, rsmp)))
return errcode;
if (nn < 2 || (qsegnoA < 1 && qsegnoB < 1))
return ERRCODE_SUCCESS;
for (i=0; i<nn; i++) {
if ((mpr[i].mapflg&mask) == properflg) {
/* is first proper pair, flag out all other pairs with complementary fragments */
int sxA = resultGetFragmentNo(mpr[i].ap);
int sxB = resultGetFragmentNo(mpr[i].bp);
for (j=0; j<nn; j++) {
if (!(mpr[j].mapflg&MAPFLG_INVALID) &&
j != i &&
(mpr[j].mapflg&properflg) != properflg &&
(resultGetFragmentNo(mpr[j].ap) == sxA ||
resultGetFragmentNo(mpr[j].bp) == sxB)
)
mpr[j].mapflg |= MAPFLG_INVALID;
}
}
}
/* skip the flagged out pairs */
for (j=0; j<nn && !(mpr[j].mapflg&MAPFLG_INVALID); j++);
for (i=j+1; i<nn; i++) {
if (!(mpr[i].mapflg&MAPFLG_INVALID))
mpr[j++] = mpr[i];
}
ARRLEN(mpr) = (size_t) j;
return ERRCODE_SUCCESS;
}
示例12: test_nghttp2_hd_deflate_same_indexed_repr
void test_nghttp2_hd_deflate_same_indexed_repr(void) {
nghttp2_hd_deflater deflater;
nghttp2_hd_inflater inflater;
nghttp2_nv nva1[] = {MAKE_NV("cookie", "alpha"), MAKE_NV("cookie", "alpha")};
nghttp2_nv nva2[] = {MAKE_NV("cookie", "alpha"), MAKE_NV("cookie", "alpha"),
MAKE_NV("cookie", "alpha")};
nghttp2_bufs bufs;
ssize_t blocklen;
nva_out out;
int rv;
nghttp2_mem *mem;
mem = nghttp2_mem_default();
frame_pack_bufs_init(&bufs);
nva_out_init(&out);
CU_ASSERT(0 == nghttp2_hd_deflate_init(&deflater, mem));
CU_ASSERT(0 == nghttp2_hd_inflate_init(&inflater, mem));
/* Encode 2 same headers. Emit 1 literal reprs and 1 index repr. */
rv = nghttp2_hd_deflate_hd_bufs(&deflater, &bufs, nva1, ARRLEN(nva1));
blocklen = nghttp2_bufs_len(&bufs);
CU_ASSERT(0 == rv);
CU_ASSERT(blocklen > 0);
CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem));
CU_ASSERT(2 == out.nvlen);
assert_nv_equal(nva1, out.nva, 2, mem);
nva_out_reset(&out, mem);
nghttp2_bufs_reset(&bufs);
/* Encode 3 same headers. This time, emits 3 index reprs. */
rv = nghttp2_hd_deflate_hd_bufs(&deflater, &bufs, nva2, ARRLEN(nva2));
blocklen = nghttp2_bufs_len(&bufs);
CU_ASSERT(0 == rv);
CU_ASSERT(blocklen == 3);
CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem));
CU_ASSERT(3 == out.nvlen);
assert_nv_equal(nva2, out.nva, 3, mem);
nva_out_reset(&out, mem);
nghttp2_bufs_reset(&bufs);
/* Cleanup */
nghttp2_bufs_free(&bufs);
nghttp2_hd_inflate_free(&inflater);
nghttp2_hd_deflate_free(&deflater);
}
示例13:
MapgenSpecificParams *EmergeManager::createMapgenParams(const std::string &mgname)
{
u32 i;
for (i = 0; i < ARRLEN(reg_mapgens) && mgname != reg_mapgens[i].name; i++);
if (i == ARRLEN(reg_mapgens)) {
errorstream << "EmergeManager: Mapgen " << mgname <<
" not registered" << std::endl;
return NULL;
}
MapgenFactory *mgfactory = reg_mapgens[i].factory;
return mgfactory->createMapgenParams();
}
示例14: test_nghttp2_hd_no_index
void test_nghttp2_hd_no_index(void) {
nghttp2_hd_deflater deflater;
nghttp2_hd_inflater inflater;
nghttp2_bufs bufs;
ssize_t blocklen;
nghttp2_nv nva[] = {
MAKE_NV(":method", "GET"), MAKE_NV(":method", "POST"),
MAKE_NV(":path", "/foo"), MAKE_NV("version", "HTTP/1.1"),
MAKE_NV(":method", "GET"),
};
size_t i;
nva_out out;
int rv;
nghttp2_mem *mem;
mem = nghttp2_mem_default();
/* 1st :method: GET can be indexable, last one is not */
for (i = 1; i < ARRLEN(nva); ++i) {
nva[i].flags = NGHTTP2_NV_FLAG_NO_INDEX;
}
frame_pack_bufs_init(&bufs);
nva_out_init(&out);
nghttp2_hd_deflate_init(&deflater, mem);
nghttp2_hd_inflate_init(&inflater, mem);
rv = nghttp2_hd_deflate_hd_bufs(&deflater, &bufs, nva, ARRLEN(nva));
blocklen = nghttp2_bufs_len(&bufs);
CU_ASSERT(0 == rv);
CU_ASSERT(blocklen > 0);
CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem));
CU_ASSERT(ARRLEN(nva) == out.nvlen);
assert_nv_equal(nva, out.nva, ARRLEN(nva), mem);
CU_ASSERT(out.nva[0].flags == NGHTTP2_NV_FLAG_NONE);
for (i = 1; i < ARRLEN(nva); ++i) {
CU_ASSERT(out.nva[i].flags == NGHTTP2_NV_FLAG_NO_INDEX);
}
nva_out_reset(&out, mem);
nghttp2_bufs_free(&bufs);
nghttp2_hd_inflate_free(&inflater);
nghttp2_hd_deflate_free(&deflater);
}
示例15: test_nghttp2_nv_array_copy
void test_nghttp2_nv_array_copy(void)
{
nghttp2_nv *nva;
ssize_t rv;
nghttp2_nv emptynv[] = {MAKE_NV("", ""),
MAKE_NV("", "")};
nghttp2_nv nv[] = {MAKE_NV("alpha", "bravo"),
MAKE_NV("charlie", "delta")};
nghttp2_nv bignv;
bignv.name = (uint8_t*)"echo";
bignv.namelen = strlen("echo");
bignv.valuelen = (1 << 14) - 1;
bignv.value = malloc(bignv.valuelen);
memset(bignv.value, '0', bignv.valuelen);
rv = nghttp2_nv_array_copy(&nva, NULL, 0);
CU_ASSERT(0 == rv);
CU_ASSERT(NULL == nva);
rv = nghttp2_nv_array_copy(&nva, emptynv, ARRLEN(emptynv));
CU_ASSERT(0 == rv);
CU_ASSERT(nva[0].namelen == 0);
CU_ASSERT(nva[0].valuelen == 0);
CU_ASSERT(nva[1].namelen == 0);
CU_ASSERT(nva[1].valuelen == 0);
nghttp2_nv_array_del(nva);
rv = nghttp2_nv_array_copy(&nva, nv, ARRLEN(nv));
CU_ASSERT(0 == rv);
CU_ASSERT(nva[0].namelen == 5);
CU_ASSERT(0 == memcmp("alpha", nva[0].name, 5));
CU_ASSERT(nva[0].valuelen = 5);
CU_ASSERT(0 == memcmp("bravo", nva[0].value, 5));
CU_ASSERT(nva[1].namelen == 7);
CU_ASSERT(0 == memcmp("charlie", nva[1].name, 7));
CU_ASSERT(nva[1].valuelen == 5);
CU_ASSERT(0 == memcmp("delta", nva[1].value, 5));
nghttp2_nv_array_del(nva);
/* Large header field is acceptable */
rv = nghttp2_nv_array_copy(&nva, &bignv, 1);
CU_ASSERT(0 == rv);
nghttp2_nv_array_del(nva);
free(bignv.value);
}