// File: /workspace/github_cpp_makefile_star2_O2/f18m[P]boost-intrusive-pool/tests/tutorial.cpp
// Function: showcase_boost_intrusive_pool()
void showcase_boost_intrusive_pool()
{
    print_header();

    {
        std::cout << "  Now allocating a new memorypool::boost_intrusive_pool<>. A large malloc will happen."
                  << std::endl;

        memorypool::boost_intrusive_pool<DummyClass> pool(4, 1);
        // you will see a memory malloc traced when running this line

        std::cout << "  Boost Intrusive Pool for DummyClass has size: " << sizeof(pool) << std::endl;

        {
            std::cout << "  Now allocating dummy class of size: " << sizeof(DummyClass)
                      << " from the memory pool. This time no mallocs will happen!" << std::endl;
            boost::intrusive_ptr<DummyClass> hdummy = pool.allocate();

            // of course copying pointers around does not trigger any memory allocation:
            boost::intrusive_ptr<DummyClass> hdummy2 = hdummy;
            std::cout << "  Value from allocated dummy class constructed via default ctor: " << hdummy2->dummy()
                      << std::endl;

            observe_pool(pool);

            std::cout << "  Going to release the references to the boost::intrusive_ptr<> created so far. This time no "
                         "free() will happen!"
                      << std::endl;

        } // this time no memory free() will happen!

        observe_pool(pool);

        std::cout << "  Going to release the whole memory pool. You will see a bunch of dtor and memory free happen!"
                  << std::endl;
    } // you will see a memory free traced when running this line

    print_header();

    // now showcase a memory pool of objects having the following class hierarchy:
    //   boost_intrusive_pool_item
    //   \--- DummyClass
    //        \--- DummyDerivedClass

    {
        std::cout << "  Now allocating a new memorypool::boost_intrusive_pool<>. A large malloc will happen."
                  << std::endl;
        memorypool::boost_intrusive_pool<DummyDerivedClass> pool(4, 1);

        {
            std::cout << "  Now allocating derived dummy class of size: " << sizeof(DummyDerivedClass)
                      << " from the memory pool. This time no mallocs will happen but the ctor will get called again!"
                      << std::endl;

            size_t initializer_value = 3;

            auto custom_init_fn
                = [&initializer_value](DummyDerivedClass& object) { object.yet_another_init_fun(initializer_value); };

            // just for fun this time we allocate the object using non-default constructor:
            boost::intrusive_ptr<DummyDerivedClass> hdummy = pool.allocate_through_function(custom_init_fn);

            std::cout << "  Value from allocated dummy class constructed via NON default ctor: " << hdummy->dummy()
                      << std::endl;

            observe_pool(pool);

            std::cout << "  Going to release the references to the boost::intrusive_ptr<> created so far. This time no "
                         "free() will happen, just a dtor call!"
                      << std::endl;

        } // this time no memory free() will happen!

        observe_pool(pool);

        std::cout << "  Going to release the whole memory pool. You will see a bunch of dtor and memory free happen!"
                  << std::endl;
    } // you will see a memory free traced when running this line

    std::cout << "Note that the overhead of memory pool support is sizeof(memorypool::boost_intrusive_pool_item)="
              << sizeof(memorypool::boost_intrusive_pool_item) << "bytes" << std::endl;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
subq $0x88, %rsp
callq 0x23ed
movq 0x78b2(%rip), %rdi      # 0x9fd0
leaq 0x2b37(%rip), %rsi      # 0x525c
callq 0x20f0
movq %rax, %rdi
callq 0x2080
xorps %xmm0, %xmm0
leaq -0x70(%rbp), %r9
movaps %xmm0, (%r9)
movaps %xmm0, 0x10(%r9)
leaq -0x20(%rbp), %rdi
pushq $0x4
popq %rsi
pushq $0x1
popq %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x2c14
leaq -0x70(%rbp), %rdi
callq 0x2e90
movq 0x786a(%rip), %rdi      # 0x9fd0
leaq 0x2b46(%rip), %rsi      # 0x52b3
callq 0x20f0
pushq $0x10
popq %rsi
movq %rax, %rdi
callq 0x20a0
movq %rax, %rdi
callq 0x2080
movq 0x7844(%rip), %rdi      # 0x9fd0
leaq 0x293b(%rip), %rsi      # 0x50ce
callq 0x20f0
movl $0x420, %esi            # imm = 0x420
movq %rax, %rdi
callq 0x20a0
leaq 0x2b38(%rip), %rsi      # 0x52e4
movq %rax, %rdi
callq 0x20f0
movq %rax, %rdi
callq 0x2080
leaq -0x28(%rbp), %rdi
leaq -0x20(%rbp), %rsi
callq 0x2ca8
leaq -0x10(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x2bb2
movq 0x77f3(%rip), %rdi      # 0x9fd0
leaq 0x2b39(%rip), %rsi      # 0x531d
callq 0x20f0
movq %rax, %rbx
leaq -0x10(%rbp), %rdi
callq 0x2bcc
movq (%rax), %rcx
movq %rax, %rdi
callq *0x18(%rcx)
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2110
movq %rax, %rdi
callq 0x2080
leaq -0x20(%rbp), %rdi
callq 0x2d2d
movq 0x77af(%rip), %rdi      # 0x9fd0
leaq 0x2b37(%rip), %rsi      # 0x535f
callq 0x20f0
movq %rax, %rdi
callq 0x2080
leaq -0x10(%rbp), %rdi
callq 0x2bf8
leaq -0x28(%rbp), %rbx
movq %rbx, %rdi
callq 0x2bf8
leaq -0x20(%rbp), %rdi
callq 0x2d2d
movq 0x7776(%rip), %rdi      # 0x9fd0
leaq 0x2b6f(%rip), %rsi      # 0x53d0
callq 0x20f0
movq %rax, %rdi
callq 0x2080
leaq -0x20(%rbp), %rdi
callq 0x2db6
callq 0x23ed
movq 0x774d(%rip), %rdi      # 0x9fd0
leaq 0x29d2(%rip), %rsi      # 0x525c
callq 0x20f0
movq %rax, %rdi
callq 0x2080
xorps %xmm0, %xmm0
leaq -0x50(%rbp), %r9
movaps %xmm0, (%r9)
movaps %xmm0, 0x10(%r9)
leaq -0x20(%rbp), %rdi
pushq $0x4
popq %rsi
pushq $0x1
popq %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x2dfc
leaq -0x50(%rbp), %rdi
callq 0x2e90
movq 0x7705(%rip), %rdi      # 0x9fd0
leaq 0x2b5d(%rip), %rsi      # 0x542f
callq 0x20f0
movl $0x4420, %esi           # imm = 0x4420
movq %rax, %rdi
callq 0x20a0
leaq 0x2b73(%rip), %rsi      # 0x545e
movq %rax, %rdi
callq 0x20f0
movq %rax, %rdi
callq 0x2080
movq $0x3, -0x28(%rbp)
leaq -0x90(%rbp), %rdx
andq $0x0, 0x8(%rdx)
movq %rbx, (%rdx)
leaq 0x1a5(%rip), %rax       # 0x2abe
movq %rax, 0x18(%rdx)
leaq 0x1b0(%rip), %rax       # 0x2ad4
movq %rax, 0x10(%rdx)
leaq -0x10(%rbp), %rdi
leaq -0x20(%rbp), %rsi
callq 0x2eb0
leaq -0x90(%rbp), %rdi
callq 0x2e90
movq 0x7688(%rip), %rdi      # 0x9fd0
leaq 0x2b6b(%rip), %rsi      # 0x54ba
callq 0x20f0
movq %rax, %rbx
leaq -0x10(%rbp), %rdi
callq 0x2f94
movq (%rax), %rcx
movq %rax, %rdi
callq *0x18(%rcx)
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2110
movq %rax, %rdi
callq 0x2080
leaq -0x20(%rbp), %rdi
callq 0x2fc0
movq 0x7644(%rip), %rdi      # 0x9fd0
leaq 0x2b6d(%rip), %rsi      # 0x5500
callq 0x20f0
movq %rax, %rdi
callq 0x2080
leaq -0x10(%rbp), %rdi
callq 0x304a
leaq -0x20(%rbp), %rdi
callq 0x2fc0
movq 0x7617(%rip), %rdi      # 0x9fd0
leaq 0x2a10(%rip), %rsi      # 0x53d0
callq 0x20f0
movq %rax, %rdi
callq 0x2080
leaq -0x20(%rbp), %rdi
callq 0x3066
movq 0x75f3(%rip), %rdi      # 0x9fd0
leaq 0x2b9f(%rip), %rsi      # 0x5583
callq 0x20f0
pushq $0x20
popq %rsi
movq %rax, %rdi
callq 0x20a0
leaq 0x2be8(%rip), %rsi      # 0x55e3
movq %rax, %rdi
callq 0x20f0
movq %rax, %rdi
callq 0x2080
addq $0x88, %rsp
popq %rbx
popq %rbp
retq
movq %rax, %rbx
leaq -0x90(%rbp), %rdi
callq 0x2e90
jmp 0x2a50
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
jmp 0x2a38
jmp 0x2a72
movq %rax, %rbx
leaq -0x70(%rbp), %rdi
callq 0x2e90
jmp 0x2a7e
movq %rax, %rbx
leaq -0x10(%rbp), %rdi
callq 0x304a
jmp 0x2a50
movq %rax, %rbx
leaq -0x20(%rbp), %rdi
callq 0x3066
jmp 0x2a7e
movq %rax, %rbx
leaq -0x10(%rbp), %rdi
callq 0x2bf8
leaq -0x28(%rbp), %rdi
callq 0x2bf8
jmp 0x2a75
movq %rax, %rbx
leaq -0x20(%rbp), %rdi
callq 0x2db6
movq %rbx, %rdi
callq 0x2190