Andreas Leitgeb schrieb:
> In*that* case, I'd use a plain array, sized to say 2048 and
> just index into it.
Actually this is a very good idea. But it only
works when the application did not use the ArrayList
as a point of reference for sharing, so that
by pointing to the ArrayList object all clients of
this object would automatically see any changes
on the object. This is not possible with an array.
So have to check how the ArrayList is used in
the application. There are chances that the ArrayList
itself sits in an object and that this parent object
can be used as a point for sharing instead of the
ArrayList. And then I could replace the ArrayList
by an array. If there is no such parent object, then not.
If there is no such parent object, I would need
to wrap the array in some object, and would end
up re-implementing ArrayList. Lets see.
But you are also right that if I know an the size
of the array, and could make the size fixed, then
no change of the array itself would happen. I would
not need to bother about having a shared reference.
But I guess the fixed size assumption is not possible
here. The array might or might not filled at all.
Joshua Cranmer schrieb:
> On 8/10/2011 6:52 PM, Jan Burse wrote:
>> So the chances are very high, that an emulation eats up
>> exactly these 5-20% percents.
> I honestly doubt that. But instead of arguing about it, why not *try*
> implementing it and measuring the performance implications to verify for
I don't exclude doing this some time ahead.
Currently I was not yet able to do this
given the time and cost constraints around.
Patricia Shanahan schrieb:
>> You can assume the constraint that the element access
>> should stay at O(1). This narrows down the possible
>> data structures a little bit.
> Does that include accesses that require a size increase?
I don't have yet frequency figures, and thus cannot
give you much non-functional requirements on
setSize(). But you are right, if no fast path is
available, in some circumstances a semi-fast path
or even a slow path might also do.
Sorry for not being able to provide you more information.
Jan Burse <(E-Mail Removed)> wrote:
> Andreas Leitgeb schrieb:
>> In*that* case, I'd use a plain array, sized to say 2048 and
>> just index into it.
> But I guess the fixed size assumption is not possible
> here. The array might or might not filled at all.
Is that now about an odd chance that the array/ArrayList might
grow beyond the initial estimate? Or is that about other code
(that sees the ArrayList) that may be relying on that the last
non-null element is at position "size()-1" ?
If the former: for an odd-chance event, doing
is good enough.
If the latter: stick to Vector ;-/ Even if ArrayList.setSize()
was ever added, that would surely happen too late for your project.