Described here:
https://github.com/apache/trafficserver/blob/os_pkey_cnf_reload/doc/developer-guide/api/functions/TSHeapBuf.en.rst#tsheapbufdata
,

In PR https://github.com/apache/trafficserver/pull/8790 .

This allows a dynamically allocated buffer, of any reasonable length, to be
returned by a TS API function, like this:

TSHeapBuf hb = TSSomething(x, y, z);

One alternative is an interface like this:

int length;
char *data = TSSomething(x, y, z, &length);

The data is dynamically allocated, and would be freed with TSfree().

Another alternative is:

char *buf = TSalloc(BUF_SIZE);
int actual_size = TSSomething(x, y, z, buf, BUF_SIZE);
if (actual_size > BUF_SIZE) {
  // buf was too small, unchanged.
  TSfree(buf);
  buf = TSalloc(actual_size);
  TSSomething(x, y, z, buf, actual_size);
}

Reply via email to