[Tutor] memory consumption

Alan Gauld alan.gauld at btinternet.com
Wed Jul 3 20:57:31 CEST 2013


On 03/07/13 19:17, Andre' Walker-Loud wrote:

Your terminology is all kixed up and therefore does not make sense.
WE definitely need to know more about the my_class module and do_stuff....

> ################################################
> # generic code skeleton
> # import a class I wrote to utilize the 3rd party software
> import my_class

This import a module which may contain some code that you wrote
but...

> # instantiate the function do_stuff
> my_func = my_class.do_stuff()

You don;t instantiate functions you call them. You are setting my_func 
to be the return value of do_stuff(). What is that return value? What 
does my_func actually refer to?

> my_array = numpy.zeros([20,10,10])
> # loop over parameters and fill array with desired output
> for i in range(loop_1):
>      for j in range(loop_2):
>          for k in range(loop_3):
>              # create tmp_data that has a shape which is the same as data except the first dimension can range from 1 - 1024 instead of being fixed at 300
>
>              '''  Is the next line where I am causing memory problems? '''
>              tmp_data = my_class.chop_data(data,i,j,k)

Again we must guess what the chop_data function is returning. Some 
sample data would be useful here.

>              my_func(tmp_data)

Here you call a function but do not store any return values. Or are you 
using global variables somewhere?

>              my_func.third_party_function()

But now you are accessing an attribute of my_func. What is my_func? Is 
it a function or an object? We cannot begin to guess what is going on 
without knowing that.

>              my_array([i,j,k]) = my_func.results() # this is just a floating point number
>
>              ''' should I do something to flush tmp_data? '''

No idea, you haven't begun to give us enough information.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/



More information about the Tutor mailing list