News:

  • October 13, 2025, 05:07:56 PM

Login with username, password and session length

Author Topic: FIFO - Is way to delete a FIFO queue entry?  (Read 1838 times)

diannacone

  • Newbie
  • *
  • Posts: 4
FIFO - Is way to delete a FIFO queue entry?
« on: June 29, 2022, 04:07:41 PM »
Struggling to figure out if there is a way to delete a FIFO entry from the queue / memory block. To be more specific, I am trying to delete the last entry of a FIFO, but have other applications where it would be nice to delete in the middle of the queue.

My best guess was to use MEMCLEAR of the targeted data location but instead of clearing it and resetting the state to accept the next FIFO entry, it retains a 0 in the queue/memory position and loads the FIFO data in the next data location.

Established FIFO_1

Where V0 is the queue position

MEMCLEAR
Struct/Numeric Range   - Fifodata1[V0]
Number of Elements      -             1


I also tried do a LIFOUNLOAD of a FIFO and that syntax was invalid..which makes since... just thought it would be nice to be able to load and unload from both sides of the array. 

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3761
    • Host Engineering
Re: FIFO - Is way to delete a FIFO queue entry?
« Reply #1 on: June 29, 2022, 04:25:05 PM »
There is no easy way to delete something in the middle of a FIFO or LIFO queue. You need to implement your own custom FIFO mechanism for that.

The firmware implementation uses a circular buffer where the delete-from "index" could wrap-around, assuming the index is a relative index from the "top" (or "bottom"?, or you might need "absolute")?  For example, how do you determine the relative "index" - do you handle all the possible cases (empty, full, wrap-around, etc.???)

There is no "good" way to do this without making a "remove" instruction hugely complex (just allowing removal of an index relative from "top" vs. "bottom", vs. "absolute" is confusing enough, along with FIFO vs. LIFO differences).  This is not a standard queue function (you typically can't do this with library-based queue classes).

If you understand how to do it in C with a circular buffer, array indexing in Do-more can do that, so you could write your own algorithms for FIFO, and corresponding removal, including searching (e.g. "remove value" and also a "remove index" feature), handling all the special case empty/full/wrap-around is do-able.  Also, it seems that you only need to implement a FIFO version, not LIFO.

diannacone

  • Newbie
  • *
  • Posts: 4
Re: FIFO - Is way to delete a FIFO queue entry?
« Reply #2 on: June 30, 2022, 03:55:46 PM »
Yes, yes, yes.

franji1 - Thanks for the tip on the circular buffer. Found a little conceptual description on emory.edu and it put everything in focus very neatly.

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6126
  • Yes Pinky, Do-more will control the world!
Re: FIFO - Is way to delete a FIFO queue entry?
« Reply #3 on: June 30, 2022, 04:08:50 PM »
Yes, yes, yes.

franji1 - Thanks for the tip on the circular buffer. Found a little conceptual description on emory.edu and it put everything in focus very neatly.

I actually implemented the FIFO using PLC instructions first, and then converted it to C code in the instruction implementation. It really wasn't that hard, and I actually fought adding them as built-in instructions, 'cause "all ya gotta do is...". That was an oversimplification though and it was quite a bit harder than I had always envisioned, but it's still pretty manageable.
"It has recently come to our attention that users spend 95% of their time using 5% of the available features. That might be relevant." -BobO