|
|
Log in / Subscribe / Register

A new API for mounting filesystems

A new API for mounting filesystems

Posted Apr 3, 2017 17:33 UTC (Mon) by Homer512 (subscriber, #85295)
In reply to: A new API for mounting filesystems by Cyberax
Parent article: A new API for mounting filesystems

>> On the other hand I see a (in my optinion) significant downside of your encoding. With known lengths of the values it is very easy to calculate the required buffer size with zero terminated strings. In your case calculating the buffer size in advance is complicated.
> I don't follow. In a case of \0-terminated array of dynamically-sized strings calculating the total length would require traversal of the whole array with parsing along the way.

I think the point is that with \0-terminated strings, you can precalculate the buffer size by summing strlen() of the parts. With a prefixed string, you have to add ceil(log10(strlen())) + 1 or something like that to account for the length.
The simplest workaround in plain old C is to use snprintf(NULL, 0, format, …) and use the return value to allocate the actual buffer.


to post comments

A new API for mounting filesystems

Posted Apr 3, 2017 17:34 UTC (Mon) by Cyberax (✭ supporter ✭, #52523) [Link] (2 responses)

With my scheme there are no \0 symbols in the mix. So just get strlen() of the whole thing.

A new API for mounting filesystems

Posted Apr 3, 2017 20:58 UTC (Mon) by khim (subscriber, #9252) [Link] (1 responses)

It's impossible to call strlen till you allocate butter and put all the data into it. And calculating size of buffer is not trivial

A new API for mounting filesystems

Posted Apr 3, 2017 21:02 UTC (Mon) by Cyberax (✭ supporter ✭, #52523) [Link]

And how is that different from a bag of \0-terminated key-value pairs?


Copyright © 2026, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds