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


C++ DataBlock类代码示例

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


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

示例1: LNE_ASSERT_RETURN_VOID

void SockSpray::Send(DataBlock *blocks[], LNE_UINT count)
{
    LNE_ASSERT_RETURN_VOID(blocks != NULL && count > 0);
    bool to_handle = true;
    // ignore when shutdown
    shutdown_lock_.Lock();
    if(shutdown_state_.already || shutdown_state_.query)
        to_handle = false;
    shutdown_lock_.Unlock();
    if(!to_handle)
        return;
    // append to queue
    DataBlock *block;
    send_lock_.Lock();
    for(LNE_UINT i = 0; to_handle && i < count; ++i) {
        block = blocks[i];
        block->AddRef();
        if(send_blocks_.Append(block) != LNERR_OK) {
            block->Release();
            to_handle = false;
        } else if(send_blocks_.count() > limit_write_cache_)
            to_handle = false;
    }
    if(!to_handle) {
        shutdown_lock_.Lock();
        shutdown_state_.query = true;
        shutdown_lock_.Unlock();
    }
    send_lock_.Unlock();
    if(to_handle)
        __HandleWrite();
}
开发者ID:breezechen,项目名称:lne,代码行数:32,代码来源:SockSpray.cpp

示例2: AssertFatal

void *DataChunker::alloc(S32 size)
{
   if (size > mChunkSize)
   {
      DataBlock * temp = (DataBlock*)dMalloc(DataChunker::PaddDBSize + size);
      AssertFatal(temp, "Malloc failed");
      constructInPlace(temp);
      if (mCurBlock)
      {
         temp->next = mCurBlock->next;
         mCurBlock->next = temp;
      }
      else
      {
         mCurBlock = temp;
         temp->curIndex = mChunkSize;
      }
      return temp->getData();
   }

   if(!mCurBlock || size + mCurBlock->curIndex > mChunkSize)
   {
      const U32 paddDBSize = (sizeof(DataBlock) + 3) & ~3;
      DataBlock *temp = (DataBlock*)dMalloc(paddDBSize+ mChunkSize);
      AssertFatal(temp, "Malloc failed");
      constructInPlace(temp);
      temp->next = mCurBlock;
      mCurBlock = temp;
   }
   
   void *ret = mCurBlock->getData() + mCurBlock->curIndex;
   mCurBlock->curIndex += (size + 3) & ~3; // dword align
   return ret;
}
开发者ID:Azaezel,项目名称:Torque3D,代码行数:34,代码来源:dataChunker.cpp

示例3: fixEndian

// Convert endiannes
bool RadioDataFile::fixEndian(DataBlock& buf, unsigned int bytes)
{
    if (!bytes)
    return false;
    unsigned int n = buf.length() / bytes;
    if (bytes == 2) {
    for (uint16_t* p = (uint16_t*)buf.data(); n; n--, p++)
#ifdef LITTLE_ENDIAN
        *p = be16toh(*p);
#else
        *p = le16toh(*p);
#endif
    return true;
    }
    if (bytes == 4) {
    for (uint32_t* p = (uint32_t*)buf.data(); n; n--, p++)
#ifdef LITTLE_ENDIAN
        *p = be32toh(*p);
#else
        *p = le32toh(*p);
#endif
    return true;
    }
    if (bytes == 8) {
    for (uint64_t* p = (uint64_t*)buf.data(); n; n--, p++)
#ifdef LITTLE_ENDIAN
        *p = be64toh(*p);
#else
        *p = le64toh(*p);
#endif
    return true;
    }
    return false;
}
开发者ID:0x7678,项目名称:evilbts,代码行数:35,代码来源:radio.cpp

示例4: TEST

TEST(TestFileReader,readSmallFile){
    string path = "/tmp/small.txt";
    ofstream outfile (path.c_str(),std::ofstream::binary);
    FileReader * fr;
    DataBlock * block;
    char data[]="0123456789";
    // Creo un archivo de pruebas: 10 bytes * 10k = 100k
    for(int i=0; i<10000;i++)
        outfile.write((char*)&data,10);
    outfile.close();

    fr = new FileReader(path);
    ASSERT_TRUE(fr->hasBlocksLeft());
    block = fr->getBlock();
    //blockSize = 16k  (7 bloques)
    ASSERT_EQ(block->getSizeInBytes(),16384);
    vector<unsigned char>::iterator it = block->getIterator();
    unsigned char c = '0';
    for(int i=0; i<10;i++){
        ASSERT_EQ(c,*it);
        c+=1;
        it++;
    }
    for(int i=0;i<6;i++){
        ASSERT_TRUE(fr->hasBlocksLeft());
        delete block;
        block = fr->getBlock();
    }
    ASSERT_FALSE(fr->hasBlocksLeft());
    ASSERT_EQ(block->getSizeInBytes(),1696);
    delete block;
    delete fr;
}
开发者ID:awainer,项目名称:datos2014,代码行数:33,代码来源:test_filereader.cpp

示例5: getData

fulliautomatix_data* AsterixData::getData()
{
  fulliautomatix_data *firstData=NULL,*lastData=NULL;
  int byteoffset = 0;

  std::list<DataBlock*>::iterator it;
  for ( it=m_lDataBlocks.begin() ; it != m_lDataBlocks.end(); it++ )
  {
    DataBlock* db = (DataBlock*)(*it);
    if (db != NULL)
    {
      if (!lastData)
      {
        firstData = lastData = db->getData(byteoffset);
      }
      else
      {
        lastData->next = db->getData(byteoffset);
      }
      while(lastData->next)
      {
        lastData = lastData->next;
      }
      byteoffset = lastData->bytenr + lastData->length;
    }
  }
  return firstData;
}
开发者ID:bbertrand,项目名称:asterix,代码行数:28,代码来源:AsterixData.cpp

示例6: GetBlock

/*
 * zmienianie zawartosci pliku
 */
bool Inode::SetData(std::string text)
{
    for(unsigned int i = 0; i < this->i_blocks; i++)
    {
        DataBlock *blockData = GetBlock(i);
        if(!blockData->setData(text.substr(i * Synchro::blockSize).c_str()) == true)
            return false;
    }

    // gdy zakonczy sie powodzeniem
    return true;
}
开发者ID:Keraxel,项目名称:LinuxBlockAllocation,代码行数:15,代码来源:Inode.cpp

示例7: rxData

// Break received audio data into manageable chunks, forward them to decoder
void FaxTerminal::rxData(const DataBlock& data, unsigned long tStamp)
{
    unsigned int pos = 0;
    while (pos < data.length())
    {
    // feed the decoder with small chunks of data (16 bytes/ms)
    int len = data.length() - pos;
    if (len > FAX_DATA_CHUNK)
        len = FAX_DATA_CHUNK;
    rxBlock(((char *)data.data())+pos, len);
    pos += len;
    }
}
开发者ID:mehulsbhatt,项目名称:yate,代码行数:14,代码来源:faxchan.cpp

示例8: mprinterr

// CIFfile::AddDataBlock()
int CIFfile::AddDataBlock( DataBlock const& block ) {
  if (block.Header().empty()) {
    mprinterr("Internal Error: Attempting to add empty CIF data block.\n");
    return 1;
  }
  CIF_DataType::const_iterator it = cifdata_.find( block.Header() );
  if (it != cifdata_.end()) {
    mprinterr("Error: Duplicate CIF block found: '%s'\n", block.Header().c_str());
    return 1;
  }
  cifdata_.insert( std::pair<std::string, DataBlock>(block.Header(), block) );
  return 0;
}
开发者ID:Amber-MD,项目名称:cpptraj,代码行数:14,代码来源:CIFfile.cpp

示例9: append

void Column::append(int rows)
{
    if (rows == 0)
        return;

    BlockMap::reverse_iterator itr = _blocks.rbegin();

    if (itr == _blocks.rend()) // no blocks
    {
        ull firstId = DataBlock::capacity();
        DataBlock *firstBlock = _mem->construct<DataBlock>(anonymous_instance)();

        _blocks.insert(BlockEntry(firstId, firstBlock));
        itr = _blocks.rbegin();
    }

    BlockEntry entry = *itr;
    DataBlock *block = entry.second.get();
    ull id = entry.first;

    int room = DataBlock::capacity() - block->rowCount();
    int rowsLeft = rows - room;
    if (rowsLeft <= 0)
    {
        block->insert(block->rowCount(), rows);
        _rowCount += rows;
        return;
    }

    block->insert(block->rowCount(), room);
    _rowCount += room;

    int newBlocksRequired = rowsLeft / DataBlock::capacity();
    if (rowsLeft % DataBlock::capacity())
        newBlocksRequired++;

    for (int i = 0; i < newBlocksRequired; i++)
    {
        try {

        DataBlock *newBlock = _mem->construct<DataBlock>(anonymous_instance)();

        int toInsert = std::min(rowsLeft, DataBlock::capacity());
        newBlock->insert(0, toInsert);
        rowsLeft -= toInsert;

        id += DataBlock::capacity();
        _blocks.insert(BlockEntry(id, newBlock));

        _rowCount += toInsert;

        }
        catch (boost::interprocess::bad_alloc &e)
        {
            cout << e.what();
            cout << "setRowCount" << _rowCount << "\n";
            throw;
        }
    }
}
开发者ID:MaxG87,项目名称:jasp-desktop,代码行数:60,代码来源:column.cpp

示例10: define

void DNN::define(const char* filename)
{

    DataBlock data;
    data.load(filename);

    strvec layers = split(data("layers"),',');

    std::cout << "We have " << layers.size() << " layers\n";

    activations.resize(layers.size());
    weights.resize(layers.size()-1);
    bias.resize(layers.size()-1);

    unsigned int i;

    for(i=0;i<layers.size();++i)
    {

        unsigned int num_neurons = atof(layers[i].c_str());

        activations[i] = Matrix(num_neurons,1,0.0f);

        if(i > 0)
        {

            weights[i-1] = Matrix(activations[i].rows(),
                                  activations[i-1].rows(),
                                  1.0f);

            bias[i-1]    = Matrix(activations[i].rows(),1,1.0f);

        }

    }

    for(i=0;i<layers.size();++i)
    {
        std::cout << activations[i].rows() << " inputs in layer " << i << "\n";
    }

    for(i=0;i<layers.size()-1;++i)
    {
        std::cout << "Weight matrix dimensions: " << weights[i].rows() << " " << weights[i].cols();
        std::cout << " in layer " << i << "\n";
    }

    learningRate = atof(data("learning_rate").c_str());

}
开发者ID:kSkip,项目名称:free-time,代码行数:50,代码来源:DNN.cpp

示例11: TestClient

LNE_NAMESPACE_USING

void TestClient()
{
    TimeValue tv(3);
    SockAddr addr("www.google.com:80");
    SockConnector *connector = SockConnector::NewInstance(addr, &tv);
    if(connector == NULL) {
        printf("connector cannot create\n");
        return;
    }
    SockPad skpad;
    if(connector->Connect(skpad) != LNERR_OK) {
        printf("connector cannot connect\n");
        connector->Release();
        return;
    }
    SockWaves *stream = SockWaves::NewInstance(skpad);
    const char *query = "GET / HTTP/1.1\r\n\r\n";
    DataBlock *block = DataBlock::NewInstance(1024 * 1024);
    strcpy(block->buffer(), query);
    block->set_size(static_cast<LNE_UINT>(strlen(block->buffer())));
    stream->Send(block);
    while(stream->Recv(block, tv) == LNERR_OK) {
        block->buffer()[block->size()] = '\0';
        puts(block->buffer());
    }
    block->Release();
    SockAddr addr_sock, addr_peer;
    stream->GetSockAddr(addr_sock);
    stream->GetPeerAddr(addr_peer);
    printf("connect %s => %s\n", addr_sock.addr_text(), addr_peer.addr_text());
    stream->Release();
    connector->Release();
}
开发者ID:breezechen,项目名称:lne,代码行数:35,代码来源:TestClient.cpp

示例12: clock

void ParameterLoader<T>::ParseAndRequest(multiverso::DataBlockBase *data_block)
{
    if (m_parse_and_request_count == 0)
    {
        m_start_time = clock();
    }

    fprintf(m_log_file, "%lf\n", (clock() - m_start_time) / (double)CLOCKS_PER_SEC);
    multiverso::Log::Info("Rank %d ParameterLoader begin %d\n", multiverso::Multiverso::ProcessRank(), m_parse_and_request_count);
    DataBlock *data = reinterpret_cast<DataBlock*>(data_block);

    SkipGramMixtureNeuralNetwork<T>* sg_mixture_neural_network = reinterpret_cast<SkipGramMixtureNeuralNetwork<T>*>(m_sgmixture_neural_networks[m_parse_and_request_count % 2]);
    ++m_parse_and_request_count;
    data->UpdateNextRandom();
    sg_mixture_neural_network->PrepareParmeter(data);

    std::vector<int>& input_layer_nodes = sg_mixture_neural_network->GetInputLayerNodes();
    std::vector<int>& output_layer_nodes = sg_mixture_neural_network->GetOutputLayerNodes();
    assert(sg_mixture_neural_network->status == 0);
    sg_mixture_neural_network->status = 1;

    for (int i = 0; i < input_layer_nodes.size(); ++i)
    {
        int word_id = input_layer_nodes[i];
        for (int j = 0; j < m_words_sense_info->word_sense_cnts_info[word_id]; ++j)
            RequestRow(kInputEmbeddingTableId, m_words_sense_info->p_input_embedding[word_id] + j);
    }

    for (int i = 0; i < output_layer_nodes.size(); ++i)
        RequestRow(kEmbeddingOutputTableId, output_layer_nodes[i]);

    RequestRow(kWordCountActualTableId, 0);

    for (int i = 0; i < input_layer_nodes.size(); ++i)
    {
        int word_id = input_layer_nodes[i];
        if (m_words_sense_info->word_sense_cnts_info[word_id] > 1)
            RequestRow(kWordSensePriorTableId, m_words_sense_info->p_wordidx2sense_idx[word_id]);
    }

    std::vector<int> & tables = data->GetTables();
    for (int i = 0; i < tables.size(); ++i)
        RequestTable(tables[i]);

    multiverso::Log::Info("Rank %d ParameterLoader finish %d\n", multiverso::Multiverso::ProcessRank(), m_parse_and_request_count - 1);
    fprintf(m_log_file, "%lf\n", (clock() - m_start_time) / (double)CLOCKS_PER_SEC);
    assert(sg_mixture_neural_network->status == 1);
    sg_mixture_neural_network->status = 2;
}
开发者ID:UNIVERSAL-IT-SYSTEMS,项目名称:distributed_skipgram_mixture,代码行数:49,代码来源:param_loader.cpp

示例13: PyList_New

PyObject* AsterixData::getData()
{
    PyObject* hp = PyList_New(0);

    std::list<DataBlock*>::iterator it;
    for ( it=m_lDataBlocks.begin() ; it != m_lDataBlocks.end(); it++ )
    {
        DataBlock* db = (DataBlock*)(*it);
        if (db != NULL)
        {
            db->getData(hp);
        }
    }
    return hp;
}
开发者ID:bbertrand,项目名称:asterix,代码行数:15,代码来源:AsterixData.cpp

示例14: Consume

unsigned long FaxConsumer::Consume(const DataBlock& data, unsigned long tStamp, unsigned long flags)
{
    if (data.null() || !m_wrap)
    return 0;
    m_wrap->rxData(data,tStamp);
    return invalidStamp();
}
开发者ID:mehulsbhatt,项目名称:yate,代码行数:7,代码来源:faxchan.cpp

示例15: read

// Read a record from file
bool RadioDataFile::read(uint64_t& ts, DataBlock& buffer, DebugEnabler* dbg, int* error)
{
    int e = 0;
    if (error)
    *error = 0;
    else
    error = &e;
    uint8_t hdr[12];
    int rd = m_file.readData(hdr,sizeof(hdr));
    // EOF ?
    if (rd == 0) {
    buffer.resize(0);
    return true;
    }
    if (rd != sizeof(hdr))
    return ioError(false,dbg,error,rd > 0 ? "Incomplete read (invalid size?)" : 0);
    uint32_t len = 0;
    uint32_t* u = (uint32_t*)hdr;
    if (m_littleEndian == m_header.m_littleEndian)
    len = *u;
    else if (m_littleEndian)
    len = be32toh(*u);
    else
    len = le32toh(*u);
    uint64_t* p = (uint64_t*)&hdr[4];
    if (m_littleEndian == m_header.m_littleEndian)
    ts = *p;
    else if (m_littleEndian)
    len = be64toh(*p);
    else
    len = le64toh(*p);
    buffer.resize(len);
    if (!len)
    return ioError(false,dbg,0,"Empty record");
    rd = m_file.readData((void*)buffer.data(),len);
    if (rd != (int)len)
    return ioError(false,dbg,error,rd > 0 ? "Incomplete read (invalid size?)" : 0);
#ifdef XDEBUG
    String sHdr, s;
    sHdr.hexify(hdr,sizeof(hdr),' ');
    s.hexify((void*)buffer.data(),rd,' ');
    Debug(dbg,DebugAll,"RadioDataFile[%s] read %d hdr=%s data=%s [%p]",
    c_str(),rd + (int)sizeof(hdr),sHdr.c_str(),s.c_str(),this);
#endif
    return true;
}
开发者ID:0x7678,项目名称:evilbts,代码行数:47,代码来源:radio.cpp


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