<html>
<head>
<style>
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
FONT-SIZE: 10pt;
FONT-FAMILY:Tahoma
}
</style>
</head>
<body class='hmmessage'>I totally want common code, there's just no point in moving it into a separate function.<BR>
For now I used a separate function, and I made it nested.<BR>
I also tried WITH that got its value from "PickBuffer", also a useless function but at least small, but functions can't return open arrays.<BR>
<BR>
The problem with heap allocation is that it is slow. This code is optimizing it away in the first place for "small" strings, that's not my doing. Of course you have to pick some heuristic "small" and hope not to blow too much wasted stack. 256 bytes of stack is not small sometimes.<BR>
<BR>
It appears that nested functions have to occur up in the variable section but that is very dificult to glean from the documentation or the error messages. Blech.<BR>
<BR>
- Jay<BR><BR><BR>
<HR id=stopSpelling>
<BR>
> Date: Mon, 28 Jan 2008 12:39:10 +0100<BR>> From: lemming@henning-thielemann.de<BR>> Subject: Re: [M3devel] heap vs. stack? (sort of)<BR>> To: jayk123@hotmail.com<BR>> CC: m3devel@elegosoft.com<BR>> <BR>> <BR>> On Mon, 28 Jan 2008, Jay wrote:<BR>> <BR>> > Is it possible to have this pattern in Modula-3:<BR>> ><BR>> > 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;<BR>> ><BR>> > PROCEDURE DoParse (nm_txt: TEXT; VAR nm: ARRAY OF CHAR; host: BOOLEAN): T =<BR>> <BR>> I think it is a good idea to encapsulate the common code in DoParse. If<BR>> DoParse needs local variables, it can be turned into a local PROCEDURE of<BR>> Parse. On the other hand I doubt that it is sensible to reserve 256 bytes<BR>> on the stack also if they are not used, or only a part of them are used.<BR>> What's bad about always using NEW? I think Modula-3's memory management<BR>> has optimizations for small amounts of memory.<BR><BR><br /><hr />Helping your favorite cause is as easy as instant messaging. You IM, we give. <a href='http://im.live.com/Messenger/IM/Home/?source=text_hotmail_join' target='_new'>Learn more.</a></body>
</html>