summaryrefslogtreecommitdiffhomepage
path: root/docs
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2021-09-24 07:08:56 +0200
committerTyge Løvset <[email protected]>2021-09-24 07:08:56 +0200
commit23f5994392dc3a3ad4a1b680f4453cba21e632eb (patch)
tree780da8dab0df64db344558d3f0a698df10826d18 /docs
parent9f2cf3080ee03346cfe0e13b34505b1fd017fbe6 (diff)
downloadSTC-modified-23f5994392dc3a3ad4a1b680f4453cba21e632eb.tar.gz
STC-modified-23f5994392dc3a3ad4a1b680f4453cba21e632eb.zip
Reworked csptr docs. Made static members to inline (ccommon.h).
Diffstat (limited to 'docs')
-rw-r--r--docs/csptr_api.md15
1 files changed, 11 insertions, 4 deletions
diff --git a/docs/csptr_api.md b/docs/csptr_api.md
index d1157162..7b44e4c1 100644
--- a/docs/csptr_api.md
+++ b/docs/csptr_api.md
@@ -24,13 +24,20 @@ See the c++ classes [std::shared_ptr](https://en.cppreference.com/w/cpp/memory/s
#define i_valdel // destroy value func - defaults to empty destruct
#include <stc/csptr.h>
```
-`X` should be replaced by the value of `i_tag` in all of the following documentation. When declaring a container with shared pointers, define the `i_val_csptr` with the csptr's `i_tag`. See example below.
+`X` should be replaced by the value of `i_tag` in all of the following documentation.
-## Methods
+The *csptr_X_compare()*, *csptr_X_del()* methods are defined based on the `i_cmp` and `i_valdel`
+macros specified. Use *csptr_X_clone(p)* when sharing ownership of the pointed-to object.
+
+When declaring a container with shared pointers, define the `i_val_csptr` with the csptr's `i_tag`.
+See example.
-The *csptr_X_compare()*, *csptr_X_del()* methods are defined based on the `i_cmp` and `i_valdel` macros specified.
+Also for containers, make sure to pass the result of *csptr_X_make()* to *insert*, *push_back*,
+or *push*, and not an *emplace* function. The *csptr_X_make()* method creates a **csptr** with
+use-count 1, and *emplace* will ***clone*** it and increase the count, causing a memory leak. Use
+*emplace* functions when sharing **csptr**s between containers or other existing shared pointers.
-Use *csptr_X_clone(p)* when sharing ownership of the pointed-to object. For shared pointers stored in containers, define `i_val_csptr` to the shared pointers tag instead of a `i_val` macro. See example below.
+## Methods
```c
csptr_X csptr_X_init(); // empty constructor
csptr_X csptr_X_make(i_val val); // make_shared constructor, like std::make_shared()