• simple/crude intrusive ref count for boltar...

    From Chris M. Thomasson@3:633/10 to All on Sat Jun 6 21:02:37 2026
    Fwiw, this might help you. I accidentally posted some my my really old
    code in another thread. This is bare bones. This
    g_utils_ctors/g_utils_dtors are only there for a sanity check:

    __________
    static unsigned long g_utils_ctors = 0;
    static unsigned long g_utils_dtors = 0;


    struct iptr_base {
    mutable long m_iptr_base_count;
    iptr_base() : m_iptr_base_count(0) { ++g_utils_ctors; }
    virtual ~iptr_base() { ++g_utils_dtors; }
    };


    template<typename T>
    struct iptr {
    T* m_ptr;
    iptr(T* ptr = nullptr) : m_ptr(ptr) { if (m_ptr) m_ptr->m_iptr_base_count++; }
    iptr(iptr const& rhs) : m_ptr(rhs.m_ptr) { if (m_ptr) m_ptr->m_iptr_base_count++; }
    ~iptr() { sub_ref(); }

    void sub_ref() {
    if (m_ptr) {
    if (--m_ptr->m_iptr_base_count <= 0) {
    delete m_ptr;
    m_ptr = nullptr;
    }
    }
    }

    void set_ref(iptr const& rhs) {
    if (rhs.m_ptr) {
    rhs.m_ptr->m_iptr_base_count++;
    }

    T* old_ptr = m_ptr;
    m_ptr = rhs.m_ptr;

    if (old_ptr) {
    if (--old_ptr->m_iptr_base_count <= 0) {
    delete old_ptr;
    }
    }
    }

    iptr& operator =(iptr const& rhs)
    {
    set_ref(rhs);
    return *this;
    }

    T* operator ->() { assert(m_ptr); return m_ptr; }
    T const* operator ->() const { assert(m_ptr); return m_ptr; }
    };
    __________


    Bare bones crude simple refcount.

    --- PyGate Linux v1.5.15
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Chris M. Thomasson@3:633/10 to All on Sat Jun 6 22:06:18 2026
    On 6/6/2026 9:02 PM, Chris M. Thomasson wrote:
    Fwiw, this might help you. I accidentally posted some my my really old
    code in another thread. This is bare bones. This g_utils_ctors/ g_utils_dtors are only there for a sanity check:

    __________
    static unsigned long g_utils_ctors = 0;
    static unsigned long g_utils_dtors = 0;
    [...]


    Fwiw, I use it in an experimental game engine I am creating. Here is a
    console dump from a running instance. Notice the
    g_utils_ctors/g_utils_dtors output at the end? Sanity check indeed. :^)



    --- CT_GAMER ENGINE STARTUP ---
    [HARDWARE] Renderer: NVIDIA GeForce MX330/PCIe/SSE2
    [HARDWARE] Version: 4.5.0 NVIDIA 576.83
    ubo_test::ubo_test() [with bones and vfield]
    source_code::source_code()
    source_code::source_code()
    [PROGRAM] Linked successfully from shaders/core/ct_vertex_simple.glsl
    and shaders/core/ct_frag.glsl
    program::program()
    source_code::~source_code()
    source_code::~source_code()
    source_code::source_code()
    source_code::source_code()
    [PROGRAM] Linked successfully from shaders/core/ct_vertex_simple.glsl
    and shaders/core/ct_frag_pbr.glsl
    program::program()
    source_code::~source_code()
    source_code::~source_code()
    source_code::source_code()
    [PROGRAM] Linked successfully from shaders/core/compute/ct_compute.glsl program::program() [compute]
    source_code::~source_code()
    source_code::source_code()
    source_code::source_code()
    [PROGRAM] Linked successfully from shaders/core/ct_vertex_animated.glsl
    and shaders/core/ct_frag_pbr.glsl
    program::program()
    source_code::~source_code()
  • From Chris M. Thomasson@3:633/10 to All on Wed Jun 10 16:13:19 2026
    On 6/6/2026 9:02 PM, Chris M. Thomasson wrote:
    Fwiw, this might help you. I accidentally posted some my my really old
    code in another thread. This is bare bones. This g_utils_ctors/ g_utils_dtors are only there for a sanity check:

    __________
    static unsigned long g_utils_ctors = 0;
    static unsigned long g_utils_dtors = 0;


    struct iptr_base {
    ÿÿÿ mutable long m_iptr_base_count;

    ^^^^^^^^^^

    No pendants have went after this long instead of unsigned long yet? ;^)

    When I first started out in modern opengl, dx12... I wanted to be able
    to see a negative count to help me nail down some things.



    ÿÿÿ iptr_base() : m_iptr_base_count(0) { ++g_utils_ctors; }
    ÿÿÿ virtual ~iptr_base() { ++g_utils_dtors; }
    };


    template<typename T>
    struct iptr {
    ÿÿÿ T* m_ptr;
    ÿÿÿ iptr(T* ptr = nullptr) : m_ptr(ptr) { if (m_ptr) m_ptr-
    m_iptr_base_count++; }
    ÿÿÿ iptr(iptr const& rhs) : m_ptr(rhs.m_ptr) { if (m_ptr) m_ptr-
    m_iptr_base_count++; }
    ÿÿÿ ~iptr() { sub_ref(); }

    ÿÿÿ void sub_ref() {
    ÿÿÿÿÿÿÿ if (m_ptr) {
    ÿÿÿÿÿÿÿÿÿÿÿ if (--m_ptr->m_iptr_base_count <= 0) {
    ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ delete m_ptr;
    ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ m_ptr = nullptr;
    ÿÿÿÿÿÿÿÿÿÿÿ }
    ÿÿÿÿÿÿÿ }
    ÿÿÿ }

    ÿÿÿ void set_ref(iptr const& rhs) {
    ÿÿÿÿÿÿÿ if (rhs.m_ptr) {
    ÿÿÿÿÿÿÿÿÿÿÿ rhs.m_ptr->m_iptr_base_count++;
    ÿÿÿÿÿÿÿ }

    ÿÿÿÿÿÿÿ T* old_ptr = m_ptr;
    ÿÿÿÿÿÿÿ m_ptr = rhs.m_ptr;

    ÿÿÿÿÿÿÿ if (old_ptr) {
    ÿÿÿÿÿÿÿÿÿÿÿ if (--old_ptr->m_iptr_base_count <= 0) {
    ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ delete old_ptr;
    ÿÿÿÿÿÿÿÿÿÿÿ }
    ÿÿÿÿÿÿÿ }
    ÿÿÿ }

    ÿÿÿ iptr& operator =(iptr const& rhs)
    ÿÿÿ {
    ÿÿÿÿÿÿÿ set_ref(rhs);
    ÿÿÿÿÿÿÿ return *this;
    ÿÿÿ }

    ÿÿÿ T* operator ->() { assert(m_ptr); return m_ptr; }
    ÿÿÿ T const* operator ->() const { assert(m_ptr); return m_ptr; }
    };
    __________


    Bare bones crude simple refcount.


    --- PyGate Linux v1.5.15
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Scott Lurndal@3:633/10 to All on Thu Jun 11 13:49:30 2026
    "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> writes:
    On 6/6/2026 9:02 PM, Chris M. Thomasson wrote:

    <snip>

    struct iptr_base {
    ÿÿÿ mutable long m_iptr_base_count;

    ^^^^^^^^^^

    No pendants have went after this long instead of unsigned long yet? ;^)

    The word is 'pedant'.

    :-)

    --- PyGate Linux v1.5.16
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)