0

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); 
NobodyNada
  • 7,529
  • 6
  • 44
  • 51
Charlie
  • 3
  • 2
  • It seems to work like one would expect in C++, i.e. memory is released when the object is destroyed. Do you have any indication that it doesn't? – molbdnilo Nov 27 '14 at 09:29
  • For some reasons, I need define 8 pqs in my program, when the total memory occupied by PQ outnumber the memory of my computer(i.e. 4G, ubuntu), it runs slowly, so I want to delete some pq which do not need any more. – Charlie Nov 27 '14 at 09:51
  • @Charlie: That's exactly to be expected with STXXL. It uses your disk in addition to memory, but memory is a whole lot slower. – MSalters Nov 27 '14 at 12:16

1 Answers1

0

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.

MSalters
  • 173,980
  • 10
  • 155
  • 350