diff options
| author | Tyge Løvset <[email protected]> | 2023-02-07 12:30:39 +0100 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2023-02-07 12:30:39 +0100 |
| commit | ca54204557669fb54f43959594ee92109fcc75b6 (patch) | |
| tree | 9880ad3d7e3dca7e309e0b96f5c88ebbb0552853 /docs | |
| parent | 3cb564e7274b7749531742fa7c50fd928fdbe2d9 (diff) | |
| download | STC-modified-ca54204557669fb54f43959594ee92109fcc75b6.tar.gz STC-modified-ca54204557669fb54f43959594ee92109fcc75b6.zip | |
Added custom allocator per container type.
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/ccommon_api.md | 36 |
1 files changed, 13 insertions, 23 deletions
diff --git a/docs/ccommon_api.md b/docs/ccommon_api.md index 54b0312d..0a361d46 100644 --- a/docs/ccommon_api.md +++ b/docs/ccommon_api.md @@ -261,9 +261,9 @@ int main() { ``` Note that `c_flt_take()` is given as an optional argument, which makes the loop stop when it becomes false (for efficiency). Chaining it after `isPrime()` instead will give same result, but the full input is processed. -### c_make +### c_make, c_new -Make a container from a literal initializer list. Example: +**c_make**: Make a container from a literal initializer list. Example: ```c #define i_val_str // cstr value type #include <stc/cset.h> @@ -277,6 +277,13 @@ int x = 7, y = 8; cmap_int mymap = c_make(cmap_int, { {1, 2}, {3, 4}, {5, 6}, {x, y} }); ``` +**c_new(Type)**: Allocate and init a new object on the heap +```c +struct Pnt { double x, y, z; }; +struct Pnt *pnt = c_new(struct Pnt, {1.2, 3.4, 5.6}); +c_free(pnt); +``` + ### crange **crange** is a number sequence generator type. The **crange_value** type is `long long`. Below *start*, *stop*, and *step* are of type *crange_value*: ```c @@ -342,29 +349,12 @@ bool crawstr_eq(const crawstr* x, const crawstr* y); uint64_t crawstr_hash(const crawstr* x); ``` -### c_NEW, c_ALLOC, c_ALLOC_N - -| Usage | Meaning | -|:----------------------------|:-------------------------------------------| -| `c_NEW (type, value)` | Allocate and init a new object on the heap | -| `c_ALLOC (type)` | `(type *) c_malloc(c_sizeof(type))` | -| `c_ALLOC_N (type, N)` | `(type *) c_malloc((N)*c_sizeof(type))` | - -```c -struct Pnt { double x, y, z; }; -struct Pnt *pnt = c_NEW(struct Pnt, {1.2, 3.4, 5.6}); -c_free(pnt); - -int* array = c_ALLOC_N(int, 100); -c_free(array); -``` - ### c_malloc, c_calloc, c_realloc, c_free: customizable allocators -Memory allocator for the entire library. Macros can be overridden by the user. +Memory allocator wrappers that uses signed sizes. -### c_ARRAYLEN -- **c_ARRAYLEN(array)**: Return number of elements in an array. array must not be a pointer! +### c_arraylen +Return number of elements in an array. array must not be a pointer! ```c int array[] = {1, 2, 3, 4}; -intptr_t n = c_ARRAYLEN(array); +intptr_t n = c_arraylen(array); ``` |
