[M3devel] heap vs. stack? (sort of)

Jay jayk123 at hotmail.com
Mon Jan 28 10:48:31 CET 2008


Is it possible to have this pattern in Modula-3:
 
PROCEDURE Parse (nm: TEXT;  host: BOOLEAN): T =  VAR len := Text.Length (nm);   buf: ARRAY [0..255] OF CHAR;  BEGIN    IF (len <= NUMBER (buf))      THEN RETURN DoParse (nm, SUBARRAY (buf, 0, len), host);      ELSE RETURN DoParse (nm, NEW (REF ARRAY OF CHAR, len)^, host);    END;  END Parse;
 
PROCEDURE DoParse (nm_txt: TEXT;  VAR nm: ARRAY OF CHAR;  host: BOOLEAN): T =
 
without the extra function?
 
There are places in M3Path.m3 that duplicate code otherwise, one branch acting on a local stack allocated array, the other acting on a heap allocated array when the stack array is too small, but otherwise identical code.
 
So far I have not figured out how. Local variables cannot be open array. SUBARRAY returns an ARRAY and not a REF ARRAY... It seems that parameters can be open arrays but local variables cannot, and that seems wrong.. parameters and locals so often share characteristics...
 
 - Jay
_________________________________________________________________
Need to know the score, the latest news, or you need your Hotmail®-get your "fix".
http://www.msnmobilefix.com/Default.aspx
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://m3lists.elegosoft.com/pipermail/m3devel/attachments/20080128/3dc16a80/attachment-0001.html>


More information about the M3devel mailing list