sprintf allocates mem from heap if use %f

Luke Diamand lgd@virata.com
Tue Nov 16 01:36:00 GMT 1999


David Williams wrote:
> 
> Hi All,
> 
> I discovered that when I use floating point formats in calls to sprintf()
> (eg %f) then a small amount of dynamic memory is required. My system does
> not require any dynamic memory but I would like to be able to use sprintf()
> to format floating point values. Is there anyway of not using dynamic
> memory, short of patching the library (newlib) or writing my own floating
> point formating routine.

sprintf ultimately ends up using dtoa. There is a version of dtoa
written by David. M. Gay of Lucent Technologies, (with a free copyright)
which can be configured to use a private block of memory rather than
malloc/free. 

Note that in some extreme circumstances it will still call malloc/free,
although you can adjust this via a #define.

I believe that this code is where the GNU libc dtoa code is derived
from.


You can get it (IIRC) from http://www.netlib.org .

HTH!
Luke Diamand

-- 
Virata http://www.virata.com
Cambridge
Tel: +44 1223 566919      Fax: +44 1223 566915

------
Want more information?  See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/
Want to unsubscribe? Send a note to crossgcc-unsubscribe@sourceware.cygnus.com



More information about the crossgcc mailing list