Seems like an great idea for simplifying memory management. The overhead of dealing with non-NULL termination should be minor.
Isn't there an equivalent of TSHttpBodyGet(TSMBuffer bufp, TSMLoc obj, int *length); Manish On Thu, Dec 2, 2010 at 4:47 PM, Leif Hedstrom <zw...@apache.org> wrote: > 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); > > >