Caffe源码中各种依赖库的作用及简单使用(4)

printf("Deleting with cursor\n");
 E(mdb_txn_begin(env, NULL, 0, &txn));
 E(mdb_cursor_open(txn, dbi, &cur2));
 for (i = 0; i<50; i++) {
  if (RES(MDB_NOTFOUND, mdb_cursor_get(cur2, &key, &data, MDB_NEXT)))
   break;
  printf("key: %p %.*s, data: %p %.*s\n",
   key.mv_data, (int)key.mv_size, (char *)key.mv_data,
   data.mv_data, (int)data.mv_size, (char *)data.mv_data);
  E(mdb_del(txn, dbi, &key, NULL));
 }

printf("Restarting cursor in txn\n");
 for (op = MDB_FIRST, i = 0; i <= 32; op = MDB_NEXT, i++) {
  if (RES(MDB_NOTFOUND, mdb_cursor_get(cur2, &key, &data, op)))
   break;
  printf("key: %p %.*s, data: %p %.*s\n",
   key.mv_data, (int)key.mv_size, (char *)key.mv_data,
   data.mv_data, (int)data.mv_size, (char *)data.mv_data);
 }
 mdb_cursor_close(cur2);
 E(mdb_txn_commit(txn));

printf("Restarting cursor outside txn\n");
 E(mdb_txn_begin(env, NULL, 0, &txn));
 E(mdb_cursor_open(txn, dbi, &cursor));
 for (op = MDB_FIRST, i = 0; i <= 32; op = MDB_NEXT, i++) {
  if (RES(MDB_NOTFOUND, mdb_cursor_get(cursor, &key, &data, op)))
   break;
  printf("key: %p %.*s, data: %p %.*s\n",
   key.mv_data, (int)key.mv_size, (char *)key.mv_data,
   data.mv_data, (int)data.mv_size, (char *)data.mv_data);
 }
 mdb_cursor_close(cursor);
 mdb_txn_abort(txn);

mdb_dbi_close(env, dbi);
 mdb_env_close(env);

return 0;
}

void ListMsg(const lm::helloworld& msg) {
 std::cout << msg.id() << std::endl;
 std::cout << msg.str() << std::endl;
}

int test_ProtoBuf()
{
 //http://www.ibm.com/developerworks/cn/linux/l-cn-gpb/
 //http://blog.163.com/jiang_tao_2010/blog/static/12112689020114305013458/
 //http://www.cnblogs.com/dkblog/archive/2012/03/27/2419010.html
 // 1-->首先编写一个ml.helloworld.proto文件,内容如下:
 /*
 syntax = "proto2";
 package lm;

message helloworld
 {
  required int32    id = 1;  // ID
  required string    str = 2;  // str
  optional int32    opt = 3;  //optional field
 }
 */

// 2-->利用protoc.exe生成ml.helloworld.pb.h和ml.hellowrold.ph.cc

// 3-->Writer,将把一个结构化数据写入磁盘,以便其他人来读取
 /*lm::helloworld msg1;
 msg1.set_id(101);
 msg1.set_str("hello");

// Write the new address book back to disk.
 std::fstream output("./log", std::ios::out | std::ios::trunc | std::ios::binary);
 if (!msg1.SerializeToOstream(&output)) {
  std::cerr << "Failed to write msg." << std::endl;
  return -1;
 }*/

// 4-->Reader,读取结构化数据,log文件
 lm::helloworld msg2;
 
 std::fstream input("./log", std::ios::in | std::ios::binary);
 if (!msg2.ParseFromIstream(&input)) {
  std::cerr << "Failed to parse address book." << std::endl;
  return -1;
 }

ListMsg(msg2);

return 0;
}

#define H5FILE_NAME  "E:/tmp/HDF5/SDS.h5"
#define DATASETNAME  "IntArray"
#define NX   5 /* dataset dimensions */
#define NY   6
#define RANK   2

int test_HDF5_write_HDF5_Data()
{
 hid_t      file, dataset;        /* file and dataset handles */
 hid_t      datatype, dataspace;  /* handles */
 hsize_t    dimsf[2];              /* dataset dimensions */
 herr_t      status;
 int        data[NX][NY];          /* data to write */
 int        i, j;

//Data  and output buffer initialization.
 for (j = 0; j < NX; j++)
  for (i = 0; i < NY; i++)
   data[j][i] = i + j + 100;//changed
 /*
 * 0 1 2 3 4 5
 * 1 2 3 4 5 6
 * 2 3 4 5 6 7
 * 3 4 5 6 7 8
 * 4 5 6 7 8 9
 */

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/b4757544dc3cf42f4c437584fa8527cf.html