On Tue, 8 Apr 2008 08:29:29 -0400, "Tom Lake" <tlake@[EMAIL PROTECTED]
>
wrote:
<snip>
>Oh, you want *easy* do you? 8^)
Old programming rule: KISS. :-)
I'm an old programmer. :-)
>My simple example was just to show how SSEG and SADD work.
>In practice, you'd use those functions to store ML routines in the
>string or to do string manipulation without fear of garbage
>collection (just make sure you DON'T change the string length!)
Or do anything else to any string. :-)
>Here's a more practical example:
>
>To change "him" to "her" you could do this:
>
>a$ = "him"
>MID$(a$, 2) = "er"
>
>but this would cause BASIC to make temp strings and
>possibly move a$ around in memory. and trigger a garbage
>collection.
It doesn't seem to, try this in QBasic:
a$ = "him"
PRINT HEX$(SADD(a$))
MID$(a$, 2) = "er"
PRINT HEX$(SADD(a$))
IIRC, the MID$ sub only does inplace operations, and I don't think it
will ever change the length of a string (but I am not sure).
FROM PDS HELP:
Usage Notes
The optional length refers to the number of characters from the
argument stringexpression$ that are used in the replacement. If
length% is omitted, all of stringexpression$ is used. However,
regardless of whether length% is omitted or included, the replacement
of characters never goes beyond the original length of
stringvariable$.
In BCET, the MID$ sub will only change characters already existing in
a string and will never change the length.
>If you do this:
>
>a$ = "him"
>Segment = SSEG(a$)
>Offset = SADD(a$)
>DEF SEG = Segment
>POKE Offset + 1, ASC("e")
>POKE Offset + 2, ASC("r")
>
>This won't trigger garbage collection and is actually
>faster than the MID$ method.
Other than taking about twice the code space, all very true.
However, you need a 'DEFINT A-Z' or some approximate DIMs in front
else QBasic & QB will use SINGLEs, and a 'DEF SEG' after to restore.
Back in the late 80's and early 90's I wrote a lot of assembler to
these kind of speed ups and code size reduction. The routine to do
what your sample was 'MidAsc' and was used like this:
MidAsc a$, 2, ASC("e")
MidAsc a$, 3, ASC("r")
Although I would normally have coded it as
MidAsc a$, 2, 101 ' ASC("e")
MidAsc a$, 3, 114 ' ASC("r")
which saves an additional 16 bytes of code space & 2 string constants.
A quick look at that library source shows:
; MidAsc Written on 09/16/93
I am not sure why MidAsc was ever written unless it was for speed.
It's calling sequence is not really any smaller that the normal MID$
sub.
--
ArarghMail804 at [drop the 'http://www.'
from ->] http://www.arargh.com
BCET Basic Compiler Page: http://www.arargh.com/basic/index.html
To reply by email, remove the extra stuff from the reply address.


|