I wish to change any unprintable characters to a visual reporesentation
(eg: "" ) in an XmText widget.

Right now, I use XmTextGetString to get a copy which I use to find
nonprintable characters and then use the offset into that buffer to call XmTextReplace.

However, wben expanding from nonprintable to printable (5 characters
instead of 1), it is slow, I guess because XmText widget needs to
realloc the memory block every time and then shuft text. Going from the
printable to non printable is much quicker.

Is there a way to greatly increase the speed of multiple XmTextReplace ?

Or is the only real way to do this to use XmTextGetString to a buffer,
then use one XtRealloc to grow the buffer, then make the changes
manually in the buffer and then send it back to the XmTest widget ?

Any other tricks ?

Using XmTextReplace is elegant because it is not only cleaner, but also
alleviates the need to generate yet another copy of the text in memory.