1. Release memory?
- Posted by Juergen Luethje <jluethje at gmx.de> Sep 18, 2002
- 569 views
Hi all, I've got a question about sequences. For instance, assume the following code: ----------------------------------- include file.e object list sequence file_list, entry file_list = {} list = dir("test.*") if sequence(list) then for i = 1 to length(list) do entry = list[i] if not find('d', entry[D_ATTRIBUTES]) then file_list = append(file_list, entry[D_NAME]) end if end for list = {} -- ? entry = {} -- ? end if ? length(file_list) ----------------------------------- If I don't use 'list' and 'entry' any more in the rest of the program, is it a good idea to assign empty sequences to them in order to release memory? Thanks in advance, Juergen
2. Re: Release memory?
- Posted by r.schr at t-online.de Sep 18, 2002
- 521 views
Juergen Luethje wrote: > > > Hi all, > > I've got a question about sequences. For instance, assume the following > code: > > ----------------------------------- > include file.e > object list > sequence file_list, entry > > file_list = {} > list = dir("test.*") > if sequence(list) then > for i = 1 to length(list) do > entry = list[i] > if not find('d', entry[D_ATTRIBUTES]) then > file_list = append(file_list, entry[D_NAME]) > end if > end for > list = {} -- ? > entry = {} -- ? > end if > ? length(file_list) > ----------------------------------- > > If I don't use 'list' and 'entry' any more in the rest of the program, > is it a good idea to assign empty sequences to them in order to release > memory? Hi Juergen, why you don't put this code into a function and return only length(...)? After leaving the function, all private variables should be freed?! Have a nice day, Rolf
3. Re: Release memory?
- Posted by Derek Parnell <ddparnell at bigpond.com> Sep 18, 2002
- 549 views
>From my understanding, this action will only "release" memory for the application to reuse, it will not release memory for other applications. Each time a Euphoria program need more memory for a sequence operation, the memory is taken from the program's heap, but if the heap is not large enough the program grabs a bit more RAM from the operating system (thus increasing the size of th eprogram's heap), and the heap is not returned until the program ends. This also applies to allocate() and allocate_string() calls. It does not apply to the Win32lib memory allocation routines, as these return freed heap allocations back to Windows - thus allowing them to be used by other Windows programs. ---------------- cheers, Derek Parnell ----- Original Message ----- From: <r.schr at t-online.de> To: "EUforum" <EUforum at topica.com> Sent: Thursday, September 19, 2002 5:21 AM Subject: Re: Release memory? > > Juergen Luethje wrote: > > > > > > Hi all, > > > > I've got a question about sequences. For instance, assume the following > > code: > > > > ----------------------------------- > > include file.e > > object list > > sequence file_list, entry > > > > file_list = {} > > list = dir("test.*") > > if sequence(list) then > > for i = 1 to length(list) do > > entry = list[i] > > if not find('d', entry[D_ATTRIBUTES]) then > > file_list = append(file_list, entry[D_NAME]) > > end if > > end for > > list = {} -- ? > > entry = {} -- ? > > end if > > ? length(file_list) > > ----------------------------------- > > > > If I don't use 'list' and 'entry' any more in the rest of the program, > > is it a good idea to assign empty sequences to them in order to release > > memory? > > Hi Juergen, > > why you don't put this code into a function and return only length(...)? > After leaving the function, all private variables should be freed?! > > Have a nice day, Rolf > > > >
4. Re: Release memory?
- Posted by petelomax at blueyonder.co.uk Sep 18, 2002
- 533 views
On Wed, 18 Sep 2002 20:46:02 +0200, Juergen Luethje <jluethje at gmx.de> wrote: >If I don't use 'list' and 'entry' any more in the rest of the program, >is it a good idea to assign empty sequences to them in order to release >memory? The short answer is use local variables to the function/procedure where possible. If that is not practical, and they are big, then yes. Small things just tend to end up in the swap file and cause no further problems. In one case (file comparison) I had: seq loca, locb func, proc, func, ... global procedure(seq a,seq b) loca=a locb=b -- kinda need them global where a & b were the entire contents of the files I was comparing, so rather than pass them to each & every local procedure & function, as above I [lazily] made local "copies" of them. In the above include file, loca & locb took near zero space (just pointers to a & b), despite a and b themselves being rather large. However, I found that coding a={} and b={} in the calling procedure then had no effect but adding loca{} and locb{} at the end of the include file improved things quite a bit. So, in summary, often it makes no odds, but if you need to do it make sure there are no other references to the variable contents. Pete PS it also makes your ex.err alot smaller.
5. Re: Release memory?
- Posted by rolf.schroeder at desy.de Sep 19, 2002
- 548 views
Derek Parnell wrote: > ... > Each time a Euphoria program need more memory for a sequence operation, the > memory is taken from the program's heap, but if the heap is not large enough > the program grabs a bit more RAM from the operating system (thus increasing > the size of th eprogram's heap), and the heap is not returned until the > program ends. > > This also applies to allocate() and allocate_string() calls. > Derek, I'm not sure if this really is true. I run lots of EU-programs on a WinNT machine, and when I watch the memory consumption of each program, then I watch during one inner program loop increasing and decreasing memory consumption which means in my opinion that memory is returned to the OS (I don't use allocate() and free()). But the true expert (about the lots of experts on the list) is Rob. Rob? Nave a nice day, Rolf
6. Re: Release memory?
- Posted by Derek Parnell <ddparnell at bigpond.com> Sep 19, 2002
- 519 views
You could be right. I vaguely remember Rob saying something about Eu just using the stock standard malloc() that comes with the C compilers he uses. Maybe they are clever enough to use Windows heaps when running on NT? 19/09/2002 5:10:46 PM, rolf.schroeder at desy.de wrote: > >Derek Parnell wrote: > >> ... >> Each time a Euphoria program need more memory for a sequence operation, the >> memory is taken from the program's heap, but if the heap is not large enough >> the program grabs a bit more RAM from the operating system (thus increasing >> the size of th eprogram's heap), and the heap is not returned until the >> program ends. >> >> This also applies to allocate() and allocate_string() calls. >> > >Derek, > >I'm not sure if this really is true. I run lots of EU-programs on a >WinNT machine, and when I watch the memory consumption of each program, >then I watch during one inner program loop increasing and decreasing >memory consumption which means in my opinion that memory is returned to >the OS (I don't use allocate() and free()). > >But the true expert (about the lots of experts on the list) is Rob. Rob? > >Nave a nice day, Rolf > > > > --------- Cheers, Derek Parnell ICQ# 7647806
7. Re: Release memory?
- Posted by Robert Craig <rds at RapidEuphoria.com> Sep 19, 2002
- 561 views
Rolf Schroeder writes: > I run lots of EU-programs on a WinNT machine, and when I watch > the memory consumption of each program, then I watch during > one inner program loop increasing and decreasing memory consumption > which means in my opinion that memory is returned to the OS > (I don't use allocate() and free()). > > But the true expert (about the lots of experts on the list) is Rob. Rob? The Euphoria interpreter and translator both use C's malloc() and free(). These do not give memory back to the operating system. The memory that they manage is returned when the process terminates. Perhaps you are not monitoring the total virtual memory used, but rather the amount of memory that's actually in RAM (not paged out to disk by the O/S) from one moment to the next. Juergen Luethje writes: > ... > list = {} -- ? > entry = {} -- ? > end if > ? length(file_list) > If I don't use 'list' and 'entry' any more in the rest of the program, > is it a good idea to assign empty sequences to them in order to release > memory? When you assign {}, if there are no other references to the data, the space will be returned to the heap. This will make the space available for new sequences (or floating-point numbers) that you might create in the future. Note that private variables of a routine are freed automatically when the routine returns. If your program is not at risk of running out of memory, there is nothing to be gained by assigning {}. It will just confuse the reader of your program. Regards, Rob Craig Rapid Deployment Software http://www.RapidEuphoria.com
8. Re: Release memory?
- Posted by Juergen Luethje <jluethje at gmx.de> Sep 21, 2002
- 537 views
Thanks to all for the informative replies! Best regards, Juergen