1. where does the memory go?
- Posted by Colin Taylor <71630.1776 at COMPUSERVE.COM>
Oct 07, 1997
-
Last edited Oct 08, 1997
This little program gobbles up over 2megs of RAM, and won't give it back.=
=
Where is the dynamic memory allocation?
Colin Taylor
--< start code >--
include get.e
include memory.e -- by J. Deschenes
sequence seq, size
integer xms, last, key
seq =3D {}
size =3D "small"
xms =3D FreeXMS()
procedure show_mem()
last =3D xms
xms =3D FreeXMS()
printf(1, "%s sequence, ", {size})
printf(1, "free XMS =3D %d, ", xms)
printf(1, "change =3D %d\n", last-xms)
end procedure -- show_mem
function xyz(sequence s)
return s*1
end function -- xyz
clear_screen()
puts(1, "Press a key; or l for large seq, s for small seq, q to quit\n")
while 1 do
show_mem()
seq =3D xyz(seq)
key =3D wait_key()
if key =3D 'l' then
seq =3D repeat({1}, 25000) -- make large sequence
size =3D "large"
elsif key =3D 's' then
seq =3D {1} -- make small sequence
size =3D "small"
elsif key =3D 'q' then
exit
end if
end while
--< end >--
2. Re: where does the memory go?
Colin Taylor writes:
> This little program gobbles up over 2megs of RAM, and won't give it back.
I tried your example on my machine and it crashed with a Causeway error.
So I copied safe.e (from the Recent User Contributions page)
into the directory and renamed it as machine.e. When I ran
the program again it failed with "BAD POKE ADDRESS..."
There appears to be a bug in Jacques memory routines.
(Jacques: take a look at GetPageSize - I think you call poke_int()
where perhaps you meant to call poke(). After a quick band-aid patch it
went further and had a peek() failure - please get safe.e and try it, thanks.)
It will be interesting to try it again once Jacques makes the fix.
Jacques, if you are too busy, I can try to figure it out, but it's 1:00 AM
already.
Regards,
Rob Craig
Rapid Deployment Software
3. Re: where does the memory go?
At 05:00 AM 10/8/97 UT, you wrote:
>
>Jacques, if you are too busy, I can try to figure it out, but it's 1:00 AM
>already.
Gripe gripe gripe. :)
I assume you're needing that much time during the day, anyway, to finish up
the Win32 and Linux versions, right?
BTW, if anybody around here has $1.5 million they can invest (payback
includes interest and equity kicker), please let me know. Internet business
starting. IF I had EUPHORIA for Linux (or maybe PowerPC), I just might be
using it for the business. As it is, I'm using some Java and off-the-shelf
apps. :)
4. Re: where does the memory go?
- Posted by Robert Craig <rds at CLASSIC.MSN.COM>
Oct 09, 1997
-
Last edited Oct 10, 1997
Colin Taylor wrote:
> This little program gobbles up over 2megs of RAM, and won't give it back.
Jacques Deschenes fixed his memory.e file
and the new version is now available as memory.zip
on the User Contributions page.
Using the fixed version with Colin Taylor's example program
I got somewhat inconsistent results. In a Win95 DOS window,
the example program showed 0 memory used. When I rebooted
in pure DOS mode, it showed 102K used, then it jumped
to 1.2 Mb on the next iteration and stayed there.
Here's what is happening:
The line that says:
seq = repeat({1}, 25000) -- make large sequence
will use a little over 100K (25000 times 4 bytes), because
there will be 25000 pointers to a single copy of {1}.
That would explain the first 102K value I saw.
Later, the example calls function xyz() to compute:
seq * 1
and return it as a result.
Unfortunately, the result of s * 1 will have 25000 *separate* copies of {1}
rather than 25000 pointers to a single shared copy. Instead of using
4 bytes per copy, it will need much more. There are several pieces of
overhead information stored for each sequence. 1.2M/100K = a factor of
12. This would imply that {1} uses 12*4 = 48 bytes. That is too high.
It's more like 32 bytes, but for efficiency the storage allocator may be
grabbing more from the O/S than it immediately needs. Once it grabs it,
it won't return it. It will keep it for possible further use in the Euphoria
program.
Regards,
Rob Craig
Rapid Deployment Software