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


C++ SharedMemory::DeleteArea方法代码示例

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


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

示例1: main

// This program exercises the Message class.
int main(int argc, char ** argv) 
{
   bool deleteArea = ((argc > 1)&&(strncmp(argv[1], "del", 3) == 0));

   uint8 base = 0;
   LogTime(MUSCLE_LOG_INFO, deleteArea ? "Deleting shared memory area!\n" : "Beginning shared memory test!\n");

   SharedMemory m;
   if (m.SetArea(TEST_KEY, TEST_AREA_SIZE, true) == B_NO_ERROR)
   {
      if (deleteArea) LogTime(MUSCLE_LOG_INFO, "Deletion of area %s %s\n", m.GetAreaName()(), (m.DeleteArea() == B_NO_ERROR) ? "succeeded" : "failed");
      else
      {
         uint8 * a = m.GetAreaPointer();
         uint32 s = m.GetAreaSize();

         if (m.IsCreatedLocally()) 
         {
            LogTime(MUSCLE_LOG_INFO, "Created new shared memory area %s\n", m.GetAreaName()());
            for (uint32 i=0; i<s; i++) a[i] = base;
         }
         else LogTime(MUSCLE_LOG_INFO, "Found existing shared memory area %s\n", m.GetAreaName()());

         LogTime(MUSCLE_LOG_INFO, "Area is " UINT32_FORMAT_SPEC " bytes long, starting at address %p\n", s, a);

         m.UnlockArea();

         uint64 lastTime = 0;
         while(1)
         {
            if (OnceEvery(MICROS_PER_SECOND, lastTime)) LogTime(MUSCLE_LOG_INFO, "Still going... base=%u\n", base);

            // Test out the read/write exclusive lock
            if (m.LockAreaReadWrite() == B_NO_ERROR)
            {
               uint32 s = m.GetAreaSize();
               if (s > 0)
               {
                  uint8 * a = m.GetAreaPointer();
                  {for (uint32 i=1; i<s; i++) if (a[i-1] != a[i]) LogTime(MUSCLE_LOG_ERROR, "A. [email protected]" UINT32_FORMAT_SPEC "\n",i);}
                  {for (uint32 i=0; i<s; i++) a[i] = base;}
                  {for (uint32 i=0; i<s; i++) if (a[i] != base) LogTime(MUSCLE_LOG_ERROR, "B. [email protected]" UINT32_FORMAT_SPEC "\n",i);}
               }
               else LogTime(MUSCLE_LOG_ERROR, "Area size is zero!?\n");

               m.UnlockArea();
            }
            else 
            {
               LogTime(MUSCLE_LOG_ERROR, "Exclusive Lock failed!  Maybe the area was deleted!\n");
               break;
            }

            // Also test out the read-only lock
            if (m.LockAreaReadOnly() == B_NO_ERROR)
            {
               uint32 s = m.GetAreaSize();
               if (s > 0)
               {
                  const uint8 * a = m.GetAreaPointer();
                  {for (uint32 i=1; i<s; i++) if (a[i-1] != a[i]) LogTime(MUSCLE_LOG_ERROR, "C. [email protected]" UINT32_FORMAT_SPEC "\n",i);}
               }
               else LogTime(MUSCLE_LOG_ERROR, "Area size is zero!?\n");

               m.UnlockArea();
            }
            else 
            {
               LogTime(MUSCLE_LOG_ERROR, "Read-Only Lock failed!  Maybe the area was deleted!\n");
               break;
            }

            base++;
         }
      }
   }
   else LogTime(MUSCLE_LOG_ERROR, "SetArea() failed, exiting!\n");

   return 0;
}
开发者ID:ruurdadema,项目名称:muscle,代码行数:81,代码来源:testsharedmem.cpp


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