|
F.1 String handling
|
Business applications use a lot of strings. sheerpower is highly optimized
when handling strings.
fullname$ = 'Sally Sue'
sentence$ = fullname$ + ' was here.'
print sentence$
sentence$ = 'So I heard.'
print sentence$
Strings are handled very efficiently by sheerpower. Each string knows
its memory address, allocated size and its real size.
For example, if a string holds the
words "The rain in Spain" and later needs to hold the shorter string of
"Enjoy life", sheerpower can copy the characters from the new shorter string
into where the longer string was, repurposing its already allocated buffer.
sheerpower manages all memory use for you. You never have to worry about
memory leaks, allocations, or deallocations when using sheerpower.
It accomplishes this using a series of
memory pools that
are created as the
program runs. This is all accomplished without the use of
a "garbage collector" -- avoiding program slowdowns.
In addition, each string is given a globally unique string ID (SID). When a
string is copied, its SID is copied to the target as well. Later, sheerpower
avoids unnecessary string copies by first checking if the SIDs of the source
and target strings match. If they do, the copying process is avoided.
When using functions like
getword$(), sheerpower also uses SIDs as
part of an internal
hinting system for further efficiency. For
example, if the entire contents of the Bible is stored in the variable
bible$ and you do a
getword$(bible$, 1000) and then later you
do a
getword$(bible$, 1001), the function does not need to re-read the
first 1000 words to get to the 1001 word. It knows from the hinting system
where it last left off and returns the 1001 word immediately.
sheerpower provides memory safety without
garbage collection.
This eliminates the string handling slowdowns that other languages experience
Note: See the
fileinfo$() function for an easy way to read the entire contents of a file,
such as the Bible, into a variable.