Re: allocate() and free()
- Posted by Aku <aku at inbox.as> Dec 02, 2000
- 517 views
I have made a program in VB that free memory that do not used by the operating system. I use this code: a = space(10485760) ' Allocate 10 MB of memory for variable 'a' ' with spaces. '-------- the free memory decreases... a = "" ' Free that 10 MB. '-------- ...then increases again. I tried run this in Euphoria: object a ? getc(0) a = repeat(' ', 10485760) ? getc(0) a = "" ? getc(0) And this is a test: object a ? getc(0) -- Here, my free memory: 110 MB a = repeat(' ', 10485760) ? getc(0) -- Here, my free memory: 30 MB -- [ repeat(' ', 10485760) uses 80 MB -- of memory!!! ] a = "" ? getc(0) -- Here, my free memory is STILL 30 MB! I can free memory that is used in VB, why not in Euphoria? ______________________________________________________________________ R> free() does not give memory back to the operating R> system. It simply puts it into a pool of free memory R> that's controlled by Euphoria. It will be used by future R> calls to allocate(). R> When the pool is exhausted, allocate() will get R> more memory from the operating system, but R> free() will never give it back. R> I don't know of any language that gives R> heap space back to the operating system. R> It would be a tricky business, since you can R> theoretically only give back space at the end R> of the heap, not an arbitrary piece in the middle R> somewhere. R> In Windows, this is all virtual memory anyway. R> The operating system can swap out pages R> of memory that aren't being actively used, R> to make room for active programs to run. R> Regards, R> Rob Craig R> Rapid Deployment Software R> http://www.RapidEuphoria.com