60 points · by luu · 13y ago · 32 comments
The positives (like tny) were that the code was very straightforward and easy to use. And one of the negatives were that it wasn't "self describing" (which JSON is to some extent).
Of course the ultimate in binary self describing data is ASN.1 syntax :-) but lets not go there.
As such I doubt "the author read the XDR code", though perhaps you weren't wondering that at all, but rather wanted to mention XDR and ASN.1, in which case you should've really just done that. As it's written, it makes "the author" look like either an ignorant imbecile who doesn't know such basics as XDR or as someone who piggy-backed on XDR without acknowledging it.
A first step to improving this library would be to add a SAX style parser so I could build my own representation.
If you're into C++, take a look at benejson's pull parser. There is a C core but its presently very ugly and only intended for library, not application developers.
Optimizing the usage of malloc and free is no different than optimizing the run time of any algorithm. The only difference is people believe they can just abstract allocation away and rely on somebody else's code to handle it.
My second question is, can you actually avoid relying on somebody else's code when you call malloc? Due to virtual memory being comprised of pages, address randomization, and other things, heap is not a continuous memory space in hardware ready to be used at the moment program runs. So, what is the cost/benefit of "individually called malloc" for each struct, as opposed to pre-allocating some space? I could be totally out of my depth, in which case ignore me ;)
{
"hello": "world"
}
Tny converts this JSON into a (usually, but not always) smaller form that's faster to traverse and encode/decode. Tny's alternative, BSON, is being used by MongoDB [1], so that might be a good place to learn more.After a short review of the add function for handling of complex structs i found a possible bug as they miss to perform a deep copy of objects containing references to other objects. they would only copy the value of the pointers of a struct like that: struct { obj* ptr; } and not the content of ptr.