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


C++ MyVector::rbegin方法代码示例

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


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

示例1: main

int main(int argc, char *argv[])
{
	if (argc == 1)
	{
		struct shm_remove
		{
			shm_remove()  { shared_memory_object::remove("MySharedMemory"); }
			~shm_remove() { shared_memory_object::remove("MySharedMemory"); }
		} remover;

		// Create a new segment with given name and size
		managed_shared_memory segment(create_only, "MySharedMemory", 65536);

		// Initialize shared memory STL-compatible allocator
		const ShmemAllocator alloc_inst(segment.get_segment_manager());

		// Construct a vector named "MyVector" in shared memory with argument alloc_inst
		MyVector *myvector = segment.construct<MyVector>("MyVector")(alloc_inst);

		for (int i = 0; i < 100; ++i)
		{
			myvector->push_back(i);
		}

		// Launch child process
		std::string s(argv[0]); s += " child ";
		if (0 != std::system(s.c_str()))
			return 1;

		if (segment.find<MyVector>("MyVector").first)
			return 1;
	}
	else
	{
		managed_shared_memory segment(open_only, "MySharedMemory");

		MyVector *myvector = segment.find<MyVector>("MyVector").first;

		std::sort(myvector->rbegin(), myvector->rend());

		segment.destroy<MyVector>("MyVector");
	}

	return 0;
}
开发者ID:kasicass,项目名称:kasicass,代码行数:45,代码来源:STLSharedMem.cpp

示例2: main

int main(int argc, char *argv[])
{
   if(argc == 1){ 
      struct shm_remove
      {
         shm_remove() { shared_memory_object::remove("MySharedMemory"); }
         ~shm_remove(){ shared_memory_object::remove("MySharedMemory"); }
      } remover;

      managed_shared_memory segment(create_only, "MySharedMemory", 65536);

      const ShmemAllocator alloc_inst (segment.get_segment_manager());

      MyVector *myvector = segment.construct<MyVector>("MyVector")(alloc_inst);

      for(int i = 0; i < 100; ++i)  //Insert data in the vector
         myvector->push_back(i);

      std::string s(argv[0]); s += " child ";
      if(0 != std::system(s.c_str()))
         return 1;

      if(segment.find<MyVector>("MyVector").first)
         return 1;
   }
   else{ 
      managed_shared_memory segment(open_only, "MySharedMemory");
      MyVector *myvector = segment.find<MyVector>("MyVector").first;
      std::sort(myvector->rbegin(), myvector->rend());
      for(int i = 0; i < 100; ++i)  //Insert data in the vector
      {
        printf("%d ", myvector->at(i));
      }
      segment.destroy<MyVector>("MyVector");
   }

   return 0;
};
开发者ID:Daiver,项目名称:scripts,代码行数:38,代码来源:main.cpp

示例3: main

//Main function. For parent process argc == 1, for child process argc == 2
int main(int argc, char *argv[])
{
   if(argc == 1){ //Parent process
      //Remove shared memory on construction and destruction
      struct shm_remove
      {
      //<-
      #if 1
         shm_remove() { shared_memory_object::remove(test::get_process_id_name()); }
         ~shm_remove(){ shared_memory_object::remove(test::get_process_id_name()); }
      #else
      //->
         shm_remove() { shared_memory_object::remove("MySharedMemory"); }
         ~shm_remove(){ shared_memory_object::remove("MySharedMemory"); }
      //<-
      #endif
      //->
      } remover;
      //<-
      (void)remover;
      //->

      //Create a new segment with given name and size
      //<-
      #if 1
      managed_shared_memory segment(create_only, test::get_process_id_name(), 65536);
      #else
      //->
      managed_shared_memory segment(create_only, "MySharedMemory", 65536);
      //<-
      #endif
      //->

      //Initialize shared memory STL-compatible allocator
      const ShmemAllocator alloc_inst (segment.get_segment_manager());

      //Construct a vector named "MyVector" in shared memory with argument alloc_inst
      MyVector *myvector = segment.construct<MyVector>("MyVector")(alloc_inst);

      for(int i = 0; i < 100; ++i)  //Insert data in the vector
         myvector->push_back(i);

      //Launch child process
      std::string s(argv[0]); s += " child ";
      //<-
      s += test::get_process_id_name();
      //->
      if(0 != std::system(s.c_str()))
         return 1;

      //Check child has destroyed the vector
      if(segment.find<MyVector>("MyVector").first)
         return 1;
   }
   else{ //Child process
      //Open the managed segment
      //<-
      #if 1
      managed_shared_memory segment(open_only, argv[2]);
      #else
      //->
      managed_shared_memory segment(open_only, "MySharedMemory");
      //<-
      #endif
      //->

      //Find the vector using the c-string name
      MyVector *myvector = segment.find<MyVector>("MyVector").first;

      //Use vector in reverse order
      std::sort(myvector->rbegin(), myvector->rend());

      //When done, destroy the vector from the segment
      segment.destroy<MyVector>("MyVector");
   }

   return 0;
};
开发者ID:OggYiu,项目名称:rag-engine,代码行数:79,代码来源:doc_spawn_vector.cpp


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