[comp.windows.x] HELP - XmStringCreateLtoR

walter (Walter Steinemann) (04/30/91)

I have the following in many places within my code:

	char msg[80];
	XmString	xmMessage;

	... msg gets seto to some short string (20-30 bytes)...

	xmMessage = XmStringCreateLtoR( msg, XmSTRING_DEFAULT_CHARSET );


I get the message "Error: Cannot perform malloc" (nothing else) and my
application exits (no core file), but not always on the same call to
XmStringCreateLtoR.  My application code does not use this string, but
I have found that this string is in libXt.a, in the Alloc.c section.

I thought perhaps the Motif Library had some build in limit on the
number of compound strings, so I inserted calls to XmStringFree for
all my XmStringCreates - but the error still occurs.  [BTW, when is it
safe to do the free? ... after that SetArg or after the SetValues, or
does it need to be done much later??]

Am I doing something wrong? Is something wrong with Motif or Xt?
We have Motif 1.1.1 and IRIX 3.3.2 on a PI 4D/25.

Thanks for any help you can give me,
-- WalteR --
-- 
Walter R. Steinemann                    HYPERCUBE, INC.
                                        #7-419 Phillip Street
Phone:  (519) 725-4040                  Waterloo, Ontario
email:  walter@hyper.com                N2L 3X2

pd@x.co.uk (Paul Davey) (05/01/91)

>>>>> On 29 Apr 91 19:27:48 GMT, walter (Walter Steinemann) said:


Walter> I have the following in many places within my code:

Walter> 	char msg[80];
Walter> 	XmString	xmMessage;

Walter> 	... msg gets seto to some short string (20-30 bytes)...

Is msg null terminated? 

Walter> 	xmMessage = XmStringCreateLtoR( msg, XmSTRING_DEFAULT_CHARSET );


Walter> I get the message "Error: Cannot perform malloc" (nothing else) and my
Walter> application exits (no core file), but not always on the same call to
Walter> XmStringCreateLtoR.  My application code does not use this string, but
Walter> I have found that this string is in libXt.a, in the Alloc.c section.

Walter> I thought perhaps the Motif Library had some build in limit on the
Walter> number of compound strings, so I inserted calls to XmStringFree for
Walter> all my XmStringCreates - but the error still occurs.  [BTW, when is it
Walter> safe to do the free? ... after that SetArg or after the SetValues, or
Walter> does it need to be done much later??]

You can free after the XtSetValues if your not using the string again.

Walter> Am I doing something wrong? Is something wrong with Motif or Xt?
Walter> We have Motif 1.1.1 and IRIX 3.3.2 on a PI 4D/25.

Well, it's clearly a memory problem somewhere. You should free
XmStrings as soon as you have finished with them. Motif will not reuse
the memory. Look out for any other toolkit allocated memory that you
are not freeing. (eg the returned data from XmStringGetLtoR).
--
 Regards,			 pd@x.co.uk          IXI Limited
	Paul Davey		 pd@ixi.uucp         62-74 Burleigh St.
				 ...!uunet!ixi!pd    Cambridge  U.K.
 "These are interesting times"   +44 223 462 131     CB1  1OJ      
				 USA: 1 800 XDESK 57