Am Mittwoch, 18. Oktober 2006 01:35 schrieb Karl Forner: > Hi, > > Is there a way to specify a minimum allocation size for PMCs like strings > or arrays ? > Something like in perl : %h = 1000 ? > > It could boost execution times when you have a good idea of the space you > need. > For example, I'd like to do: > > #ensure that the array has enough allocated storage for 1000000 elements > without need for allocationg memory > new P0, .Array, 1000000 > > and then push 1,000,000 elements. > > N.B: it is not the same as > > new P0, .Array > P0 = 1000000
This isssue was already discussed a few times. Last time was likely, when I introduced the elements opcode, which helps at least to fix the 'get' side of the problem. It originated in a perl5-ism in the first array implementations, following the perl-way: $elems = scalar @array; which was directly translated to: set I0, P0 This works at least for "small" arrays. The problem is now of course, that we are forcing perl syntax elements on all HLLs having arrays. Now we have additionally: elements I0, P0 with it's own vtable. The problem is of course that the former construct is used heavily. There's no such thing for setting the size or/and the allocation. And worse, arrays are implementing: set P0, I0 # pre-size or allocate and fill and set element count? ... in an inconsistent way. IMHO the only way to get rid of this historical confusion is: - disable the set opcode for arrays by throwing an exception in the vtable - use elements for getting .elems only - implement 2 new opcodes elements P0, I0 # fill with default value, set element count to I0 presize P0, I0 # allocate storage, elem count is unchanged - implement an introspection method to get various info like allocated size or storage needed > Thx > Karl leo
