Hi John,<div><br></div><div>    privately...<br><br><div class="gmail_quote">On Fri, Jul 24, 2009 at 4:02 PM, John M McIntosh <span dir="ltr">&lt;<a href="mailto:johnmci@smalltalkconsulting.com">johnmci@smalltalkconsulting.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="im"><br>
<br>
On 24-Jul-09, at 3:42 PM, Eliot Miranda wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
...stinks.<br>
<br>
I&#39;m talking about sqAllocateMemory.  Here&#39;s the base definition from platforms/Cross/vm/sq.h:<br>
<br>
#define sqAllocateMemory(minHeapSize, desiredHeapSize)  malloc(desiredHeapSize)<br>
<br>
The problem here is that there&#39;s no obvious way for the client to know how much memory is returned.  The signature implies it is somewhere between minHeapSize &amp; desiredHeapSize inclusive (or null, if allocation failed).  But how do you tell?  Well, one could always ask to grow memory by 0 and see what you get back, except for the small chicken-and-egg problem that sqGrowMemory:By: and sqShrinkMemory:By: require the ammount of memory allocated as an argument:<br>

<br>
#define sqGrowMemoryBy(oldLimit, delta)         oldLimit<br>
#define sqShrinkMemoryBy(oldLimit, delta)       oldLimit<br>
<br>
So one has to go to extraordinary lengths that are completely non-obvious in the client code to actually pass-back the ammount allocated.  Here&#39;s a client in readImageFromFile:<br>
<br>
        &quot;allocate a contiguous block of memory for the Squeak heap&quot;<br>
        memory := self cCode: &#39;sqAllocateMemory(minimumMemory, heapSize)&#39;.<br>
        memory = nil ifTrue: [self insufficientMemoryAvailableError].<br>
<br>
        memStart := self startOfMemory.<br>
        self setMemoryLimit: (memStart + heapSize) - 24. &quot;decrease memoryLimit a tad for safety&quot;<br>
        self setEndOfMemory: memStart + dataSize.<br>
<br>
</blockquote>
<br>
<br></div>
Somehow that looks dated? Since it now reads<div class="im"><br>
<br>
        &quot;allocate a contiguous block of memory for the Squeak heap&quot;<br>
        memory := self<br></div>
                allocateMemory: heapSize<br>
                minimum: minimumMemory<br>
                imageFile: f<br>
                headerSize: headerSize.<div class="im"><br>
        memory = nil ifTrue: [self insufficientMemoryAvailableError].<br>
<br></div>
which turns into<br>
<br>
        memory = allocateMemoryMinimumImageFileHeaderSize(heapSize, minimumMemory, f, headerSize);<br>
        if (memory == null) {<br>
                insufficientMemoryAvailableError();<br>
        }<br>
<br>
which is<br>
 #define allocateMemoryMinimumImageFileHeaderSize(heapSize, minimumMemory, fileStream, headerSize) \<br>
    sqAllocateMemory(minimumMemory, heapSize)<br>
#endif<br>
</blockquote><div><br></div><div>Yes, but that&#39;s beside the point.  The basic issue still remains.  I&#39;d still like your opinion on the question asked.  Would you be willing to answer again?  Don&#39;t assume that all platforms will reserve the entire memory. Yes, all the platforms we use here do but a bare metal port might still use malloc.</div>
<div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><br>
but on iPhone and mac is<br>
<br>
#define allocateMemoryMinimumImageFileHeaderSize(heapSize, minimumMemory, fileStream, headerSize) \<br>
        sqAllocateMemoryMac(heapSize, minimumMemory, fileStream, headerSize)<br>
<br>
and<br>
<br>
sqAllocateMemoryMac<br>
<br>
On the iPhone let&#39;s you vmap in the image from offset  500*1024*1024 plus header size  to the size of the image file rounded up 4K pages.<br>
After that the free space is mmap anonymous upto the total  heapsize, we ignore minimumMemory.<br>
For WikiServer a 10MB image, then  6MB gets paged in from flash, 4MB is not touched.<br>
The sqImageFileReadEntireImage does nothing.<br>
<br>
On the macintosh the total heap size is mmapped anonymously  at the  500*1024*1024 boundary plus header size, the sqImageFileReadEntireImage<br>
then reads the image file into the mmap region.  I note that I had the same code here from the iPhone but it was discovered there is a bug with mmapped<br>
files being read from NFS disks so the feature was made optional. It does btw save a few 100 ms at startup time on slower machines (500 Mhz)<br>
But the macintosh virtual memory system does read all the pages from the file into RAM, versus the iPhone which does not.<br><font color="#888888">
--<br>
===========================================================================<br>
John M. McIntosh &lt;<a href="mailto:johnmci@smalltalkconsulting.com" target="_blank">johnmci@smalltalkconsulting.com</a>&gt;   Twitter:  squeaker68882<br>
Corporate Smalltalk Consulting Ltd.  <a href="http://www.smalltalkconsulting.com" target="_blank">http://www.smalltalkconsulting.com</a><br>
===========================================================================<br>
<br>
<br>
<br>
<br>
</font></blockquote></div><br></div>