How to delete a STXXL priority queue?

131 views Asked by At

I created a STXXL priority queue in my program. If I do not need the PQ any more, how to delete it? Just like delete[] buffer in C++. I want to free the memory used by it.

I looked through their examples and description, but I cannot find the way. Once a PQ is created, will the memory be occupied by this PQ until the end of the program?

For example, if I define two priority queues: Q1 and Q2.

typedef stxxl::PRIORITY_QUEUE_GENERATOR <
   SufNode<unsigned char>,
   ComparatorGreater<unsigned char>,
   mem*1024*1024, 1024*1024
 >::result pqueue_type0;

 pqueue_type0 Q1(pool1); 

Then I do something with Q1, then delete it, so I can allocate more memory for Q2.

typedef stxxl::PRIORITY_QUEUE_GENERATOR<
   SufNode<unsigned char>,
   ComparatorGreater2<unsigned char>,
   mem*1024*1024, 1024*1024
>::result pqueue_type20;

pqueue_type20 Q2(pool2); 
1

There are 1 answers

0
MSalters On BEST ANSWER

When Q1 goes out of scope, it's memory will be automatically freed. So don't put everything in one big function. Put Q1 and the things you do with it in one function, and Q2 in another function.

The biggest problem would if Q1 is needed to create Q2, and Q2 is needed to create Q3, etc. In that case, std::unique_ptr<pqueue_type0> can be handy.