本文整理汇总了C++中Queue::Clear方法的典型用法代码示例。如果您正苦于以下问题:C++ Queue::Clear方法的具体用法?C++ Queue::Clear怎么用?C++ Queue::Clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Queue
的用法示例。
在下文中一共展示了Queue::Clear方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
// This program tests the relative speeds of various object allocation strategies.
int main(int argc, char ** argv)
{
CompleteSetupSystem css; // required!
const uint32 NUM_OBJECTS = 10000000;
Queue<MessageRef> tempQ;
if (tempQ.EnsureSize(NUM_OBJECTS, true) != B_NO_ERROR) return 10;
int whichTest = (argc>1) ? atoi(argv[1]) : -1;
uint64 startTime = GetRunTime64();
switch(whichTest)
{
case 1:
{
// See how long it takes to allocate an array of objects
(void) new Message[NUM_OBJECTS];
}
break;
case 2:
{
// As above, but with deletion also
delete [] new Message[NUM_OBJECTS];
}
break;
case 3:
{
// See how long it takes to allocate each object individually
for (uint32 i=0; i<NUM_OBJECTS; i++) tempQ[i].SetRef(new Message);
}
break;
case 4:
{
// As above, but we delete the item after allocating it
for (uint32 i=0; i<NUM_OBJECTS; i++) tempQ[i].SetRef(new Message);
for (uint32 i=0; i<NUM_OBJECTS; i++) tempQ[i].Reset();
}
break;
case 5:
{
// See how long it takes to allocate each object individually
for (uint32 i=0; i<NUM_OBJECTS; i++) tempQ[i] = GetMessageFromPool();
}
break;
case 6:
{
// As above, but then we clear the queue
for (uint32 i=0; i<NUM_OBJECTS; i++) tempQ[i] = GetMessageFromPool();
tempQ.Clear();
}
break;
case 7:
{
// As above, but we only use one object at a time
for (uint32 i=0; i<NUM_OBJECTS; i++) (void) GetMessageFromPool();
}
break;
default:
printf("Usage: testpools <testnum> (where testnum is between 1 and 6)\n");
break;
}
uint64 endTime = GetRunTime64();
printf("Test duration for " UINT32_FORMAT_SPEC " objects was " UINT64_FORMAT_SPEC "ms \n", NUM_OBJECTS, (endTime-startTime)/1000);
if ((argc > 2)&&(strcmp(argv[2], "hold") == 0))
{
printf("Holding indefinitely, so that you can look at OS reported memory usage...\n");
while(1) Snooze64(SecondsToMicros(10));
}
return 0;
}
示例2: main
//.........这里部分代码省略.........
printf("INSERTITEMAT TEST\n");
{
for (int i=0; i<testSize; i++)
{
TEST(q.InsertItemAt(i,i));
PrintToStream(q);
}
}
printf("REMOVEITEMAT TEST\n");
{
for (int i=0; i<testSize; i++)
{
TEST(q.RemoveItemAt(i));
PrintToStream(q);
}
}
// Check that C++11's move semantics aren't stealing values they shouldn't
{
Queue<String> q;
String myStr = "Magic";
q.AddTail(myStr);
if (myStr != "Magic")
{
printf("Error, AddTail() stole my string!\n");
exit(10);
}
}
printf("SORT TEST 1\n");
{
q.Clear();
for (int i=0; i<testSize; i++)
{
int next = rand()%255;
TEST(q.AddTail(next));
printf("Added item %i = %i\n", i, q[i]);
}
printf("sorting ints...\n");
q.Sort();
for (int j=0; j<testSize; j++) printf("Now item %i = %i\n", j, q[j]);
}
printf("SORT TEST 2\n");
{
Queue<String> q2;
for (int i=0; i<testSize; i++)
{
int next = rand()%255;
char buf[64];
sprintf(buf, "%i", next);
TEST(q2.AddTail(buf));
printf("Added item %i = %s\n", i, q2[i].Cstr());
}
printf("sorting strings...\n");
q2.Sort();
for (int j=0; j<testSize; j++) printf("Now item %i = %s\n", j, q2[j].Cstr());
}
printf("REMOVE DUPLICATES test\n");
{
Queue<int> q;
const int vars[] = {9,2,3,5,8,3,5,6,6,7,2,3,4,6,8,9,3,5,6,4,3,2,1};
if (q.AddTailMulti(vars, ARRAYITEMS(vars)) == B_NO_ERROR)