Home AMX User Forum AMX General Discussion
Options

Queue, Heads or Tails?

For those that use queue arrays do you have the tail try to catch the head or do you have the head chase the tail?

For me having the tail catch up to the head makes more sense but I was re-working the i!-EquipmentMonitorOut.axi to fix some timing issues and I noticed that it goes the other way which just seems wrong unless you're a dog.

What do others do?

Comments

  • Options
    PhreaKPhreaK Posts: 966
    I always use a FIFO buffer here. If I've been telling a device to do something I like making sure that my buffering doesn't screw with the command order (unless there's some logic in there for the explicit purpose - power off etc).
  • Options
    DHawthorneDHawthorne Posts: 4,584
    Ditto. FIFO is the way I always do it too, for much of the same reasons.
  • Options
    viningvining Posts: 4,368
    Both examples I was referring to were FIFO. What I consider the normal method is adding to the queue at the current head index and then take action on the tail index position until it reaches the head. The method used in i!-EquipmentMonitorOut is still FIFO but it adds new entries to the current tail index and then acts on the current head index until it catches the tail. Head lags the tail instead of the tail lagging the head.

    Really the same thing, both FIFO but calling the index pointers the opposite names. It just seems backward to me to add new entries to the tail and have the head chase it. The tail should trail and the head should lead.
  • Options
    ericmedleyericmedley Posts: 4,177
    I'm a FIFO kinda guy. I use a data_event to pile up the commands/strings with delimigters inbetween and a timeline that watches for work to do and then does it.
  • Options
    HedbergHedberg Posts: 671
    I'd think about this but I'm still trying to figure out which end of my egg to open first.
  • Options
    buffering the string outputs to a device is the way i also do my comms and FIFO is the way i am going too.

    Only in specific cases i was adding in front of the queue the user commands (from button pushes) and at the
    end the automatic requests from a running timeline.

    I am not shure how this really achieved my goal but my thought was to rush up the user commands instead
    of having them waiting at the end of the tunnel.
  • Options
    PhreaKPhreaK Posts: 966
    vining wrote: »
    Both examples I was referring to were FIFO. What I consider the normal method is adding to the queue at the current head index and then take action on the tail index position until it reaches the head.
    Ah ok. I couldn't think of an advantage/disadvantage of either method. Either way you have an array, an insertion index and an extraction index. As to how you refer to them is just semantics - you could call them 'foo' and 'bar' if you want, just make sure they both cycle in the same direction.
  • Options
    viningvining Posts: 4,368
    PhreaK wrote: »
    Ah ok. I couldn't think of an advantage/disadvantage of either method. Either way you have an array, an insertion index and an extraction index. As to how you refer to them is just semantics - you could call them 'foo' and 'bar' if you want, just make sure they both cycle in the same direction.
    Yeah there is no difference but having the head chasing the tail is like calling up, down and down, up which is fine if you're intentionally trying to confuse people. I was just wondering if this would be considered proper by you smart people or not. Being a little simple myself I had to spend a couple minutes scratching my head wondering what the F was going on until I realized it was exactly what I would expect but with the names reversed.

    Naming them foo and bar would be ok becuase I wouldn't have an pre-conceived expectations of what was what. :)
  • Options
    DHawthorneDHawthorne Posts: 4,584
    Honestly, I was having trouble understanding what you meant by "head chase the tail" and didn't want to look silly by admitting it :). Now that you explain it, I'm definitely having the tail chase the head. I find it simpler to keep buffers (when possible) as a CHAR array, and use string operators on it. Since REMOVE_STRING works from the head, that's how I do it. Add to the buffer by concatenating the string, then using REMOVE_STRING to tokenize it.

    Now if it's a multi-level array, I do it the same way out of sheer habit, but, as mentioned, it comes out the same. Either way, you have to add it, remove another, and juggle all the rest to the new order.
  • Options
    mpullinmpullin Posts: 949
    neither

    I do my queues sliding window style. This involves an array and two integers. When the two integers are equal, the queue is empty. When we push something, we put it in the cell integer A points to and increment integer A. (wrapping back around to the beginning if it reaches the end) When we pop something, we do something with the cell integer B points to and increment B. (again, wrapping it around to the beginning if necessary) So there is a number that chases another number but neither the "head" nor "tail" of the array is special.
  • Options
    DHawthorne wrote: »
    Honestly, I was having trouble understanding what you meant by "head chase the tail" and didn't want to look silly by admitting it :). Now that you explain it, I'm definitely having the tail chase the head. I find it simpler to keep buffers (when possible) as a CHAR array, and use string operators on it. Since REMOVE_STRING works from the head, that's how I do it. Add to the buffer by concatenating the string, then using REMOVE_STRING to tokenize it.

    Now if it's a multi-level array, I do it the same way out of sheer habit, but, as mentioned, it comes out the same. Either way, you have to add it, remove another, and juggle all the rest to the new order.

    This is the way I usually set up my buffers as well, and I also was having trouble understanding what you meant :)
Sign In or Register to comment.