Skip to content

Commit a74af43

Browse files
committed
Improve comment for 'pool_new' function
No need to use a 'struct', we can just use (or even typedef) a 'union'.
1 parent 4916ea7 commit a74af43

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/libpool.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,24 +52,22 @@ struct Pool {
5252
/*
5353
* We use an exteran allocation function (by default `malloc', but can be
5454
* overwritten by user) to allocate a `Pool' structure, and the array of
55-
* chunks. You can think of a chunk as the following structure:
55+
* chunks. You can think of a chunk as the following union:
5656
*
57-
* struct Chunk {
58-
* union {
59-
* struct Chunk* next_free;
60-
* char user_data[CHUNK_SZ];
61-
* } val;
57+
* union Chunk {
58+
* union Chunk* next_free;
59+
* char user_data[CHUNK_SZ];
6260
* };
6361
*
64-
* In this hypothetical struct, the data in a non-free chunk will be overwritten
62+
* In this hypothetical union, the data in a non-free chunk will be overwritten
6563
* by the user, in the `user_data' array, where `CHUNK_SZ' was specified by the
6664
* caller of `pool_new':
6765
*
6866
* +-------------+ +-------------+ +-------------+ +-------------+
6967
* | <user-data> | | <user-data> | | <user-data> | | <user-data> |
7068
* +-------------+ +-------------+ +-------------+ +-------------+
7169
*
72-
* However, if the chunk is free, the structure uses the `val.next_free' pointer
70+
* However, if the chunk is free, the union uses the `Chunk.next_free' pointer
7371
* to build a linked list of available chunks, shown below. This linked list is
7472
* built once, inside this `pool_new' function, and it is the only time when the
7573
* library has to iterate the `Chunk' array. The linked list will be modified by

0 commit comments

Comments
 (0)