<html>
<head>
<style>
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
FONT-SIZE: 10pt;
FONT-FAMILY:Tahoma
}
</style>
</head>
<body class='hmmessage'><FONT face="Courier New, Courier, Monospace">How can I write this in idiomatic Modula-3:</FONT><BR>
<BR><FONT face="Courier New, Courier, Monospace"> date : Date.T<BR> Fmt.FN( (* heap alloc *)<BR> "%04s-%02s-%02s %02s:%02s:%02s",<BR> ARRAY OF TEXT{ (* heap alloc? easily avoided, but just over the limit *)<BR> Fmt.Int(date.year), (* heap alloc *)<BR> Fmt.Int(ORD(date.month) + 1), (* heap alloc *)<BR> Fmt.Int(date.day), (* heap alloc *)<BR> Fmt.Int(date.hour), (* heap alloc *)<BR> Fmt.Int(date.minute), (* heap alloc *)<BR> Fmt.Int(date.second) (* heap alloc *)<BR> })));</FONT><BR>
<BR><FONT face="Courier New, Courier, Monospace">to be more like in performance to:</FONT><BR>
<BR><FONT face="Courier New, Courier, Monospace"> Date_t date; /* Win32 SYSTEMTIME essentially */<BR> char Buffer[sizeof("2008-01-01 20:29:58")];<BR> sprintf(<BR> Buffer,<BR> "%04u-%02u-%02u %02u:%02u:%02u",<BR> date.year,<BR> ORD(date.month) + 1,<BR> date.day,<BR> date.hour,<BR> date.minute,<BR> date.second);</FONT><BR>
<BR><FONT face="Courier New, Courier, Monospace">or, ok:</FONT><BR>
<BR><FONT face="Courier New, Courier, Monospace"> Date_t date; /* Win32 SYSTEMTIME essentially */<BR> char* Buffer = (char*) malloc(sizeof("2008-01-01 20:29:58")); /* deliberate heap alloc for long lived string */<BR> if (Buffer== NULL)</FONT><BR>
<FONT face="Courier New, Courier, Monospace">...<BR> sprintf(<BR> Buffer,<BR> "%04u-%02u-%02u %02u:%02u:%02u",<BR> date.year,<BR> ORD(date.month) + 1,<BR> date.day,<BR> date.hour,<BR> date.minute,<BR> date.second);</FONT><BR>
<BR><FONT face="Courier New, Courier, Monospace">Unnecessary heap allocations bug me.</FONT><BR>
<BR><FONT face="Courier New, Courier, Monospace">I seem to see a fair amount of tedious Modula-3 code around to avoid heap allocs,<BR>folks manually managing growing arrays instead of using something generic and efficient.</FONT><BR>
<BR><FONT face="Courier New, Courier, Monospace">Can "safe" code be efficient and convenient to write?</FONT><BR>
<BR><FONT face="Courier New, Courier, Monospace">(and yes, I know about snprintf, sprintf_s, etc.)</FONT><BR>
<BR><FONT face="Courier New, Courier, Monospace"> - Jay</FONT><BR><br /><hr />The best games are on Xbox 360. Click here for a special offer on an Xbox 360 Console. <a href='http://www.xbox.com/en-US/hardware/wheretobuy/' target='_new'>Get it now!</a></body>
</html>