How to create a TF_String type Tensor from C/C++?

In the pre 2.4 versions of TF, I allocated the space for my string tensor with TF_AllocateTensor with size (8 bytes + TF_StringEncodedSize). Then I encoded the actual string with TF_StringEncode directly to the right place in the Tensor (offset 8 bytes). This also worked with an array of strings playing cleverly the offset.
Since 2.4 the two above string functions are not available.

Can somebody give me a small hint how to do it now? What did actually StringEncode do? Shall I do something similar manually or there is another solution?



Btw. I am using Pascal, but through the c API (c_api.h and related ones)

I have just found the same question from last August: Wrap string into tensor in tensorflow C API (v2.4+)
Unfortunately there is no answer there.

I think I finally solved it. The trick is that one cell of a tensor is 24 bytes (size of TF_Tstring structure). When a String type tensor is to be made, a tensor has to be created as TF_String type and allocate a memory of 24 * number of cells. Then in every cell the result (dst) of the TF_StringCopy has to be copied. If the string is less or equal than 22 bytes, it is placed into the 24 bytes cell, if longer than it takes care of the heap allocation and referencing. No need to do more.
Once a Tensor is deleted it frees up the Heap as well if used.

If I misunderstood something, please let me know.

For anyone that might have stumbled upon this via a google search, creating the string tensor will look something like this

const char embedding[] = "The quick brown fox jumps over the lazy dog.";

TF_TString tstring[1];
TF_TString_Copy(&tstring[0], embedding, sizeof(embedding) - 1);
int64_t dims[] = {1,1};
int num_dims = 1;

TF_Tensor* input_tensor = TF_NewTensor(TF_STRING, dims, num_dims, &tstring[0], sizeof(tstring), &Deallocator, nullptr);