freelanceprogrammers.org Forum Index » Delphi

About the memory occupation

View user's profile Post To page top
ztdraw Posted: Thu Aug 31, 2006 10:24 am


Joined: 31 Aug 2006

Posts: 10
About the memory occupation
Hello
I tried Demo21 yesterday, and just made a small change to it. I
repeated the line "P.OffsetBy(2,3)" for 10,000 times and found out that
the program used more than 38MB memory.

Is that OK, or just I missed something? How can I reduce or limit the
memory usage of my program using P4D which will keep running for a long
time? (Best under 10MB memory usage...)

I`m preparing for using PythonForDelphi as the basic plug-in engine of
my program, a part of which will be designed to stay in memory after
the system starts. So a relatively low memory occupation is necessary
for me.

Are there any suggestions for me?

Thank you very much.
:)
Reply with quote
Send private message
View user's profile Post To page top
morgan_martinet Posted: Thu Aug 31, 2006 7:44 pm


Joined: 29 Apr 2005

Posts: 103
About the memory occupation
Hi,
 
I just tried this demo using Delphi7 and
the latest version of P4D and could not get any memory leak!
I tried to loop on:
- the p=spam.CreatePoint(2,3)
- P.OffsetBy(2,2)
- both
- both + print statement
 
Give me more information on your
configuration…
 
Bye,
 
Morgan
 
 





From:
pythonfordelphi@yahoogroups.com [mailto:pythonfordelphi@yahoogroups.com] On Behalf Of ztdraw
Sent: Thursday, August 31, 2006
1:24 AM
To:
pythonfordelphi@yahoogroups.com
Subject: [pythonfordelphi] About
the memory occupation

 



Hello
I tried Demo21 yesterday, and just made a small change to it. I
repeated the line "P.OffsetBy(2,3)" for 10,000 times and found
out that
the program used more than 38MB memory.

Is that OK, or just I missed something? How can I reduce or limit the
memory usage of my program using P4D which will keep running for a long
time? (Best under 10MB memory usage...)

I`m preparing for using PythonForDelphi as the basic plug-in engine of
my program, a part of which will be designed to stay in memory after
the system starts. So a relatively low memory occupation is necessary
for me.

Are there any suggestions for me?

Thank you very much.
:)
Reply with quote
Send private message
View user's profile Post To page top
ztdraw Posted: Fri Sep 01, 2006 4:46 pm


Joined: 31 Aug 2006

Posts: 10
About the memory occupation
Thank you for replying. :)

I`m using the latest P4D under Delphi2006.
I found that the 38MB memory usage was just caused by the way I
tested the function.

Because I`m not familiar with the python syntax, I just copied the
statement "P.OffsetBy(2,2)" for 10,000 times, that is more than
10,000 lines in the script. To finish executing those lines, the
program took several seconds and used up 38MB memory.

Today I used the "while" statement to loop for the same times,
finding out that the program performed really well, and only used
about 3MB memory.

It seems that the memory problem is caused by the script which has
too many lines.
If I want to reduce the memory usage after the execution of such a
large script, for example, having more than 10,000 lines, what
should I do?

Thank you.


--- In pythonfordelphi@yahoogroups.com, Morgan Martinet <yahoo@...>
wrote:
>
> Hi,
>
>
>
> I just tried this demo using Delphi7 and the latest version of P4D
and could
> not get any memory leak!
>
> I tried to loop on:
>
> - the p=spam.CreatePoint(2,3)
>
> - P.OffsetBy(2,2)
>
> - both
>
> - both + print statement
>
>
>
> Give me more information on your configuration.
>
>
>
> Bye,
>
>
>
> Morgan
>
Reply with quote
Send private message
View user's profile Post To page top
dbudelsky Posted: Fri Sep 01, 2006 10:25 pm


Joined: 01 Sep 2006

Posts: 3
About the memory occupation
Hello,
I assume that the memory usage was caused by the just in time compilation.
Therefore I would recommend compiling such large scripts before importing them
or executing them.

Compilation can be done with the module compiler using function
compileFile(`filename.py`) generating a `filename.pyc` file.

Best regards

Dietmar
Reply with quote
Send private message
View user's profile Post To page top
richardander... Posted: Thu Sep 07, 2006 1:41 am


Joined: 01 May 2005

Posts: 7
About the memory occupation
Hi
If you really need a script of 10,000 lines then it should be split
into multiple source files.
Use the `import` statement to link together the source files at
execution time.
See the excellent Python tutorial for details of the import system.

That way, individual source files are only recompiled after
modification.
Also, I assume (although I have not tested this) that memory useage
would be much lower because the primary Python script - i.e. the one
that is executed and imports functions from the others - would be much
smaller.

Hope this helps!

Rich

ztdraw wrote:


Thank you for replying. :)

I`m using the latest P4D under Delphi2006.
I found that the 38MB memory usage was just caused by the way I
tested the function.

Because I`m not familiar with the python syntax, I just copied the
statement "P.OffsetBy(2,2)" for 10,000 times, that is more than
10,000 lines in the script. To finish executing those lines, the
program took several seconds and used up 38MB memory.

Today I used the "while" statement to loop for the same times,
finding out that the program performed really well, and only used
about 3MB memory.

It seems that the memory problem is caused by the script which has
too many lines.
If I want to reduce the memory usage after the execution of such a
large script, for example, having more than 10,000 lines, what
should I do?

Thank you.

--- In pythonfordelphi@yahoogroups.com,
Morgan Martinet <yahoo@...>
wrote:
>
> Hi,
>
>
>
> I just tried this demo using Delphi7 and the latest version of P4D

and could
> not get any memory leak!
>
> I tried to loop on:
>
> - the p=spam.CreatePoint(2,3)
>
> - P.OffsetBy(2,2)
>
> - both
>
> - both + print statement
>
>
>
> Give me more information on your configuration.
>
>
>
> Bye,
>
>
>
> Morgan
>
Reply with quote
Send private message
View user's profile Post To page top
ztdraw Posted: Thu Sep 07, 2006 5:36 pm


Joined: 31 Aug 2006

Posts: 10
About the memory occupation
Thanks a lot for your reply. I now know more about it, and I`ll try that out sometime. Thanks! By the way, the 10,000 line script is just a test, through which I wanted to know the speed of execution.   And at present, I`m just worried about the engine of python itself. Before, I intend to execute python scripts using multi-threads in my program, that is to execute several independent scripts at the same time using different python engines. However, from the earlier letters, I got the knowledge that the python engine should be created only for one and not be created and freed frequently due to the way python used to manage the memory.   If I really want to execute several scripts at the same time, is there any suggestion for me?   Zhou Richard Wright <rich@...>
写道: HiIf you really need a script of 10,000 lines then it should be split into multiple source files.Use the `import` statement to link together the source files at execution time.See the excellent Python tutorial for details of the import system.That way, individual source files are only recompiled after modification.Also, I assume (although I have not tested this) that memory useage would be much lower because the primary Python script - i.e. the one that is executed and imports functions from the others - would be much
smaller.Hope this helps!Richztdraw wrote: Thank you for replying. :)I`m using the latest P4D under Delphi2006.I found that the 38MB memory usage was just caused by the way I tested the function.Because I`m not familiar with the python syntax, I just copied the statement "P.OffsetBy(2,2)" for 10,000 times, that is more than 10,000 lines in the script. To finish executing those lines, the program took several seconds and used up 38MB memory.Today I used the "while" statement to loop for the same times, finding out that the program performed really well, and only used about 3MB memory.It seems that the memory problem is caused by the script which has too many lines. If I want to reduce the memory usage after the execution of such a large script, for example, having more
than 10,000 lines, what should I do?Thank you.--- In pythonfordelphi@yahoogroups.com, Morgan Martinet <yahoo@...> wrote:>> Hi,> > > > I just tried this demo using Delphi7 and the latest version of P4D and could> not get any memory leak!> > I tried to loop on:> > - the p=spam.CreatePoint(2,3)> > - P.OffsetBy(2,2)> > - both> > - both + print statement> > > > Give me more information on your configuration.> > > > Bye,> > > > Morgan>
Mp3疯狂搜-新歌热歌高速下
Reply with quote
Send private message
View user's profile Post To page top
morgan_martinet Posted: Thu Sep 07, 2006 7:09 pm


Joined: 29 Apr 2005

Posts: 103
About the memory occupation
You can look at Demo11 and this section of
the wiki: http://py4d.pbwiki.com/Using%20Threads
But you鈥檒l have to be very careful鈥
What鈥檚 your need? Only executing scripts? Does
your script use Delphi objects or do you plan
to provide custom modules/types to your scripts? Do you need Delphi
only for the UI? Do you need to communicate between your threaded Python
scripts and the main UI thread?
 
Morgan
 





From:
pythonfordelphi@yahoogroups.com [mailto:pythonfordelphi@yahoogroups.com] On Behalf Of T Z
Sent: Thursday, September 07, 2006
8:37 AM
To:
pythonfordelphi@yahoogroups.com
Subject: 鍥炲锛 Re:
[pythonfordelphi] Re: About the memory occupation

 




Thanks
a lot for your reply.


I
now know more about it, and I`ll try that out sometime. Thanks!


By
the way, the 10,000 line script is just a test, through which I wanted to know
the speed of execution.


 


And
at present, I`m just worried about the engine of
python itself. Before, I intend to execute python scripts using multi-threads
in my program, that is to execute several independent scripts at the same time
using different python engines.


However,
from the earlier letters, I got the knowledge that the python engine should be
created only for one and not be created and freed
frequently due to the way python used to manage the memory.


 


If I
really want to execute several scripts at the same time, is there any
suggestion for me?


 


Zhou




Richard Wright
<rich@richardwright.fsbusiness.co.uk> 鍐欓亾锛




Hi
If you really need a script of 10,000 lines then it should be split into
multiple source files.
Use the `import` statement to link together the source files at execution time.
See the excellent Python tutorial for details of the import system.

That way, individual source files are only recompiled after modification.
Also, I assume (although I have not tested this) that memory useage would be
much lower because the primary Python script - i.e. the one that is executed
and imports functions from the others - would be much smaller.

Hope this helps!

Rich

ztdraw wrote:



Thank you for replying. :)

I`m using the latest P4D under Delphi2006.
I found that the 38MB memory usage was just caused by the way I
tested the function.

Because I`m not familiar with the python syntax, I just copied the
statement "P.OffsetBy(2,2)" for 10,000 times, that is more than
10,000 lines in the script. To finish executing those lines, the
program took several seconds and used up 38MB memory.

Today I used the "while" statement to loop for the same times,
finding out that the program performed really well, and only used
about 3MB memory.

It seems that the memory problem is caused by the script which has
too many lines.
If I want to reduce the memory usage after the execution of such a
large script, for example, having more than 10,000 lines, what
should I do?

Thank you.

--- In pythonfordelphi@yahoogroups.com,
Morgan Martinet <yahoo@...>
wrote:
>
> Hi,
>
>
>
> I just tried this demo using Delphi7 and the latest version of P4D
and could
> not get any memory leak!
>
> I tried to loop on:
>
> - the p=spam.CreatePoint(2,3)
>
> - P.OffsetBy(2,2)
>
> - both
>
> - both + print statement
>
>
>
> Give me more information on your configuration.
>
>
>
> Bye,
>
>
>
> Morgan
>





 





Mp3鐤媯鎼-鏂版瓕鐑瓕楂橀熶笅
Reply with quote
Send private message
View user's profile Post To page top
ztdraw Posted: Sat Sep 09, 2006 5:48 pm


Joined: 31 Aug 2006

Posts: 10
About the memory occupation
Thank you very much for the replay. And those demos provided in P4D are really good guide for me.   Yes, the scripts will frequently communicate with the Delphi objects provided in the main program as a kind of function interface. I intend to make the scripts get use of network and database through the objects I provide. Those objects can be accessed as objec types or object instances in the python script.   I prefer to create one script engine and execute one independent script in each Delphi thread, and just release the engine as soon as the script finishes. The main program will sometimes communicate with its sub-threads, but the sub-threads will be blind for each other.   Using multi-thread in my program is just because the scripts are to download information for internet and store it in database, which means I have to deal with the idle time
when the network waits for reply.   By the way, it`s a pity that I can`t get through to the website you provided(py4d.pbwiki.com) these days for some unknow reason... I will have another try some days later.   Thank you.   Zhou   Morgan Martinet <yahoo@...> 写道: You can look at Demo11 and this section of the wiki: http://py4d.pbwiki.com/Using%20Threads But you鈥檒l have to be very careful鈥?lt;o> What鈥檚 your need? Only executing scripts? Does your script use Delphi objects or do you plan to provide custom modules/types to your scripts? Do you need Delphi only for the UI? Do you need to communicate between your threaded Python scripts and the main UI thread? Morgan From: pythonfordelphi@yahoogroups.com [mailto:pythonfordelphi@yahoogroups.com] On Behalf Of T ZSent: Thursday, September 07, 2006 8:37 AMTo: pythonfordelphi@yahoogroups.comSubject: 鍥炲锛?lt;/span> Re: [pythonfordelphi] Re: About the memory occupation Thanks a lot for your reply. I now know more about it, and I`ll try that out sometime. Thanks! By the way, the 10,000 line script is just a test, through which I wanted to know the speed of execution. And at present, I`m just worried about the engine of python itself. Before, I intend to execute python scripts using multi-threads in my program, that is to execute several independent scripts at the same time using different python engines. However, from the earlier letters, I got the knowledge that the python engine
should be created only for one and not be created and freed frequently due to the way python used to manage the memory. If I really want to execute several scripts at the same time, is there any suggestion for me? Zhou Richard Wright <rich@richardwright.fsbusiness.co.uk> 鍐欓亾锛?lt;/span> HiIf you really need a script of 10,000 lines then it should be split into multiple source files.Use the `import` statement to link together the source files at execution time.See the excellent Python tutorial for details of the import system.That way, individual source files are only recompiled after modification.Also, I assume (although I have not tested this) that memory useage would be much lower because the primary Python script - i.e. the one that is executed and imports functions from the others - would be much smaller.Hope this
helps!Richztdraw wrote: Thank you for replying. :)I`m using the latest P4D under Delphi2006.I found that the 38MB memory usage was just caused by the way I tested the function.Because I`m not familiar with the python syntax, I just copied the statement "P.OffsetBy(2,2)" for 10,000 times, that is more than 10,000 lines in the script. To finish executing those lines, the program took several seconds and used up 38MB memory.Today I used the "while" statement to loop for the same times, finding out that the program performed really well, and only used about 3MB memory.It seems that the memory problem is caused by the script which has too many lines. If I want to reduce the memory usage after the execution of such a large script, for
example, having more than 10,000 lines, what should I do?Thank you.--- In pythonfordelphi@yahoogroups.com, Morgan Martinet <yahoo@...> wrote:>> Hi,> > > > I just tried this demo using Delphi7 and the latest version of P4D and could> not get any memory leak!> > I tried to loop on:> > - the p=spam.CreatePoint(2,3)> > - P.OffsetBy(2,2)> > - both> > - both + print statement> > > > Give me more information on your configuration.> > > > Bye,> > > > Morgan> 聽 Mp3鐤媯鎼?lt;/span>-鏂版瓕鐑瓕楂橀熶笅
抢注雅虎免费邮箱-3.5G容量,20M附件!
Reply with quote
Send private message
Post new topic Reply to topic
Display posts from previous:   
 

All times are GMT
Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Freelace Website Designer - Customer web design and software building.
Booking Calendar - reservation calendar script
Land Surveying - total station instruments and equipments
China Wholesale - Electronics Products
Character Studio - Tutorials and Help