It makes code cleaner and easier to read / work-with when things are nicely divided into functions. Is there any memory usage overhead to passing (large) objects back and forth between different method calls? i.e.
Model 1 - Unified:
data1 = getData("1")
# Do stuff to data1
# ...
saveData(data1)
data2 = getData("2")
# Do stuff to data2
# ...
saveData(data2)
Model 2 - Divided:
def doStuff(dat):
# Do stuff to data
# ...
return dat
data1 = getData("1")
data1 = doStuff(data1)
saveData(data1)
data2 = getData("2")
data2 = doStuff(data2)
saveData(data2)
asked Apr 21, 2014 at 0:58
DilithiumMatrix
18.8k24 gold badges83 silver badges126 bronze badges
-
There is some minor overhead for every function call. The size of the objects being passed around does not matter whatsoever.roippi– roippi2014年04月21日 01:02:40 +00:00Commented Apr 21, 2014 at 1:02
-
1In Python, objects and such are passed by reference, not by value, so the I believe the overhead should be about the same regardless of the size of the object you pass in.Michael0x2a– Michael0x2a2014年04月21日 01:05:08 +00:00Commented Apr 21, 2014 at 1:05
1 Answer 1
Of course there is, but unless you're doing something crazy it should be tiny relative to the rest of your program, on the scale of multiple kilobytes.
answered Apr 21, 2014 at 1:00
U2EF1
13.4k3 gold badges39 silver badges38 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
Explore related questions
See similar questions with these tags.
lang-py