[interfacekit] Re: BHandler::fToken

  • From: Ingo Weinhold <bonefish@xxxxxxxxxxxxxxx>
  • To: interfacekit@xxxxxxxxxxxxx
  • Date: Tue, 11 Mar 2003 21:19:55 +0100 (MET)

On Tue, 11 Mar 2003, Marc Flerackers wrote:

> > Mmh, I wonder whether 4 bytes for the token would be of any significance.
> > At least performance-wise the, at least two, syscalls to deliver the
> > set_current_view command should outweigh the additional overhead for
> > copying of hundreds of tokens.
>
> As Cedric Degea pointed out, commands aren't directly written to the port.
> They are cached in the _BSession_ (or PortLink in OpenBeOS, both work mostly
> in the same way, except that the first one writes it's data into a buffer
> and bumps a pointer, while the second one allocates a new buffer, writes the
> data and puts the buffer pointer in a list).
> The buffer is flushed at several occasions, for example when a command is
> sent from which you expect a reply (get_high_color). The buffer is sent
> through the port (synced/flushed), and the requested data is read from the
> port. So the set_current_view is just an 8 byte command written to the
> buffer. I'll still give a small example to illustrate:
>
> ---------------------
> |4: set current view|
> |4: server_token    |
> ---------------------
> |4: set high color  |
> |4: color           |
> ---------------------
> |4: move pen to     |
> |8: x, y            |
> ---------------------
> |4: stroke line to  |
> |8: x, y            |
> ---------------------
>
> without a set_current_view command you would have to add the view token to
> every command, which gives quite some extra port trafic. Now you just select
> the receiver view for the next commands which follow until the next
> set_current_view command.

OK, that makes sense. Since the set_current_view will always be
accompanied by at least one other command, you will indeed never have
additional port traffic. In worst case (if only one command is following)
you waste four bytes, but safe space for more than two commands on the
same view.

BTW, you can even safe the four bytes for the set_current_view command, if
you just send the token. You could distinguish commands and tokens e.g. by
the MSB -- set for one, unset for the other (BTW, this would also work,
when using pointers as tokens).

CU, Ingo

Other related posts: