What are the pros and cons of using uint64_t as a universal memory address instead of void *?

I am new to C programming. I found that it is uint64_tused as a buffer address, not void*libibverbs.

struct ibv_sge{
    uint64_t addr;
    uint32_t length;
    uint32_t lkey;
}

The disadvantage that I can think of is its mobility. On a 32-bit system, this will cause a compilation error, or at least memory loss. So why do this? Are there any advantages?

I also noted that there is another alternative approach, for example uintptr_t. What is the best approach for describing a universal memory address?

+4
source share
2 answers

pros and cons of using uint64_t as a universal memory address

Con:

  • , .

  • , .

C . void *, . void * . , .

void . void ; . C11dr §6.3.2.3 1

; . §6.3.2.3 8


?

C union.

union u_pointer {
  void *obj;
  int (*fun)();
};

, .


0

++ int, void* .

, , 13 000 C. , , :

static int pp_post_recv(struct pingpong_context *ctx, int n)
{
        struct ibv_sge list = {
                .addr   = (uintptr_t) ctx->buf,
                .length = ctx->size,
                .lkey   = ctx->mr->lkey
        };
        struct ibv_recv_wr wr = {
                .wr_id      = PINGPONG_RECV_WRID,
                .sg_list    = &list,
                .num_sge    = 1,
        };
        struct ibv_recv_wr *bad_wr;
        int i;

        for (i = 0; i < n; ++i)
                if (ibv_post_srq_recv(ctx->srq, &wr, &bad_wr))
                        break;

        return i;
}

.addr . , .

0

Source: https://habr.com/ru/post/1682091/


All Articles