chadaustin / sajson

Lightweight, extremely high-performance JSON parser for C++11
MIT License
565 stars 41 forks source link

Confusing size description of passed buffer #51

Open lundmark opened 3 years ago

lundmark commented 3 years ago

So we've had some problems with this: https://github.com/chadaustin/sajson/blob/eeaa7ee736ec2f826c7a30c0e340e5331d8efc57/include/sajson.h#L1115

It says "size_in_words" which is a very unusual way to describe the size of a buffer. I'd say it's very not standard. Would it be possible to update this?

chadaustin commented 3 years ago

Hi @lundmark. Agreed it's a bit unusual to use sizeof(size_t) as the allocation granularity for the AST, but that's how the AST is stored. If you have a size in bytes, you can just pass size_in_bytes / sizeof(size_t).

Would a doc comment help?

lundmark commented 3 years ago

Hi,

I think that it should accept a char *buffer and a size_t size_in_bytes instead.

I've never before seen an allocation api accept a size_t * and a size that is array_length as parameter (which would have been a less confusing name). Buffers are best described as memory chunks + number of bytes, which is different from arrays + length.