[openbeos] Re: A new BMessage implementation (Message4)

  • From: mmlr@xxxxxxxx
  • To: openbeos@xxxxxxxxxxxxx
  • Date: Fri, 11 Nov 2005 13:54:56 +0100 (CET)

> easy or not?

I meant it is easy to do. Maybe I should have put a comma there...

> Shouldn't be too hard. There are already
> BLooper::AddMessage() and _AddMessagePriv()
> which could be used.

Ok, I'll look into that. From the operation (just adding the message to
the queue) this should not be a problem, right.

> This could be dangerous if both applications
> (sender and receiver) have full write access
> to the message.

Obviously, but that was not how I planned it. I thought that the one
"receiving" the message takes the area as read only and then, when it
needs to write to it, makes a copy for it's own purposes. That's how I
understood copy-on-write at least.

The other thing that comes to mind is obviously: What if the "sender"
writes to the message after it is referenced by someone else? In that
case, the sender would have to make a copy too. I thought of something
like this:

1. We have a large message that is located in an area.
2. The data has a reference count of 1 (ourselfs).
3. The message is sent with the area_id as a pointer to the the shared
area.
4. The receiver increments the reference count.
5. Both sender and receiver have read only access to the buffer.
6. One of both needs to write something, makes a copy of the area and
decrements the reference count of the original data.
7. The other one needs to write something, it sees that the reference
count is 1 and can use the area directly (no copy).

Does that concept work or do I miss something? The area, or the buffer
inside the same application for that matter, would only be copied when
more than one party currently uses the data (reference count > 1). The
last message that gets deleted (the one decrementing the reference
count to 0) would be the last "owner" of the data and delete it. This
concept should work for both, intra application with shared buffers and
inter application with shared areas.

By the way, this whole thing would go into the assignment operator,
wouldn't it?

Regards
Michael



Other related posts: