docs/src/modules-ucx2.md

changeset 717
aa17be68fc66
parent 628
1e2be40f0cb5
child 719
034ec7abb83e
equal deleted inserted replaced
716:bab81cf591a5 717:aa17be68fc66
1 --- 1 ---
2 title: UCX 2.1 Modules 2 title: UCX 2.1 Modules
3 --- 3 ---
4 4
5 UCX 2.1 provided several modules for data structures and algorithms. 5 UCX 2.1 provided several modules for data structures and algorithms.
6 You may choose to use specific modules by inclueding the corresponding header 6 You may choose to use specific modules by including the corresponding header
7 file. 7 file.
8 Please note, that some modules make use of other UCX 2.1 modules. 8 Please note, that some modules make use of other UCX 2.1 modules.
9 For instance, the [Allocator](#allocator) module is used by many other modules 9 For instance, the [Allocator](#allocator) module is used by many other modules
10 to allow flexible memory allocation. 10 to allow flexible memory allocation.
11 By default the header files are placed into an `ucx` directory within your 11 By default, the header files are placed into an `ucx` directory within your
12 systems include directory. In this case you can use a module by including it 12 systems include directory. In this case you can use a module by including it
13 via `#include <ucx/MODULENAME.h>`. 13 via `#include <ucx/MODULENAME.h>`.
14 Required modules are included automatically. 14 Required modules are included automatically.
15 15
16 <div id="modules" align="center"> 16 <div id="modules" align="center">
520 // register destructor function 520 // register destructor function
521 ucx_mempool_set_destr(obj, (ucx_destructor) my_object_destroy); 521 ucx_mempool_set_destr(obj, (ucx_destructor) my_object_destroy);
522 ``` 522 ```
523 Be aware, that your destructor function should not free any memory, that is 523 Be aware, that your destructor function should not free any memory, that is
524 also managed by the pool. 524 also managed by the pool.
525 Otherwise you might be risking a double-free. 525 Otherwise, you might be risking a double-free.
526 More precisely, a destructor function set with `ucx_mempool_set_destr()` MUST 526 More precisely, a destructor function set with `ucx_mempool_set_destr()` MUST
527 NOT call `free()` on the specified pointer whereas a desructor function 527 NOT call `free()` on the specified pointer whereas a destructor function
528 registered with `ucx_mempool_reg_destr()` MAY (and in most cases will) call 528 registered with `ucx_mempool_reg_destr()` MAY (and in most cases will) call
529 `free()`. 529 `free()`.
530 530
531 ## Properties 531 ## Properties
532 532
679 argument type. 679 argument type.
680 E.g. the `sstrchr()` function returns a substring starting at 680 E.g. the `sstrchr()` function returns a substring starting at
681 the first occurrence of the specified character. 681 the first occurrence of the specified character.
682 Since this substring points to the memory of the argument string, it does not 682 Since this substring points to the memory of the argument string, it does not
683 accept `scstr_t` as input argument, because the return type would break the 683 accept `scstr_t` as input argument, because the return type would break the
684 constness. 684 const-ness.
685 685
686 686
687 ### Finding the position of a substring 687 ### Finding the position of a substring
688 688
689 The `sstrstr()` function gives you a new `sstr_t` object starting with the 689 The `sstrstr()` function gives you a new `sstr_t` object starting with the
783 // (all code after UCX_TEST_END is always executed) 783 // (all code after UCX_TEST_END is always executed)
784 } 784 }
785 ``` 785 ```
786 If you want to use the `UCX_TEST_ASSERT()` macro in a function, you are 786 If you want to use the `UCX_TEST_ASSERT()` macro in a function, you are
787 *required* to use a `UCX_TEST_SUBROUTINE`. 787 *required* to use a `UCX_TEST_SUBROUTINE`.
788 Otherwise the testing framework does not know where to jump, when the assertion 788 Otherwise, the testing framework does not know where to jump, when the assertion
789 fails. 789 fails.
790 790
791 After implementing the tests, you can easily build a test suite and execute it: 791 After implementing the tests, you can easily build a test suite and execute it:
792 ```C 792 ```C
793 UcxTestSuite* suite = ucx_test_suite_new(); 793 UcxTestSuite* suite = ucx_test_suite_new();

mercurial