> On 23 Feb 2015, at 21:15, Mariano Martinez Peck <marianop...@gmail.com> wrote: > > > > On Fri, Feb 20, 2015 at 5:48 AM, Clément Bera <bera.clem...@gmail.com > <mailto:bera.clem...@gmail.com>> wrote: > It depends on your OrderedCollection implementation. > > OrderedCollection has a variable size in memory. When instantiated, it has > for example 10 slots, and if you have more than 10 objects, it needs to > change its size to hold more slots. > > > I thought that was the case too, but I cannot find in code what you say.
What Clement says is that *conceptionally* it has a variyng size. The current implementation uses an internal Array, as he describes: > > The current implementation relies on an indirection to an array, when the > array overflows, the orderedCollection allocates a new bigger array and copy > the slots from the existing array. There are some heuristics on array size to > avoid having to grow the array too often. > > If you want the shallowCopy to work, you have to use the old implementation > of OrderedCollection, which encodes in its field directly the values it > holds. In this case however when the collection overflows you create a new > orderedCollection so you need to use #become: to migrate references to the > old orderedCollection to the new one. This used to be a bad idea because the > become primitive was slow, but since we have Spur, it may be relevant to look > at it again. This old implementation is more memory efficient too. And then, with the new fast #become:, we can go back the the old implementation and grow OrderedCollection using #become:, which would mean that we would not need two objects anymore… Marcus