docs/src/features.md

Tue, 27 Jun 2023 18:24:28 +0200

author
Mike Becker <universe@uap-core.de>
date
Tue, 27 Jun 2023 18:24:28 +0200
changeset 723
c33e0ac069dd
parent 722
adc3c48dd3af
child 724
5e7b1951dc80
permissions
-rw-r--r--

add web documentation for strings

     1 ---
     2 title: UCX Features
     3 ---
     5 <div id="modules">
     7 ------------------------ -------------------------  -------------------  ---------------------------------
     8 [Allocator](#allocator)  [String](#string)          [Buffer](#buffer)    [Memory&nbsp;Pool](#memory-pool)
     9 [Iterator](#iterator)    [Collection](#collection)  [List](#list)        [Map](#map)
    10 [Utilities](#utilities)
    11 ------------------------ -------------------------  -------------------  ---------------------------------
    13 </div>
    15 ## Allocator
    17 *Header file:* [allocator.h](api/allocator_8h.html)  
    19 The UCX allocator provides an interface for implementing an own memory allocation mechanism.
    20 Various function in UCX provide an additional alternative signature that takes an allocator as
    21 argument. A default allocator implementation using the stdlib memory management functions is
    22 available via the global symbol `cxDefaultAllocator`.
    24 If you want to define your own allocator, you need to initialize the `CxAllocator` structure
    25 with a pointer to an allocator class (containing function pointers for the memory management
    26 functions) and an optional pointer to an arbitrary memory region that can be used to store
    27 state information for the allocator. An example is shown below:
    29 ```c
    30 struct my_allocator_state {
    31     size_t total;
    32     size_t avail;
    33     char[] mem;
    34 };
    36 static cx_allocator_class my_allocator_class = {
    37         my_malloc_impl,
    38         my_realloc_impl,   // all these functions are somewhere defined
    39         my_calloc_impl,
    40         my_free_impl
    41 };
    43 CxAllocator create_my_allocator(size_t n) {
    44     CxAllocator alloc;
    45     alloc.cl = &my_allocator_class;
    46     alloc.data = calloc(1, sizeof(struct my_allocator_state) + n);
    47     return alloc;
    48 }
    50 void free_my_allocator(CxAllocator *alloc) {
    51     free(alloc.data);
    52     free(alloc);
    53 }
    54 ```
    56 ## String
    58 *Header file:* [string.h](api/string_8h.html)
    60 UCX strings come in two variants: immutable (`cxstring`) and mutable (`cxmutstr`).
    61 The functions of UCX are designed to work with immutable strings by default but in situations where it is necessary,
    62 the API also provides alternative functions that work directly with mutable strings.
    63 Functions that change a string in-place are, of course, only accepting mutable strings.
    65 When you are using UCX functions, or defining your own functions, you are sometimes facing the "problem",
    66 that the function only accepts arguments of type `cxstring` but you only have a `cxmutstr` at hand.
    67 In this case you _should not_ introduce a wrapper function that accepts the `cxmutstr`,
    68 but instead you should use the `cx_strcast()` function to cast the argument to the correct type.
    70 In general, UCX strings are **not** necessarily zero-terminated. If a function guarantees to return zero-terminated
    71 string, it is explicitly mentioned in the documentation of the respective function.
    72 As a rule of thumb, you _should not_ pass the strings of a UCX string structure to another API without explicitly
    73 ensuring that the string is zero-terminated.
    75 ## Buffer
    77 *Header file:* [buffer.h](api/buffer_8h.html)  
    79 ## Memory Pool
    81 *Header file:* [mempool.h](api/mempool_8h.html)  
    83 ### Basic Memory Pool
    85 *Header file:* [basic_mempool.h](api/basic__mempool_8h.html)
    87 ## Iterator
    89 *Header file:* [iterator.h](api/iterator_8h.html)
    91 ## Collection
    93 *Header file:* [collection.h](api/collection_8h.html)
    95 ## List
    97 *Header file:* [list.h](api/list_8h.html)
    99 ### Linked List
   101 *Header file:* [linked_list.h](api/linked__list_8h.html)
   103 ### Array List
   105 *Header file:* [array_list.h](api/array__list_8h.html)
   107 ## Map
   109 *Header file:* [map.h](api/map_8h.html)
   111 ### Hash Map
   113 *Header file:* [hash_map.h](api/hash__map_8h.html)
   115 ## Utilities
   117 *Header file:* [utils.h](api/utils_8h.html)
   119 ### Printf Functions
   121 *Header file:* [printf.h](api/printf_8h.html)
   123 ### Compare Functions
   125 *Header file:* [compare.h](api/compare_8h.html)

mercurial