Hi,
here's an idea, that could optimize memory allocation pressure
significantly (I think) when writing plugins. Here's the deal; A few
plugin APIs will make copies of the strings from the internal marshal
buffers, before returning them, with the only purpose of making them
NULL terminated. The odd thing, to me at least, is that all these APIs
already take an argument (an int*), which gets set with the length of
the string.
I think it'd make much more sense to consistently make all APIs that
deals with strings like this not be NULL terminated. This would require
no API changes, just that the "semantics" would change. And I think the
requirement to 'release' strings could then go away entirely (since they
are just const char* pointers into the marshal buffers).
Below are a few APIs that would change their "behavior", in that they no
longer would gurantee NULL terminated strings (which is something most
APIs don't anyways).
Thoughts on this?
-- leif
const char * TSUrlSchemeGet(TSMBuffer bufp, TSMLoc obj, int *length);
const char *TSUrlUserGet(TSMBuffer bufp, TSMLoc obj, int *length);
const char *TSUrlPasswordGet(TSMBuffer bufp, TSMLoc obj, int *length);
const char *TSUrlHostGet(TSMBuffer bufp, TSMLoc obj, int *length);
const char *TSUrlPathGet(TSMBuffer bufp, TSMLoc obj, int *length);
const char *TSUrlHttpParamsGet(TSMBuffer bufp, TSMLoc obj, int *length);
const char *TSUrlHttpQueryGet(TSMBuffer bufp, TSMLoc obj, int *length);
const char *TSUrlHttpFragmentGet(TSMBuffer bufp, TSMLoc obj, int *length);
const char *TSMimeHdrFieldNameGet(TSMBuffer bufp, TSMLoc hdr, TSMLoc
field, int *length);
const char *TSHttpHdrMethodGet(TSMBuffer bufp, TSMLoc obj, int *length);
const char *TSHttpHdrReasonGet(TSMBuffer bufp, TSMLoc obj, int *length);
TSReturnCode TSMimeHdrFieldValueStringGet(TSMBuffer bufp, TSMLoc hdr,
TSMLoc field, int idx, const char **value_ptr, int *value_len_ptr);