Reduce stack usage of _vfiprintf_r()

Freddie Chopin freddie_chopin@op.pl
Wed Oct 10 19:23:00 GMT 2012


W dniu 2012-10-10 18:27, Federico Terraneo pisze:
> I seem to be missing something: the cod you posted contains an
> unconditional
>
> buf = _malloc_r(rptr, BUFSIZ);
>
> which as I have understood is a replacement for
>
> unsigned char buf[BUFSIZ];
>
> Now, if the function is never called, the buffer is never allocated in
> both cases. On the other hand, if the function gets called, in both
> cases it will reserve 1024 bytes, either on the heap or the stack. I
> don't see how your patch would entirely prevent the reservation of
> 1024 bytes in the case of unbuffered streams.

See my previous posts - __sbprintf() is inlined into _vfiprintf_r() 
(because it's static and used only in __vfiprintf_r()), thus the buffer 
on stack is ALWAYS allocated, while the dynamic allocation is performed 
only is the code is executed.

Regards,
FCh



More information about the Newlib mailing list