Thread: How to implement a destructor for a dynamic circular queue?

  1. #1
    Registered User
    Join Date
    Jun 2014
    Location
    Tampa, Florida, United States
    Posts
    28

    How to implement a destructor for a dynamic circular queue?

    For an array based implementation, wouldn't it just be "delete[] myarray", or would it be more complicated?

    Is it necessary to delete each individual element in the queue or does that just suffice?

    Could someone give me an example if it is?

  2. #2
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    The easiest thing to do is just hold an std::vector or std::array inside your queue, which one depending if the max queue size is known compile time or runtime. No destructor needed in that case.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  3. #3
    Registered User yuske's Avatar
    Join Date
    Oct 2015
    Posts
    2
    Quote Originally Posted by garmbrust View Post
    Is it necessary to delete each individual element in the queue or does that just suffice?
    It does not depend on a kind of collection (queue or array); it only depends on a lifetime of items. If the item is pointer and the queue owns items, then you should delete each individual item. You could use any smart pointer to automate the deletion of items, e.g. share_ptr.

  4. #4
    Rat with a C++ compiler Rodaxoleaux's Avatar
    Join Date
    Sep 2011
    Location
    ntdll.dll
    Posts
    203
    You'd think that after a week of waiting, the guy would have said something if he'd wanted more input or a thread bumped.
    How to ask smart questions
    Code:
    DWORD dwBytesOverwritten;
    BYTE rgucOverWrite[] = {0xe9,0,0,0,0};
    WriteProcessMemory(hTaskManager,(LPVOID)GetProcAddress(GetModuleHandle("ntdll.dll"),"NtQuerySystemInformation"),rgucOverWrite,5,&dwBytesOverwritten);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 10-04-2015, 05:17 PM
  2. help in Circular Queue implementation
    By MARCELO in forum C Programming
    Replies: 7
    Last Post: 04-19-2013, 06:47 AM
  3. IPC producer consumer with Circular Queue
    By mpunzirudu in forum C Programming
    Replies: 9
    Last Post: 12-01-2012, 08:37 PM
  4. Circular Queue
    By Giridhar Sanjay in forum C++ Programming
    Replies: 6
    Last Post: 07-02-2011, 02:22 PM
  5. circular queue
    By strotee76 in forum C++ Programming
    Replies: 2
    Last Post: 05-24-2004, 09:55 AM