lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


This is pretty nice if you have to manipulate subsections of a sequence frequently, and want to conserve memory. Is there a big performance hit for accessing through a slice rather than the table itself?

On Fri, Jun 5, 2015 at 7:03 AM, Dibyendu Majumdar <mobile@majumdar.org.uk> wrote:
Hi,

What do you think of below? I have been experimenting with array
slices in Ravi. A slice is a table which accesses data from another
table. Obviously this is specific to array specialization of tables in
Ravi.

> function x()
>>   local a: integer[] = table.intarray(20, 5)
>>   local b: integer[] = table.slice(a,1,10)
>>   local c: integer[] = table.slice(b,3,5)
>>   c[1] = 3
>>   c[2] = 4
>>   c[3] = 5
>>   return a,b,c
>> end
> a,b,c = x()
> for k,v in pairs(a) do print(k,v) end
1       5
2       5
3       3
4       4
5       5
6       5
7       5
8       5
9       5
10      5
11      5
12      5
13      5
14      5
15      5
16      5
17      5
18      5
19      5
20      5
> for k,v in pairs(b) do print(k,v) end
1       5
2       5
3       3
4       4
5       5
6       5
7       5
8       5
9       5
10      5
> for k,v in pairs(c) do print(k,v) end
1       3
2       4
3       5
4       5
5       5




--
Brigham Toskin