0

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
2
  • There is some minor overhead for every function call. The size of the objects being passed around does not matter whatsoever. Commented Apr 21, 2014 at 1:02
  • 1
    In 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. Commented Apr 21, 2014 at 1:05

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.