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


C++ AlignedArray类代码示例

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


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

示例1: readPackAndWrite

void readPackAndWrite(
    uint64_t& writeSize, packet::Packet& pkt,
    cybozu::util::File& fileW, bool doWriteDiff, DiscardType discardType,
    uint64_t fsyncIntervalSize,
    std::vector<char>& zero, AlignedArray& buf)
{
    const char *const FUNC = __func__;
    size_t size;
    pkt.read(size);
    verifyDiffPackSize(size, FUNC);
    buf.resize(size);
    pkt.read(buf.data(), buf.size());

    verifyDiffPack(buf.data(), buf.size(), true);
    if (doWriteDiff) {
        fileW.write(buf.data(), buf.size());
    } else {
        MemoryDiffPack pack(buf.data(), buf.size());
        issueDiffPack(fileW, discardType, pack, zero);
    }
    writeSize += buf.size();
    if (writeSize >= fsyncIntervalSize) {
        fileW.fdatasync();
        writeSize = 0;
    }
}
开发者ID:walb-linux,项目名称:walb-tools,代码行数:26,代码来源:dirty_hash_sync.hpp

示例2: setRandomData

void setRandomData(AlignedArray& buf, Rand& rand)
{
    size_t off = 0;
    while (off < buf.size()) {
        const size_t size = std::min<size_t>(buf.size() - off, 16);
        rand.fill(buf.data() + off, size);
        off += 512;
    }
}
开发者ID:walb-linux,项目名称:walb-tools,代码行数:9,代码来源:fs-workload.cpp

示例3: readAndSendHash

void readAndSendHash(
    uint64_t& hashLb,
    packet::Packet& pkt, packet::StreamControl2& ctrl, Reader &reader,
    uint64_t sizeLb, size_t bulkLb,
    cybozu::murmurhash3::Hasher& hasher, AlignedArray& buf)
{
    const uint64_t lb = std::min<uint64_t>(sizeLb - hashLb, bulkLb);
    buf.resize(lb * LOGICAL_BLOCK_SIZE);
    reader.read(buf.data(), buf.size());
    const cybozu::murmurhash3::Hash hash = hasher(buf.data(), buf.size());
    doRetrySockIo(2, "ctrl.send.next", [&]() { ctrl.sendNext(); });
    pkt.write(hash);
    hashLb += lb;
}
开发者ID:walb-linux,项目名称:walb-tools,代码行数:14,代码来源:dirty_hash_sync.hpp

示例4: internalSet

void GFXGLShaderConstBuffer::internalSet(GFXShaderConstHandle* handle, const AlignedArray<ConstType>& fv)
{
   AssertFatal(handle, "GFXGLShaderConstBuffer::internalSet - Handle is NULL!" );
   AssertFatal(handle->isValid(), "GFXGLShaderConstBuffer::internalSet - Handle is not valid!" );
   AssertFatal(dynamic_cast<GFXGLShaderConstHandle*>(handle), "GFXGLShaderConstBuffer::set - Incorrect const buffer type");

   GFXGLShaderConstHandle* _glHandle = static_cast<GFXGLShaderConstHandle*>(handle);
   AssertFatal(mShader == _glHandle->mShader, "GFXGLShaderConstBuffer::set - Should only set handles which are owned by our shader");
   const U8* fvBuffer = static_cast<const U8*>(fv.getBuffer());
   for(U32 i = 0; i < fv.size(); ++i)
   {
      dMemcpy(mBuffer + _glHandle->mOffset + i * sizeof(ConstType), fvBuffer, sizeof(ConstType));
      fvBuffer += fv.getElementSize();
   }
}
开发者ID:Adhdcrazzy,项目名称:Torque3D,代码行数:15,代码来源:gfxGLShader.cpp

示例5: readAndValidateLogPackIo

uint64_t readAndValidateLogPackIo(cybozu::util::File& file, const device::SuperBlock& super, const LogPackHeader& logh)
{
    const uint32_t pbs = super.getPhysicalBlockSize();
    assert(logh.isValid());
    AlignedArray buf;
    for (size_t i = 0; i < logh.nRecords(); i++) {
        const WlogRecord &rec = logh.record(i);
        if (!rec.hasDataForChecksum()) continue;
        const uint64_t pb = super.getOffsetFromLsid(rec.lsid);
        const size_t ioSize = rec.ioSizeLb() * LBS;
        buf.resize(ioSize);
        file.pread(buf.data(), ioSize, pb * pbs);
        const uint32_t csum = cybozu::util::calcChecksum(buf.data(), buf.size(), logh.salt());
        if (csum == rec.checksum) continue;
        LOGs.info() << "INVALID_LOGPACK_IO" << rec << csum;
    }
    return logh.nextLogpackLsid();
}
开发者ID:walb-linux,项目名称:walb-tools,代码行数:18,代码来源:search-invalid-logpack.cpp

示例6: issueDiffPack

/*
 * @zero is used as zero-filled buffer. It may be resized.
 */
inline void issueDiffPack(cybozu::util::File& file, DiscardType discardType, MemoryDiffPack& pack, std::vector<char>& zero)
{
    const DiffPackHeader& head = pack.header();
    DiffRecord rec;
    AlignedArray array; // buffer for uncompressed data.
    for (size_t i = 0; i < head.n_records; i++) {
        const DiffRecord& inRec = head[i];
        const char *iodata = nullptr;
        if (inRec.isNormal()) {
            if (inRec.isCompressed()) {
                uncompressDiffIo(inRec, pack.data(i), rec, array, false);
                iodata = array.data();
            } else {
                rec = inRec;
                iodata = pack.data(i);
            }
        } else {
            rec = inRec;
        }
        issueIo(file, discardType, rec, iodata, zero);
    }
}
开发者ID:walb-linux,项目名称:walb-tools,代码行数:25,代码来源:walb_diff_io.hpp

示例7: LoadFile

/*
	read text data from fileName
*/
inline bool LoadFile(AlignedArray<char>& textBuf, const std::string& fileName)
{
	std::ifstream ifs(fileName.c_str(), std::ios::binary);
	if (!ifs) return false;
	ifs.seekg(0, std::ifstream::end);
	const size_t size = ifs.tellg();
	ifs.seekg(0);
	fprintf(stderr, "size=%d\n", (int)size);
	textBuf.resize(size + 1);
	ifs.read(&textBuf[0], size);
	textBuf[size] = '\0';
	return true;
}
开发者ID:Constellation,项目名称:mie,代码行数:16,代码来源:util.hpp

示例8: dirtyHashSyncClient

inline bool dirtyHashSyncClient(
    packet::Packet &pkt, Reader &reader,
    uint64_t sizeLb, uint64_t bulkLb, uint32_t hashSeed,
    const std::atomic<int> &stopState, const ProcessStatus &ps,
    const std::atomic<uint64_t>& maxLbPerSec)
{
    const char *const FUNC = __func__;
    packet::StreamControl2 recvCtl(pkt.sock());
    packet::StreamControl2 sendCtl(pkt.sock());
    DiffPacker packer;
    walb::PackCompressor compr(::WALB_DIFF_CMPR_SNAPPY);
    cybozu::murmurhash3::Hasher hasher(hashSeed);
    ThroughputStabilizer thStab;

    uint64_t addr = 0;
    uint64_t remainingLb = sizeLb;
    AlignedArray buf;
    size_t cHash = 0, cSend = 0, cDummy = 0;
    try {
    for (;;) {
        if (stopState == ForceStopping || ps.isForceShutdown()) {
            return false;
        }
        dirty_hash_sync_local::doRetrySockIo(4, "ctrl.recv", [&]() { recvCtl.recv(); });
        if (recvCtl.isNext()) {
            if (remainingLb == 0) throw cybozu::Exception(FUNC) << "has next but remainingLb is zero";
        } else {
            if (remainingLb == 0) break;
            throw cybozu::Exception(FUNC) << "no next but remainingLb is not zero" << remainingLb;
        }
        cybozu::murmurhash3::Hash recvHash;
        pkt.read(recvHash);
        cHash++;

        const uint32_t lb = std::min<uint64_t>(remainingLb, bulkLb);
        buf.resize(lb * LOGICAL_BLOCK_SIZE);
        reader.read(buf.data(), buf.size());

        // to avoid socket timeout.
        dirty_hash_sync_local::doRetrySockIo(4, "ctrl.send.dummy", [&]() { sendCtl.sendDummy(); });
        cDummy++; cSend++;

        const cybozu::murmurhash3::Hash bdHash = hasher(buf.data(), buf.size());
        const uint64_t bgnAddr = packer.empty() ? addr : packer.header()[0].io_address;
        if (addr - bgnAddr >= DIRTY_HASH_SYNC_MAX_PACK_AREA_LB && !packer.empty()) {
            dirty_hash_sync_local::doRetrySockIo(4, "ctrl.send.next0", [&]() { sendCtl.sendNext(); });
            cSend++;
            dirty_hash_sync_local::compressAndSend(pkt, packer, compr);
        }
        if (recvHash != bdHash && !packer.add(addr, lb, buf.data())) {
            dirty_hash_sync_local::doRetrySockIo(4, "ctrl.send.next1", [&]() { sendCtl.sendNext(); });
            cSend++;
            dirty_hash_sync_local::compressAndSend(pkt, packer, compr);
            packer.add(addr, lb, buf.data());
        }
        pkt.flush();
        remainingLb -= lb;
        addr += lb;
        thStab.setMaxLbPerSec(maxLbPerSec.load());
        thStab.addAndSleepIfNecessary(lb, 10, 100);
    }
    } catch (...) {
        LOGs.warn() << "SEND_CTL" << cHash << cSend << cDummy;
        throw;
    }
    if (!packer.empty()) {
        dirty_hash_sync_local::doRetrySockIo(4, "ctrl.send.next2", [&]() { sendCtl.sendNext(); });
        cSend++;
        dirty_hash_sync_local::compressAndSend(pkt, packer, compr);
    }
    if (recvCtl.isError()) {
        throw cybozu::Exception(FUNC) << "recvCtl";
    }
    dirty_hash_sync_local::doRetrySockIo(4, "ctrl.send.next2", [&]() { sendCtl.sendEnd(); });
    pkt.flush();

    LOGs.debug() << "SEND_CTL" << cHash << cSend << cDummy;
    return true;
}
开发者ID:walb-linux,项目名称:walb-tools,代码行数:79,代码来源:dirty_hash_sync.hpp

示例9: swap

    // ------------------------------------------------------------------------
    void swap(int ID1, int ID2)
    {
        assert(ID1 > -1);
        assert((unsigned int)ID1 < m_contents_vector.size());
        assert(ID2 > -1);
        assert((unsigned int)ID2 < m_contents_vector.size());


        TYPE* temp = m_contents_vector[ID2];

        m_contents_vector[ID2] = m_contents_vector[ID1];
        m_contents_vector[ID1] = temp;
    }   // swap
开发者ID:krishnabm,项目名称:stk-code,代码行数:14,代码来源:ptr_vector.hpp

示例10: clearAndDeleteAll

    // ------------------------------------------------------------------------
    void clearAndDeleteAll()
    {
        for (unsigned int n=0; n<(unsigned int)m_contents_vector.size(); n++)
        {
            TYPE * pointer = m_contents_vector[n];
            delete pointer;
            m_contents_vector[n] = (TYPE*)0xDEADBEEF;

            // When deleting, it's important that the same pointer cannot be
            // twice in the vector, resulting in a double delete
            assert( !contains(pointer) );
        }
        m_contents_vector.clear();
    }  // clearAndDeleteAll
开发者ID:krishnabm,项目名称:stk-code,代码行数:15,代码来源:ptr_vector.hpp

示例11: get

    // ------------------------------------------------------------------------
    const TYPE* get(const int ID) const
    {
        assert(ID > -1);
        assert((unsigned int)ID < (unsigned int)m_contents_vector.size());

        return m_contents_vector[ID];
    }   // get
开发者ID:krishnabm,项目名称:stk-code,代码行数:8,代码来源:ptr_vector.hpp

示例12: erase

    // ------------------------------------------------------------------------
    void erase(const int ID)
    {
        assert(ID > -1);
        assert((unsigned int)ID < (unsigned int)m_contents_vector.size());

        delete ( TYPE *) m_contents_vector[ID];
#ifdef USE_ALIGNED
        const unsigned int amount = (unsigned int)m_contents_vector.size();
        for(unsigned int i=ID; i<amount-1; i++)
        {
            m_contents_vector[i]=m_contents_vector[i+1];
        }
        m_contents_vector.pop_back();
#else
        m_contents_vector.erase(m_contents_vector.begin()+ID);
#endif
    }   // erase
开发者ID:krishnabm,项目名称:stk-code,代码行数:18,代码来源:ptr_vector.hpp

示例13: getStartTransform

 /** Returns the start coordinates for a kart with a given index.
  *  \param index Index of kart ranging from 0 to kart_num-1. */
 btTransform        getStartTransform (unsigned int index) const
 {
     if (index >= m_start_transforms.size())
     {
         fprintf(stderr, "No start position for kart %i\n", index);
         abort();
     }
     return m_start_transforms[index];
 }
开发者ID:PalashBansal,项目名称:stk-code,代码行数:11,代码来源:track.hpp

示例14: contains

    // ------------------------------------------------------------------------
    bool contains( const TYPE* instance ) const
    {
        const unsigned int amount = (unsigned int)m_contents_vector.size();
        for (unsigned int n=0; n<amount; n++)
        {
            const TYPE * pointer = m_contents_vector[n];
            if (pointer == instance) return true;
        }

        return false;
    }   // contains
开发者ID:krishnabm,项目名称:stk-code,代码行数:12,代码来源:ptr_vector.hpp

示例15: insertionSort

 // ------------------------------------------------------------------------
 void insertionSort(unsigned int start=0, bool desc = false)
 {
     if (!desc)
     {
         // We should not used unsigned ints here, because if the vector is
         // empty j needs to be compared against -1
         for(int j=(int)start; j<(int)m_contents_vector.size()-1; j++)
         {
             if(*(m_contents_vector[j])<*(m_contents_vector[j+1])) continue;
             // Now search the proper place for m_contents_vector[j+1]
             // in the sorted section contentsVectot[start:j]
             TYPE* t=m_contents_vector[j+1];
             unsigned int i = j+1;
             do
             {
                 m_contents_vector[i] = m_contents_vector[i-1];
                 i--;
             } while (i>start && *t<*(m_contents_vector[i-1]));
             m_contents_vector[i]=t;
         }
     }
     else
     {
         for(int j=(int)start; j<(int)m_contents_vector.size()-1; j++)
          {
              if(*(m_contents_vector[j+1])<*(m_contents_vector[j])) continue;
              // Now search the proper place for m_contents_vector[j+1]
              // in the sorted section contentsVectot[start:j]
              TYPE* t=m_contents_vector[j+1];
              unsigned int i = j+1;
              do
              {
                  m_contents_vector[i] = m_contents_vector[i-1];
                  i--;
              } while (i>start && *(m_contents_vector[i-1]) <*t);
              m_contents_vector[i]=t;
          }
      }
 }   // insertionSort
开发者ID:krishnabm,项目名称:stk-code,代码行数:40,代码来源:ptr_vector.hpp


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