al_ref_ustr(3alleg5)
β¨ al_ref_ustr β the Allegro 5 API glow-up β¨
okay bestie, welcome to the <allegro5> corner of the Allegro 5 API (that's the 3alleg5 manual section, if you're keeping track π). this one is short but it's so useful, trust.
π NAME π
al_ref_ustr β Allegro 5 API. that's the whole name. she's concise, she's iconic, she does one thing and she does it well π
πΈ SYNOPSIS πΈ
#include <allegro5/allegro.h>
const ALLEGRO_USTR *al_ref_ustr(ALLEGRO_USTR_INFO *info, const ALLEGRO_USTR *us,
int start_pos, int end_pos)
look at that signature. four args. no cap, she's got range π
π¦ DESCRIPTION π¦
so here's the tea: al_ref_ustr makes you a read-only string that just references the storage of another ALLEGRO_USTR(3alleg5) string. like, it's not copying anything, it's pointing at your friend's closet and saying "yeah that's mine now" π«Ά
the info about the string β its size, for example β gets stored in the structure that the info parameter points to. that's info's whole job, she's holding the metadata π
and here's the part that makes her so lowkey elegant: the new string does not have any other storage allocated of its own. none. zero. so if you allocate that info structure on the stack, you literally do not need to do any explicit "free" operation. it's giving no cleanup, no stress β¨
the referenced interval is [start_pos, end_pos). both of those are byte offsets, not character offsets β pay attention, this matters, iykyk.
β οΈ the string is valid until the underlying string is modified or destroyed. so the moment your original string gets touched, your little reference string is gone, bestie. it's a borrowed fit, not a bought fit π
if you need a range of code-points instead of bytes, use al_ustr_offset(3alleg5) to find the byte offsets first. she'll translate for you π§
π SEE ALSO π
go read those too, they're the same vibe, different energy β
and that's the whole page, babes π straight out of the Allegro reference manual, page al_ref_ustr(3alleg5). go forth and reference responsibly πβ¨
π¦ where this page comes from
- debian trixie: allegro5-doc 2:5.2.10.1+dfsg-1 Β· Zlib
- ubuntu questing: allegro5-doc 2:5.2.10.1+dfsg-1build1
- ubuntu resolute: allegro5-doc 2:5.2.11.3+dfsg-1 Β· Zlib
- ubuntu stonking: allegro5-doc 2:5.2.11.3+dfsg-1 Β· Zlib
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms