Пример #1
0
__tb_no_sanitize_address__ tb_size_t tb_pool_data_size(tb_cpointer_t data)
{
    // check
    tb_check_return_val(data, 0);

    // done
    tb_size_t               size = 0;
    tb_pool_data_head_t*    data_head = tb_null;
    do
    {
        // tbox must be running normally
        tb_check_break(tb_state() == TB_STATE_OK);

        // get global allocator
        tb_allocator_ref_t allocator = tb_allocator();
        tb_check_break(allocator);

        // have this data address?
        tb_check_break(tb_allocator_have(allocator, data));

        // the data head
        data_head = &(((tb_pool_data_head_t*)data)[-1]);
        tb_check_break(data_head->debug.magic == TB_POOL_DATA_MAGIC);

        // ok
        size = data_head->size;

    } while (0);

    // ok?
    return size;
}
Пример #2
0
static tb_bool_t tb_default_allocator_have(tb_allocator_ref_t self, tb_cpointer_t data)
{
    // check
    tb_default_allocator_ref_t allocator = (tb_default_allocator_ref_t)self;
    tb_assert_and_check_return_val(allocator && allocator->large_allocator, tb_false);

    // have it?
    return tb_allocator_have(allocator->large_allocator, data);
}