for loop - Inline list in python reallocate memory? -
i have pairs of objects want iterate over. example:
contenta = [1, 2, ..... 100000] lena = 123.12 contentb = [1, 2, ..... 100000] lenb = 123.12 contentc = [1, 2, ..... 100000] lenc = 123.12
now iterate on them, using following python syntax:
for (conttype, contlen) in [(contenta, lena), (contentb, lenb), (contentc, lenc)]: #
this works fine, question is:
does declaring inline list in loop first allocates memory , iterates on them?
since objects in question huge , number of iterations have enormous, allocating memory again & again consume memory time.
the list create iterate on elements contain pointers on contenta
, contentb
, contentc
.
since in example there 3 element cost in memory size of list of 3 tuple (float, pointer). not much.
if want little bit more efficient can iterate on tuple ((contenta, lena), (contentb, lenb), (contentc, lenc))
.
Comments
Post a Comment