API: string formatting / memory management

Johannes Pfau via Digitalmars-d digitalmars-d at puremagic.com
Sat Jul 12 01:46:19 PDT 2014


Am Fri, 11 Jul 2014 21:14:36 +0000
schrieb "Robert burner Schadek" <rburners at gmail.com>:

> On Friday, 11 July 2014 at 15:20:51 UTC, Johannes Pfau wrote:
> > An logger can still receive the complete string by appending 
> > the chunks
> > received in put but we might need some 'finish' function to 
> > signal the
> > end of the message. I guess not all loggers can fit into this
> > interface, so we should try to make this optional. But simple 
> > loggers
> > (file, console) which write the header first and the message 
> > last could
> > work without any dynamic memory allocation. (formattedWrite 
> > probably
> > uses an fixed-size buffer on the stack, but that's fine)
> 
> The api for none printf like logging has changed into something
> like
> write. So put properly needs to become a template. Any I'm not
> sure if
> there is a nice way around the template/inheritance problematic.
> Other
> than options one and two.

Last time we discussed this I also thought we'd need to make put a
template. But we overlooked the obvious solution:

Type->string formatting stays part of the 'frontend' functions. We only
pass strings to the backend. But instead of insisting that message is
one string, we allow to pass the msg as many strings. This means that
formatting can go in a fixed size stack buffer and still support
arbitrary length strings.

Here's a pull request to implement this idea:
https://github.com/burner/logger/pull/9


More information about the Digitalmars-d mailing list