Home > Archive > PerlTk > October 2005 > Tk memory problem?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Tk memory problem?
|
|
| sstark 2005-10-13, 6:57 pm |
| I've just built an application with Perl/Tk that reads data from groups
of files and builds a scrolled list of widgets, where users can change
settings via radiobuttons and entry fields. (Thanks to Marc D. on this
group for helping with making it scrollable.)
The app works perfectly on small-to-medium quantities of data. However
when it reads large quantities of data -- thousands of rows in the
scrolled area -- weird things start to happen. An echo of the top Label
text appears in the top left corner of the screen (outside the main
window area), and the first few rows of scrolled data never appear. (I
can scroll down and see most of it below.)
I assume this is some kind of memory problem. Does that sound right,
and is there anything I can do about it? If not I suppose I'll have to
think of a way to break the data up into smaller chunks and display
fewer at a time.
thanks
Scott
| |
| zentara 2005-10-15, 6:56 pm |
| On 13 Oct 2005 12:53:01 -0700, "sstark" <sstark@us.ibm.com> wrote:
>I've just built an application with Perl/Tk that reads data from groups
>of files and builds a scrolled list of widgets, where users can change
>settings via radiobuttons and entry fields. (Thanks to Marc D. on this
>group for helping with making it scrollable.)
>
>The app works perfectly on small-to-medium quantities of data. However
>when it reads large quantities of data -- thousands of rows in the
>scrolled area -- weird things start to happen. An echo of the top Label
>text appears in the top left corner of the screen (outside the main
>window area), and the first few rows of scrolled data never appear. (I
>can scroll down and see most of it below.)
>
>I assume this is some kind of memory problem. Does that sound right,
>and is there anything I can do about it? If not I suppose I'll have to
>think of a way to break the data up into smaller chunks and display
>fewer at a time.
>
>thanks
>Scott
Yeah, you need to paginate the output. I had to do that once before,
and will tell you it can be tricky to do without getting memory gains
in your program.
What you want to do is decide how many rows you want to display at
any one time, and reconfigure the list entries with the new data.
DON'T try to delete and create new entries for each page, you will get
a memory gain with each run of the pager.
So create say 10 entries for the Listbox display, and when you change
the page, those same 10 entries get reconfigured. That will make your
memory use stable.
Here is a basic paginator. It's best to put it in hashes.
#!/usr/bin/perl
use warnings;
use strict;
use YAML;
my @array = ( 1 .. 124);
print "@array\n";
my %pager = ();
my $count = 1;
foreach my $key (@array){
push @{$pager{$count}},$key;
if(scalar @{$pager{$count}} > 9){$count++}
}
print Dump(\%pager),"\n";
__END__
If you want to see this pagination technique in action,
see:
http://perlmonks.org?node_id=338291
Of course there are many ways to do things, so think creative.
--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html
|
|
|
|
|