Terry J. Reedy added the comment:
Proposals for strings views have be rejected precisely because of the
keep-alive effect.
I do not remember if tuples were explicitly part of earlier discussions. One
could make the argument that million-item tuples, and especially slicing
thereof is rarer
Serhiy Storchaka added the comment:
The support of sharing a content between different tuples requires changing the
structure of the tuple object, allocating additional block for every tuple,
adding a level of indirection and reference counting. This will increase memory
consumption, creating
New submission from Filip Haglund:
Slicing tuples returns a copy, which is O(n) time. This could be O(1) since
tuples are immutable, by just pointing to the same data.
This probably applies to other immutable structures as well, such as strings.
--
components: Interpreter Core
Emanuel Barry added the comment:
This is an interesting idea, +1 from me. Do you want to submit a patch?
--
nosy: +ebarry
stage: -> needs patch
versions: -Python 2.7, Python 3.2, Python 3.3, Python 3.4, Python 3.5
___
Python tracker
Martin Panter added the comment:
I think which technique (copy or view) is better depends on the situation. If
you are making a large temporary slice, a view may be more efficient. But if
you are making a long-term slice and don’t need the original any more, a copy
would allow the original