Boost logo

Boost Users :

Subject: [Boost-users] Intrusive feature idea - accessor_hook
From: Hite, Christopher (Christopher.Hite_at_[hidden])
Date: 2010-07-27 10:32:27


Intrusive has base_hooks and member_hooks. I wish it had a accessor
hook, where you can define a member function which returns the a hook
reference.

My use case: I have a class being used between two threads and I want to
break it up to avoid cache thrashing.

struct Object{
        struct UpdatedState{
        } *updatedState;

        struct PrivateState{
        } *privateState;

        struct PublishedState{
        } *publishedState;
};

So the users's thread updates stuff in UpdatedState and flags it for
consumption by the service thread. The service thread has lots of
private data associated with the object. It updates the user
asychronously updating publishedState and flagging it for consumption by
the user.

The a nice way to flag things for consumption is to put them in an
slist. The problem is that everyone wants an slist of Object instead of
just a child like UpdatedState. The problem of course is that putting
the hooks in Object would cause the cache trashing we were trying to
avoid.

Putting the hooks in the child objects requires a way back to Object.
As work around a pointer could be added for each child back to Object.

If I were writing my own linked lists, the solution is obvoius: I would
add a field
        Object* nextUpdated
to UpdatedState.

What I propose is adding a accessor to Object
        list_member_hook<>& getUpdatedHook();

typedef accessor_hook<Object, list_member_hook<>,
&Object::getUpdatedHook> MemberHookOption;

Another advantage to allowing an accessor to be used is that the user
can share memory between unused hooks by putting them in variant or
union. In my case I've got 6 sorts 2 for add/change/delete
prioritization. I only ever use 2 of these at a time, but I can't avoid
the memory cost for having all the hooks.

Chris Hite


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net