Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] AspectJ and memory management

Gregor Kiczales wrote:
Anyway, Wes and I resolved the terminology issues off-list and it appears what I want to do can't be done in AspectJ.

I thought the following code, that we exchanged mail about last night,
does do what you want. In what way doesn't it work?

/*
 * Here's an aspect that associates a lot of extra state with
* some target type. But we want to be sure not to allocate * all that storage unless we really need it. So we use a
 * lazy allocation strategy for it.
 */
abstract aspect PersistenceOrSomething {

  protected interface HPoS {}; //marker type
                               //stands for HasPersistenceOrSomething

  private static StateBlock {
    private Mumble mumble;
    private Frotz  frotz;
    ...<many more fields>...
    StateBlock() { /*appropriate initialization*/ }
  }

  private StateBlock Target.state = null;

  /* these are the accessor methods for the state */
  public Mumble HPoS.getMumble() { return state.mumble; }
  public Frotz  HPoS.getFrotz () { return state.frotz;  }
  ...<many more accessors>...

These accessor methods should be in StateBlock, and having to duplicate the methods in the aspect for the purpose of delegating to it is not ok.

/Rickard


Back to the top