[FIX] Re: DependentsArray size and subscript is out of bounds

Bert Freudenberg bert at impara.de
Fri Jul 21 15:11:21 UTC 2006


Andrew,

if you try this:

| a |
a := DependentsArray new.
[1 to: 1000 do: [:i | a := a copyWith: Object new]] timeToRun

The old code will complete that in less than a second. Your version  
takes 3 minutes (I think because of hidden size calls on the  
DependentsArray which are very expensive). This is not a realistic  
use case, but still ;-)

I suggest the following:

copyWith: newElement
	"Re-implemented to not copy any niled out dependents."
	| copy i |
	copy := self class new: self size + 1.
	i := 0.
	self do: [:item | copy at: (i:=i+1) put: item].
	copy at: (i:=i+1) put: newElement.
	^copy

This appears to be even more efficient than the original. I'll attach  
the CS.

The actual problem was that #streamContents: does not work correctly  
with dynamically sized collections (capacity ~= size). Try this for  
the same problem:

	OrderedCollection streamContents: [:s | s nextPut: 42]

Creating strong refs temporarily would only fix a symptom of that  
issue. Not sure if it's a bug.

- Bert -

Am 21.07.2006 um 11:45 schrieb Andrew Tween:

> If you still have problems, even with the garbage collect, then you  
> could try
> modifying DependentsArray>>copyWith: to something like this...
>
> ---------
> copyWith: newElement
>  "Re-implemented to not copy any niled out dependents.
>  The receiver's elements are copied into a temporary collection
>  to prevent them from being being garbage collected while the
>  copy is being made"
>  | answer tmp element |
>
>  tmp := IdentitySet new: self basicSize.
>  1 to: self basicSize do:[:i2 |
>   (element := self at: i2)
>    ifNotNil:[tmp add: element]].
>  answer := self class streamContents:[:s|
>   self do:[:item| s nextPut: item].
>   s nextPut: newElement].
>  ^answer
> -----------
>
> This solves the previous "test case", and doesn't appear to have  
> any adverse
> effects.
> Cheers,
> Andy
>
> ----- Original Message -----
> From: "Mathieu SUEN" <mathk.sue at gmail.com>
> To: "The general-purpose Squeak developers list"
> <squeak-dev at lists.squeakfoundation.org>
> Sent: Friday, July 21, 2006 10:23 AM
> Subject: Re: DependentsArray size and subscript is out of bounds
>
>
>> 2006/7/21, Marcus Denker <denker at iam.unibe.ch>:
>>>
>>> On 20.07.2006, at 10:37, Andrew Tween wrote:
>>>
>>>>
>>>>
>>>> I have also seen this problem when using Smacc, but didn't solve
>>>> the root cause
>>>> of the problem. I just did a garbage collect before generating the
>>>> parser/scanner and the problem went away.
>>>>
>>>
>>> So I changed the parser generator to do a "Smalltalk garbageCollect"
>>> befor compiling
>>> a grammar. It's in SmaCCDev-md.4.mcz
>>>
>>> http://www.squeaksource.com/SmaccDevelopment
>>>
>>> I did not yet test if it really helps, though.
>>>
>>>         Marcus
>>>
>>>
>> Yep thanks Marcus I will try
>>>
>>>
>>>
>>>
>>
>>
>> <DependentsArrayFix.1.cs>
>

-------------- next part --------------
A non-text attachment was scrubbed...
Name: depArrayFix-bf.1.cs.gz
Type: application/x-gzip
Size: 400 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20060721/9e3bf1ac/depArrayFix-bf.1.cs.bin
-------------- next part --------------



More information about the Squeak-dev mailing list