Skip to content

Commit a8b0ab8

Browse files
committed
update README.md
1 parent 73188da commit a8b0ab8

2 files changed

Lines changed: 29 additions & 9 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ lib:
5151
@echo "//! LEAVE AN EMPTY LINE HERE, REQUIRE BY GCC/G++" >> JsonUtils.h
5252
@echo "" >> JsonUtils.h
5353

54-
@cat ./src/Json.natvis >> Json.natvis
54+
@cat ./src/Json.natvis >> Json.natvis
5555

5656
@$(CC) -o json_build_test.exe json_build_test.c && rm json_build_test.exe \
5757
&& echo "Make single header library success." \

README.md

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Simple JSON parser written in C99
1212
- [FAQs](#faqs)
1313

1414

15-
## Features
15+
## Features (Design Goals)
1616
- Simple, small and easy to use, integration.
1717
- Writing in C99: simple, small, portability.
1818
- Robust error handling, no pointer-as-object.
@@ -25,12 +25,28 @@ Simple JSON parser written in C99
2525

2626
## Limits
2727
- No scientific number
28-
- Not use state machine for parsing
28+
- Do not use state machine for parsing
2929
- Not the best, the fastest json parser
3030
- Parsing require a preallocated large buffer (about kilobytes, based on file size, cannot detect buffer size requirement), buffer not an allocator (I dont often store the json value as persitent, just temp for parsing levels, game data)
31-
- Use longjmp to handling error, jump from error point to parse function call, which is have 2 disadvantages:
32-
- longjmp may works different over platforms
33-
- longjmp depends on stdlib, not work on freestanding platforms
31+
- Use `longjmp` to handling error, jump from error point to parse function call, which is have disadvantages:
32+
- `longjmp` may works different over platforms
33+
- `longjmp` depends on stdlib, not work on freestanding platforms
34+
- `longjmp` make call stack unpredictable, and must be unwind the call stack (which are overhead, and crash prone)
35+
36+
37+
## API design flaws
38+
After sometimes use this, I found that API have flaws of its own:
39+
- Too verbose, not just for good reasons
40+
- Too many params for function call, which can be better to combine as a struct
41+
- Allocator buffer, but cannot custom allocations
42+
- It's claimed cache-friendly, but the layout of data in memory after parsing usually un-ordered, un-lineared in hierarchy point-of-view (address of items of array come before the array itself)
43+
```plain
44+
[Items of a array] -> [Maybe items of other array] -> [Maybe other array JSON] -> [Array JSON] -> [... and some unpredictable value, and string/object come to the party]
45+
```
46+
- Continue to the above, reorder should help? Not exactly, how to reorder, how much reorder overhead, that too much works for simple parsing simple data format like JSON.
47+
- No big projects usage.
48+
- Parsing still too complex
49+
-> Decisioning to exploring some best practices from other parser, [MetaDesk](https://github.com/ryanfleury/metadesk) is good example. Linked list in one single arena of memory is good enough.
3450

3551

3652
## Examples
@@ -169,10 +185,14 @@ make lib
169185

170186
## FAQs
171187
### Why another json parser?
172-
When I first read an article about common mistake of c libraries are do much dynamic allocations and have no custom allocators. So I create this projects to learn to make good library in C.
188+
When I first read an article about common mistake of c libraries are do much dynamic allocations and have no custom allocators. So I create this project to learn to make good library in C.
189+
190+
### Have no update after long time?
191+
Like I said above, I started this project mainly for learning purpose, how to design a good API for C. Have no purpose for compete with battle-tested library. When I have any ideas for better API design, I comeback and do some hacks. If you have ideas, just make a issue in this repo.
173192

174193
### You said custom allocators, but I donot find one?
175-
In the first version there is a custom allocator interface. But after the long run, I found the memory of Json was throw away at one, so dynamic allocators are expensive for that. Now we just given a temporary buffer to parser, and there is a linear allocator in internal. So no dynamic allocations.
194+
In the first version there is a custom allocator interface. But after the long run, I found the memory of Json was throw away at one, so dynamic allocators are expensive for that. Now we just given a temporary buffer to parser, and there is a linear allocator in internal. So no dynamic allocations.
195+
_Note_: Next version will combine both, support passing allocator around, but have API to create one-time allocator from buffer. (Better API)
176196

177197
### Where stringify/serialize functions?
178198
It easy to write an JsonStringify version, but the real problem in C is not that simple. You need to create Json value, create Json may need memory, so we need to care about memory allocation. That headache! Fortunately, C is static type language, so we can easily convert out data structure/object to json easily base on its types. See example below:
@@ -194,7 +214,7 @@ const char* JsonifyEntity(Entity entity)
194214
```
195215
196216
### I don't like CamelCase!!!
197-
Just rename, update, change what you not like with your code editor.
217+
Just rename, update, change what you do not like with your code editor.
198218
199219
### What about licenses
200220
This repo use UNLICENSE but the source code you generate from `make` can be your license of choice.

0 commit comments

Comments
 (0)