The size of the elements in the memory pool is fixed, but the number of elements in the memory pool can be expanded by using
le_mem_ForceAlloc. Memory pools work nicely when you are allocating fixed size items, but they are quite wasteful if you are using them as you are to accept a variable length string. Is there an upper and lower bound on the size of the string? If there is and the upper and lower bound are somewhat close together, then I think a memory pool may still make sense.
Is there a requirement that the string data is stored contiguously when you receive it? Obviously that’s the case if you want to use standard string functions on it. If you do need it to be contiguous, then there are two options that I can think of. One is to just use
realloc as you originally mentioned. The other is to create a memory pool of a struct like this:
And then create a linked list of the fragments as they are coming in and then do one
malloc at the end once the entire string has arrived and copy the data from the fragments into the string and remove the fragments. This approach seems like it’s probably going to be more complicated to implement and slow to execute though, so I would go with the