[comp.unix.questions] Unix V.4 gettxt

mdv@comtst.domain.com (Mike Verstegen) (09/13/90)

We are planning to migrate to the SVR4 messaging system using the text
strings routines designed for multiple locales such as gettxt().

In reading the documentation for gettxt(3C) (from the AT&T Unix SVR4
Programmer's Reference Manual) it gives a good write-up on how to call
the function, but it does not address on important point. Does the return
value "point to static data which is overwritten with each call" or is the
point good for multiple uses?

For example can I say

...
msg1 = gettxt("MYAPP:1", "hello ");	/* cache these messages */
msg2 = gettxt("MYAPP:2", "world");
...
printf ("%s%s\n", msg1, msg2);

or do I have to say
...
printf ("%s%s\n", gettxt("MYAPP:1", "hello "), gettxt("MYAPP:2", "world"));

and incur the expense of a gettxt call each time.

I know I could malloc my own space and copy this strings into my own space,
but we will have many copies of this application running and a private copy
obviously increases the working set of each copy (increasing paging activity
etc). This seems to be a good candidate for a memory mapped file.

Could someone with access to the source take a look and see what this thing
returns? Also does any one know a good channel to route message to for AT&T
documentation comments. It seems like this routine should document one way
or the other what it returns.

gwyn@smoke.BRL.MIL (Doug Gwyn) (09/14/90)

In article <145@comtst.UUCP> mdv@comtst.domain.com (Mike Verstegen) writes:
>Does the return value "point to static data which is overwritten with each
>call" or is the point good for multiple uses?

Without even looking at the code, you can pretty much figure out what
the answer must be.  There are essentially three possibilities for the
implementation of gettxt() in this regard:
	(A) return pointer to dynamically allocated space containing a
	    copy of the relevant message
	(B) return pointer to static buffer that is reused across calls
	(C) return pointer to member of array or structure containing
	    all messages
Alternative (C) is unlikely, as it would force the entire set of messages
to be hard-wired into the library.  Alternative (A) is unlikely, as it
would result in gradually losing more and more dynamic memory as gettxt()
is invoked multiple times.  So I would simply assume that (B) is the
probable answer.  Since that is the worst case anyway (from your point
of view), it seems like a good assumption to make.