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


C++ MemoryBlock::put方法代码示例

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


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

示例1: loadData

void FileManager::loadData(const std::string & formatFile)
{
  std::ifstream pageFormat(formatFile.c_str());
  std::string tableName;
  int bufferLoc = 0;
  std::string pgSize;
  std::getline(pageFormat, pgSize);
  m_pageSize = atoi(pgSize.c_str());
  while(!std::getline(pageFormat, tableName).eof())
  {
    std::string numPartitions;
    std::string numFields;
    std::string numRecords;
    std::string numBytesPerRecord;
    std::getline(pageFormat, numPartitions, '|');
    std::getline(pageFormat, numFields, '|');
    std::getline(pageFormat, numRecords, '|');
    std::getline(pageFormat, numBytesPerRecord);
    int nPartitions = atoi(numPartitions.c_str());
    int nFields = atoi(numFields.c_str());
    int nRecords = atoi(numRecords.c_str());
    int nBytesPerRecord = atoi(numBytesPerRecord.c_str());
    int recordsPerPage = m_pageSize/nBytesPerRecord;
    int currentStart = 0;
    int* startPositions = new int[nPartitions];
    int* currentPositions = new int[nPartitions];
    int* FtoPMap = new int[nFields];
    int* FtoBMap = new int[nFields];
    int* FtoLMap = new int[nFields];
    int* PtoBMap = new int[nPartitions];
    int* PtoLMap = new int[nPartitions];
    for (int i = 0; i < nPartitions; i++)
    {
      int fLoc = 0;
      startPositions[i] = currentStart;
      currentPositions[i] = currentStart;
      std::string numFtoP;
      std::string numPBytes;
      std::getline(pageFormat, numFtoP, '|');
      int nFtoP = atoi(numFtoP.c_str());
      std::getline(pageFormat, numPBytes);
      int nPBytes = atoi(numPBytes.c_str());
      PtoLMap[i] = currentStart;
      currentStart += nPBytes*recordsPerPage;
      PtoBMap[i] = nPBytes;
      for (int j = 0; j < nFtoP; j++)
      {
	std::string field;
        std::string bytes;
        std::getline(pageFormat,field, '|');
        std::getline(pageFormat,bytes);
        int fieldNum = atoi(field.c_str());
        int fieldBytes = atoi(bytes.c_str());
        FtoPMap[fieldNum] = i;
        FtoBMap[fieldNum] = fieldBytes;
        FtoLMap[fieldNum] = fLoc;
        fLoc += fieldBytes;
      }
    }

    
    PageLayout * a = new PageLayout(nPartitions, nFields, nBytesPerRecord, FtoPMap, FtoBMap, FtoLMap, PtoLMap, PtoBMap);
    
    std::ifstream table(tableName.c_str(), std::ios::in | std::ios::binary);
    int nRecs = 0;
    std::list<int> * pages = new std::list<int>();
    MemoryBlock * data = new MemoryBlock(m_pageSize);
    char * holder = new char[recordsPerPage*nBytesPerRecord];

    for(int k = 0; k < nRecords;)
    {
      int recordsRead = 0;
      if ((nRecords - k) < recordsPerPage)
      {
        recordsRead = nRecords-k;
      }
      else
      {
        recordsRead = recordsPerPage;
      }
    
      table.read(holder,recordsRead*nBytesPerRecord);
      k+= recordsRead;
      
      int hOffset = 0;
      for (int r = 0; r < recordsRead; r++)
      {
        for (int z = 0; z < nFields; z++)
        {
	 
          int fB = FtoBMap[z];
          int currentPartition = FtoPMap[z];
          int writeLocation = currentPositions[currentPartition];
	
 
          data->put((byte*)holder + hOffset, writeLocation, fB);
	
	  currentPositions[currentPartition] = writeLocation + fB;

          hOffset += fB;
//.........这里部分代码省略.........
开发者ID:Adamanthil,项目名称:DBCacheBenchmarking,代码行数:101,代码来源:FileManager.cpp


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