Re: Vector#toArray()




"Patricia Shanahan" <pats@xxxxxxx> wrote in message
news:lgXme.2995$s64.953@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> Allan Bruce wrote:
>
>> "Patricia Shanahan" <pats@xxxxxxx> wrote in message
>> news:yTFme.2473$s64.1759@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
>>
>>
>>> Allan Bruce wrote:
>>>
>>>
>>>> I am trying to code my application to benefit from running on a
>>>> parallel machine but it is not any
>>>> faster. I think I have some data which is too
>>>> synchronized so I am looking to avoid this. I have a
>>>> Vector which stores some data but I use toArray() to
>>>> get the data as an Object []. I am pretty sure that
>>>> this will now be non-synchronized but I thought I
>>>> would ask to check - is it?
>>>>
>>>> Thanks. Allan
>>>>
>>>>
>>>
>>> Vector's toArray method is synchronized, and needs to
>>> be synchronized. The toArray method would get very
>>> confused if the Vector were to change while it is
>>> running.
>>
>>
>> Yes, I meant: Is access to the array after this call
>> synchronized? I doubt it but thought I would check.
>
> Accesses to the array will be synchronized if, and only if,
> they occur in a synchronized context.
>
> Patricia
>

Thats what I thought, thanks!
Allan


.



Relevant Pages

  • Re: ClassCastException from Vector to Array
    ... If you allocate the right size for the array, the toArray method ... > will not have to allocate another array. ... Prev by Date: ...
    (comp.lang.java.programmer)
  • Re: ClassCastException from Vector to Array
    ... If you allocate the right size for the array, the toArray method ... Prev by Date: ...
    (comp.lang.java.programmer)
  • Re: Deep thoughts on .ToArray()
    ... Using ToArray on an array is only possible when targeting framework 3.5 ... where the IEnumerable interface (which the Array class implements) has ... The ToArray method creates a Buffer object from the IEnumerable (the ... just as the ToString method of the String class just returns the ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Deep thoughts on .ToArray()
    ... You are creating an array that is just thrown away when the reference is replaced with another array in the next line. ... Using ToArray on an array is only possible when targeting framework 3.5 where the IEnumerable interface (which the Array class implements) has that extension method. ... there is a bit of overhead when calling the ToArray method compared with calling the Array.CopyTo method yourself. ... For an array the ToArray method could just have returned the array object itself, just as the ToString method of the String class just returns the string object itself. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: int [] Array Question
    ... int[] as a param. ... In that case you should use the ToArray method of either ArrayList or ... You can't add values to an array - arrays are fixed size. ...
    (microsoft.public.dotnet.languages.csharp)