QB_RB_CHUNK_PEEK(3)

πŸ’– QB_RB_CHUNK_PEEK πŸ’–

okay bestie, sit down, hydrate, and let me tell you about this little icon from the libqb Programmer's Manual. it's qb_rb_chunk_peek(3) and it is lowkey the "look but don't touch" girl of ringbuffers. πŸ‘€βœ¨


✨ NAME ✨

qb_rb_chunk_peek β€” Read (without reclaiming) the last chunk.

like… you get to see the chunk. you do not get to keep it yet. it's giving window shopping at the mall. πŸ›οΈ


✨ SYNOPSIS ✨

#include <qb/qbrb.h>

ssize_t qb_rb_chunk_peek(
    qb_ringbuffer_t   *rb,          /* ringbuffer instance */
    /*
     * (out) a pointer to the next chunk to read (not copied).
     */
    void             **data_out,
    int32_t            ms_timeout   /* (in) time to wait for new data.*/
);

no cap, that's the whole vibe. one function, three args, zero drama. 🫢


✨ PARAMS ✨

  • rb β€” ringbuffer instance. your main character, the ringbuffer herself. πŸ’…
  • data_out β€” (out) a pointer to the next chunk to read (not copied). it's an out param, so she's handing you a pointer back, not a copy. ngl that's the whole point.
  • ms_timeout β€” (in) time to wait for new data. in milliseconds. she'll wait. she's patient. but only for that long. ⏳

✨ DESCRIPTION ✨

so this function is a way of accessing the next chunk without a memcpy(). you literally read the chunk data in place. no copying, no extra allocation, no nonsense. it's efficient and honestly kind of iconic. πŸ”₯

think of it like this: instead of someone photocopying the homework and handing you the photocopy, they just point at the homework and go "it's right there bestie." πŸŽ€


✨ RETURN VALUE ✨

the size of the chunk (0 if buffer empty).

that's it. that's the return. and yes, 0 means empty β€” so if you get a 0 back, don't panic, she's just not talking to you right now. 😭


✨ NOTE ✨

⚠️ okay this part matters, do not skim: this function will not "pop" the chunk. you will need to call qb_rb_chunk_reclaim(). 🚨

like, peeking is peeking. the chunk is still sitting there in the buffer being all "hello yes I am still here." if you want it gone, that's a whole different function, bestie. don't forget the reclaim or you'll be confused later. πŸ’€


✨ SEE ALSO ✨

the whole girl gang, fr fr:


Copyright (C) 2010-2020 Red Hat, Inc.


and that's the whole page, bestie!! 🌈 this was libqb, dated 2025-09-16, page QB_RB_CHUNK_PEEK(3) β€” go forth and peek responsibly, and don't forget to qb_rb_chunk_reclaim() afterwards, i am literally begging you. πŸ«ΆπŸ’–βœ¨

πŸ“¦ where this page comes from