本文介绍了可能的内存泄漏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在程序中有一个函数可以像这样工作。


def load_pic_data(width,heigth,inpdat,filt = TRUE):

data =''''

总计= 0

tnum = 0

size = 100

for y in范围(0,高度):

row =''''

范围内的x(0,宽度):

index = 2 *(x + y *宽度)

num = ord(inpdat [index + 1])* 256 + ord(inpdat [index])

if(vfilter.get ()和d_filter和filt):

num = round((num-(d_filter [index / 2])))

if(num< 0):

num = 0

if(num> 255 * 64):

num = 255 * 64

row = row + chr(num / 64)

data = data + row

这部分程序的目的是取14位数字

表示并将其转换为8位表示。这将

以后显示为图像。但是,我注意到以下

关于此代码。我注意到当我拍了一张小照片的时候,它确实快速地消耗了b $ b,但是更大的画面需要永远贯穿始终。我在代码的y部分添加了一个打印语句

,看看它在哪里挂起了b $ b。我注意到它随着时间的推移似乎运行得更慢

继续。我做了一个time.time()时间戳来验证这一点,并确认了它已经确认了。关于我能做些什么来让它运行得更快的任何想法?注意

,如果重复这个过程,它的运行速度一样慢。我能做什么?
让它运行得更快?我怀疑如果我以某种方式处理行语句

完成后,它将运行得更快,而数据变量在

完成后,但是我只是不知道该怎么做。谢谢!

I have a function in a program that works something like this.

def load_pic_data(width,heigth,inpdat, filt=TRUE):
data=''''
total=0
tnum=0
size=100
for y in range(0,heigth):
row=''''
for x in range(0,width):
index=2*(x+y*width)
num=ord(inpdat[index+1])*256+ord(inpdat[index])
if(vfilter.get() and d_filter and filt):
num=round((num-(d_filter[index/2])))
if(num<0):
num=0
if(num>255*64):
num=255*64
row=row+chr(num/64)
data=data+row
The purpose of this part of a program is to take a 14 bit numerical
representation and convert it to an 8 bit representation. This will
later be displayed as an image. However, I''ve noticed the following
about this code. I was noticing when I took a small picture, it went
really fast, but a larger picture took forever to run through. I added
a print statement to the y portion of the code to see where it was
getting hung up. I noticed that it appears to be running slower as time
goes on. I did a time.time() timestamp to verify this, and had it
confirmed. Any ideas as to what I could do to make it run faster? Note
that if this process is repeated, it runs equally slow.What can I do to
make it run faster? I suspect if I somehow dealocate the row statement
after it''s done, that it will run faster, and the data variable when
it''s done, but I just don''t know how to do so.Thanks!

推荐答案




开ce行和数据不再被使用,Python会自动删除它们并回收它们使用的内存。你很少需要担心

那个。

-

史蒂文。



Once row and data are no longer being used, Python automatically removes
them and reclaims the memory they used. You rarely need to worry about
that.
--
Steven.





是,以及执行的频率是多少?


< / F>



do, and how often is it executed ?

</F>





使用StringIO或数组可能更好模块。



Probably better to use StringIO or the array module.


这篇关于可能的内存泄漏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 09:18