This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Reduce stack usage of _vfiprintf_r()


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]