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


C++ FloatArray::reserve方法代码示例

本文整理汇总了C++中FloatArray::reserve方法的典型用法代码示例。如果您正苦于以下问题:C++ FloatArray::reserve方法的具体用法?C++ FloatArray::reserve怎么用?C++ FloatArray::reserve使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FloatArray的用法示例。


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

示例1:

//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
TEST(ArrayTest, ReserveAndAdd)
{
    FloatArray a;
    a.reserve(5);
    a.add(1.0f);
    a.add(3.3f);
    a.add(5.5f);

    ASSERT_EQ(3u, a.size());
    ASSERT_TRUE(a.capacity() >= 5);
    ASSERT_EQ(1.0f, a[0]);
    ASSERT_EQ(3.3f, a[1]);
    ASSERT_EQ(5.5f, a[2]);

    // To test reuse of buffer
    float* before = a.ptr();

    a.reserve(3);
    ASSERT_TRUE(a.capacity() >= 5);

    float* after = a.ptr();

    // Check that no realloc has been done
    ASSERT_EQ(before, after);
    ASSERT_TRUE(a.capacity() >= 5);
}
开发者ID:JacobStoren,项目名称:ResInsight,代码行数:29,代码来源:cvfArray-Test.cpp

示例2: DoAnim

void DoAnim()
{
    static double time = 0.0; //Total time running.
    static double artTime = 0.0; //Total time with the current art.

    static DWORD lastTime = 0; //Time of last call.
    const double elapsed = double(GetTickCount() - lastTime) / 1000.0;

    if (lastTime)
    {
        lastTime = GetTickCount();
    }
    else
    {
        lastTime = GetTickCount();
        return;
    }

    time += elapsed;
    artTime += elapsed;

    //If we need new art, get it.
    static CKnot::AutoArt threads;
    static Arrays arrays;
    static FloatArray grid;


    if (!threads.get() || artTime > ResetTime)
    {
        CKnot::StrokeList sl = CreateSquareStrokes();
        sl = RemoveStrokes(sl);

        threads = CKnot::CreateThread(sl);
        artTime = 0.0;

        grid.clear();
        grid.reserve(sl.size() * 10);
        for (CKnot::StrokeList::const_iterator it = sl.begin(); it != sl.end(); ++it)
        {
            grid.push_back(it->a.x);
            grid.push_back(it->a.y);
            grid.push_back(it->type == CKnot::Cross ? 1.0 : 0.0);
            grid.push_back(it->type == CKnot::Glance ? 1.0 : 0.0);
            grid.push_back(it->type == CKnot::Bounce ? 1.0 : 0.0);

            grid.push_back(it->b.x);
            grid.push_back(it->b.y);
            grid.push_back(it->type == CKnot::Cross ? 1.0 : 0.0);
            grid.push_back(it->type == CKnot::Glance ? 1.0 : 0.0);
            grid.push_back(it->type == CKnot::Bounce ? 1.0 : 0.0);
        }

        for (size_t i = 0; i < arrays.size(); ++i)
            delete arrays[i];
        arrays.clear();

        const size_t threadCount = threads->GetThreadCount();

        for (size_t i = 0; i < threadCount; ++i)
        {
            const CKnot::Art::Thread* thread = threads->GetThread(i);
            const CKnot::Art::Z* z = threads->GetZ(i);

            const size_t segsPerKnot = 25;
            const size_t kc = thread->GetKnotCount();

            FloatArray* quads = new FloatArray;
            arrays.push_back(quads);


            const size_t target = kc * segsPerKnot;
            const size_t memSize = 12 * (target + 1);
            quads->reserve(memSize);

            const float scr = double(rand()) / RAND_MAX / 2;
            const float ecr = double(rand()) / RAND_MAX / 2 + .5;
            const float scg = double(rand()) / RAND_MAX / 2;
            const float ecg = double(rand()) / RAND_MAX / 2 + .5;
            const float scb = double(rand()) / RAND_MAX / 2;
            const float ecb = double(rand()) / RAND_MAX / 2 + .5;

            for (size_t i = 0; i <= target; ++i)
            {
                const double s = double(i) / double(target);
                const double t = s;

                const CKnot::vec2 cur = thread->Y(t);
                const CKnot::vec2 dcur = thread->Y(t + .00001);
                const CKnot::vec2 diff = dcur - cur;

                CKnot::vec2 normal(diff.y, -diff.x);
                normal = normal * (1.0 / normal.GetLength());
                normal = normal * .01;
                const CKnot::vec2 flip(-normal.x, -normal.y);

                const CKnot::vec2 start = cur + normal;
                const CKnot::vec2 end = cur + flip;

                const bool over = z->Y(t) > 0.0;

//.........这里部分代码省略.........
开发者ID:codeplea,项目名称:celtic_knots,代码行数:101,代码来源:saver.cpp


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