You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Forth words typically use the following approaches to the return string, concerning its life time:
the string is valid until the next call to the word that has returned this string or other word that uses the same buffer (usually, in the same thread/task, if in multithreaded system);
for example, a word like u-to-s ( u -- c-addr u ) (unsigned number to string), which always returns a string in the same transient buffer:
the string is valid until some other specific word is called (a mutator method);
typically, dynamic string variables behave in this way, since a new memory range can be allocated for a new value;
the string is associated with some object and is valid as long as the object is live;
for example, a name of a word is stored in the header and the corresponding string is valid as long as the word is not removed;
another example: a list of key-value pairs of strings, which retains the strings until the list is deleted;
yet another example: a string is formally associated with a nest-sys (a stack frame or activation frame) and it is indirectly available in a callback, — this string is valid until execution of the corresponding word is complete;
the return string is a newly allocated string and it is valid until the caller/client releases it using free or other specific word;
this approach is more often used for other objects (e.g., file handlers) rather than strings;
Some mix of above approaches.
Maybe some other approaches?
Whatever approach is used in an API, the life time of the return strings should be carefully documented.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Forth words typically use the following approaches to the return string, concerning its life time:
u-to-s ( u -- c-addr u )
(unsigned number to string), which always returns a string in the same transient buffer:: u-to-s ( u -- sd ) 0 <# #s #> ;
block
(see 7.3.2 Block buffer regions);free
or other specific word;Maybe some other approaches?
Whatever approach is used in an API, the life time of the return strings should be carefully documented.
Beta Was this translation helpful? Give feedback.
All reactions