gwan dynamic buffer, how often to use and when should you not use it?

132 views Asked by At

I have seen the xbuf from gwan. Not sure when it is not a good use for it. Can it be used for integers or float? When is it not recommended to be used? I am very much inclined to use it as often as possible.

1

There are 1 answers

0
Gil On BEST ANSWER

As an application server, G-WAN is expected to generate dynamic contents.

In this case, the server is building a reply served to clients.

Part of these dynamic contents are binary (like pictures) and this is why G-WAN offers a native ultra-fast in-memory GIF, charts, and frame-buffer API. More complex images can be generated with general-purpose libraries like Cairo (used by Internet browsers).

But most dynamic contents are text (like HTML pages, JSON payloads, etc.).

And this is the purpose of the G-WAN xbuffer API which works as an extended snprintf() - supporting strings, integers, floats, base64, hexdump, binary formating (3 => "11") and more.

The loan.c example illustrates very well how relevant, fast and versatile xbuffers are.

when should you not use it?

When sending an empyt reply (HTTP status code 204), or (less likely but still possible) when appending data directly in a previously resized reply buffer. G-WAN examples show how to do that, look at the fractal.c file.