@@ -4,36 +4,40 @@ using namespace nodepp;
44
55void onMain (){
66
7- ptr_t <uint> GC = new uint (10 );
7+ ptr_t <int > GC ( 0UL , 10 ); // SSO optimization and automatic heap
8+ // ptr_t<int> GC = new int(10); // No SSO optimization always heap
9+ // ptr_t<int> GC = type::bind( (int)10 ) // SSO optimization and automatic heap
10+ // ptr_t<int> GC = type::bind( new int(10) ) // NEVER USE ( new ) WITH TYPE::BIND
811
9- console::log (" -- --" );
10- console::log ( " value->" , *GC );
12+ console::log (" -- 0 --" );
1113 console::log ( " addr ->" , GC );
14+ console::log ( " value->" , *GC );
1215 console::log ( " count->" , GC.count () );
1316
14- process::add ([=](){ // <- note = and not & | this is important to correctly share the memory across tasks
15-
16- console::log (" -- --" );
17- console::log ( " value->" , *GC );
17+ process::add ([=](){
18+ console::log (" -- 1 --" );
1819 console::log ( " addr ->" , GC );
20+ console::log ( " value->" , *GC );
1921 console::log ( " count->" , GC.count () );
22+ return -1 ; });
2023
21- return -1 ;
22- });
23-
24- process::await ([&](){ // <- note & instead = | but you are still able to use =
25-
26- console::log (" -- --" );
27- console::log ( " value->" , *GC );
24+ process::await ([&](){
25+ console::log (" -- 2 --" );
2826 console::log ( " addr ->" , GC );
27+ console::log ( " value->" , *GC );
2928 console::log ( " count->" , GC.count () );
29+ return -1 ; });
3030
31- return -1 ;
31+ process::onSIGCLOSE.once ([=](){
32+ console::log (" -- 3 --" );
33+ console::log ( " addr ->" , GC );
34+ console::log ( " value->" , *GC );
35+ console::log ( " count->" , GC.count () );
3236 });
3337
34- console::log (" -- --" );
35- console::log ( " value->" , *GC );
38+ console::log (" -- 4 --" );
3639 console::log ( " addr ->" , GC );
40+ console::log ( " value->" , *GC );
3741 console::log ( " count->" , GC.count () );
3842
3943}
0 commit comments