寻找有状态的snprintf [英] looking for statefull snprintf

查看:68
本文介绍了寻找有状态的snprintf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好


这是我的情况:我有一个char buf [1024];用作日志输出的缓冲区


。通常,我这样做:


rc = snprintf(buf,sizeof(buf),some_format,some_args);


这使我的格式化输出然后我刷新缓冲区。

在90%的情况下这很好用,当格式或

参数需要1024以上的情况下执行格式化输入的字节。

没有简单的方法可以重新运行snprintf()表单''last''的位置。


假设使用asprintf (),另一个缓冲区和其他种类的

malloc()不是一个选项。假设缓冲区必须在它到达实际的io之前进行预处理




是否有任何打开/关闭的库可以解决问题?是否有关于该主题的任何讨论?
?请提供参考资料。


谢谢

-

迪玛

Hello

Here is my situation: I have a char buf[1024]; that is used as a buffer

for a log output. Normally, I do:

rc = snprintf( buf, sizeof(buf), some_format, some_args );

This makes the formatting my output and then I flush the buffer.
In 90% of cases this works well, exept the cases when the format or the

arguments require more then 1024 bytes of formatted input.
There is no easy way to re-run snprintf() form ''last'' position.

Suppose that using of asprintf(), another buffer and other kinds of
malloc() is not an option. Suppose the buffer must be preprocessed
before it hits the actual io.

Is there any open/closed libraries that solve the problem? Are there
any discussions held on the subject? Please provide the references.

Thanks
--
Dima

推荐答案

2006-08-17,dimka< di ************ @ gmail.comwrote:
On 2006-08-17, dimka <di************@gmail.comwrote:

你好


这是我的情况:我有一个char buf [1024];用作日志输出的缓冲区


。通常,我这样做:


rc = snprintf(buf,sizeof(buf),some_format,some_args);


这使我的格式化输出然后我刷新缓冲区。

在90%的情况下这很好用,当格式或

参数需要1024以上的情况下执行格式化输入的字节。

没有简单的方法可以重新运行snprintf()表单''last''的位置。


假设使用asprintf (),另一个缓冲区和其他种类的

malloc()不是一个选项。假设缓冲区必须在它到达实际的io之前进行预处理




是否有任何打开/关闭的库可以解决问题?是否有关于该主题的任何讨论?
?请提供参考资料。
Hello

Here is my situation: I have a char buf[1024]; that is used as a buffer

for a log output. Normally, I do:

rc = snprintf( buf, sizeof(buf), some_format, some_args );

This makes the formatting my output and then I flush the buffer.
In 90% of cases this works well, exept the cases when the format or the

arguments require more then 1024 bytes of formatted input.
There is no easy way to re-run snprintf() form ''last'' position.

Suppose that using of asprintf(), another buffer and other kinds of
malloc() is not an option. Suppose the buffer must be preprocessed
before it hits the actual io.

Is there any open/closed libraries that solve the problem? Are there
any discussions held on the subject? Please provide the references.



我不确定图书馆,但你可以查看代码为
Chuck Falconers ggets( )代码(Google),或我的

ioutils包中的一些内容(请参阅我的sig链接)。


查克的代码将给出你对如何阅读无限制

数量的数据有所了解,而且我有一些最小的输入解析你可能会想要检查出来。

想要查看。


-

Andrew Poelstra< http://www.wpsoftware.net/projects>

要通过电子邮件与我联系,请使用` apoelstra''在上述领域。

电缆的末端是否需要插入? -Anon。

I''m not sure about libraries, but you could check out the code for
Chuck Falconers ggets() code (Google), or some of the stuff in my
ioutils package (see my sig for link).

Chuck''s code will give you some idea on how to read in "unlimited"
amounts of data, and mine has some minimal input parsing you might
want to check out.

--
Andrew Poelstra <http://www.wpsoftware.net/projects>
To reach me by email, use `apoelstra'' at the above domain.
"Do BOTH ends of the cable need to be plugged in?" -Anon.


" dimka" < di ************ @ gmail.comwrites:
"dimka" <di************@gmail.comwrites:

这是我的情况:我有一个char buf [1024];用作日志输出的缓冲区

。通常,我这样做:


rc = snprintf(buf,sizeof(buf),some_format,some_args);


这使我的格式化输出,然后我刷新缓冲区。

在90%的情况下这很好用,当格式或

参数需要超过1024字节的格式化输入时执行。

没有简单的方法可以重新运行snprintf()形式的''last''位置。
Here is my situation: I have a char buf[1024]; that is used as a buffer
for a log output. Normally, I do:

rc = snprintf( buf, sizeof(buf), some_format, some_args );

This makes the formatting my output and then I flush the buffer.
In 90% of cases this works well, exept the cases when the format or the
arguments require more then 1024 bytes of formatted input.
There is no easy way to re-run snprintf() form ''last'' position.



通常的解决方案是分配一个更大的缓冲区并重试,

而不是尝试从第一次尝试的地方重新开始/>
没有了,正如你所说没有得到很好的支持。


snprintf函数返回你需要的缓冲区大小

(虽然你需要加1来为终止null腾出空间。

-

" ...几乎让你想知道为什么海森堡不包括postinc / dec运营商

的不确定性原则。这当然使上述内容相当于

Schrodinger的指针......"

--Anthony McDonald

The usual solution is allocate a bigger buffer and try again,
instead of trying to restart from the point where the first try
left off, which as you say is not well supported.

The snprintf function returns the size of the buffer you need
(although you need to add 1 to make room for a terminating null).
--
"...Almost makes you wonder why Heisenberg didn''t include postinc/dec operators
in the uncertainty principle. Which of course makes the above equivalent to
Schrodinger''s pointer..."
--Anthony McDonald




dimka写道:

dimka wrote:

你好


这是我的情况:我有char buf [1024];用作缓冲区
Hello

Here is my situation: I have a char buf[1024]; that is used as a buffer



内存现在大约卖出

memory is selling nowdays for about


这篇关于寻找有状态的snprintf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆