Re: Snapshot of List [Was: Re: sync on local variable]
- From: Arved Sandstrom <dcest61@xxxxxxxxxxx>
- Date: Fri, 26 Mar 2010 21:05:27 GMT
Daniel Pitts wrote:
On 3/26/2010 7:22 AM, Eric Sosman wrote:I tend to use an array where the underlying structure I am representing really is an array, and a collection where the underlying structure really is a list or set or whatever.On 3/25/2010 3:28 PM, Daniel Pitts wrote:Array is a relatively primitive concept. You're question is akin to asking why use a "Date object" instead of an "int representing the milliseconds since Jan 1, 1970".On 3/25/2010 11:06 AM, Eric Sosman wrote:>> [... about iterating over a changing List ...]>to keep the
iteration self-consistent you might want to do something like
lock ALL_ROWS, grab a snapshot with toArray(), unlock, and run
the iteration on the (private, stable) snapshot.
I agree except, don't use toArray, use new ArrayList<Row>();
Not confrontational, just curious: Why prefer a new ArrayList
to an array? To me, it appears that an ArrayList is just an array
wrapped up in extra machinery, and I can't see that the machinery
adds any value for this usage. So, why pay the extra freight?
What am I missing?
Either one "works". Yes, the non-primitive has more "machinery", but that isn't automatically a bad thing. The primitive looses semantic meaning outside of its context, where a properly designed abstraction maintains its semantics regardless of context.
Lists are also easier to work with, and work in more places.
Specifically I am not going to use an ArrayList, for example, if the thing being modelled is not resizable. Why would I want to write code to ensure that the ArrayList will stay at a fixed size when an aray will already take care of that for me?
AHS
.
- References:
- sync on local variable
- From: Roedy Green
- Re: sync on local variable
- From: Arne Vajhøj
- Re: sync on local variable
- From: Patricia Shanahan
- Re: sync on local variable
- From: Roedy Green
- Re: sync on local variable
- From: Eric Sosman
- Re: sync on local variable
- From: Daniel Pitts
- Snapshot of List [Was: Re: sync on local variable]
- From: Eric Sosman
- Re: Snapshot of List [Was: Re: sync on local variable]
- From: Daniel Pitts
- sync on local variable
- Prev by Date: Re: RFC perfectjpattern new release 1.0.3
- Next by Date: gcj compiled executable performance
- Previous by thread: Re: Snapshot of List [Was: Re: sync on local variable]
- Next by thread: Re: Snapshot of List [Was: Re: sync on local variable]
- Index(es):
Relevant Pages
|