al_ref_cstr(3)
π al_ref_cstr(3) π
okay bestie, welcome to the Library Functions Manual β today's main character is al_ref_cstr(3) from the Allegro 5 API, and she's here to let a string vibe off C-string storage. no cap.
β¨ NAME β¨
al_ref_cstrβ Allegro 5 API (short, sweet, iconic)
π SYNOPSIS π
#include <allegro5/allegro.h>
const ALLEGRO_USTR *al_ref_cstr(ALLEGRO_USTR_INFO *info, const char *s)
π¦ DESCRIPTION π¦
so basically this function creates a string that references the storage of a C-style string. it is not out here allocating a whole new copy of the string's storage β it references the storage, periodt.
the information about the string (like its size, iykyk) is stored in the structure pointed to by the info parameter.
the string will not have any other storage allocated of its own, so if you allocate the info structure on the stack then no explicit free operation is required. stack info, no manual free β lowkey a slay.
π¨ vibe check: the string is valid until the underlying C string disappears. after that? it's a no-go, bestie. don't keep using the reference once the C string has ghosted.
Example, because examples ate:
ALLEGRO_USTR_INFO info;
ALLEGRO_USTR *us = al_ref_cstr(&info, "my string");
π SEE ALSO π
al_ref_buffer(3)β go look at this siblingal_ref_ustr(3)β and this one too, fr fr
Signed, sealed, and sent with sparkles from the Allegro reference manual β no date stamped on this one, so we're just gonna call it undated and iconic π
π¦ where this page comes from
- arch rolling: allegro 5.2.11.3-2 Β· Zlib AND BSD-3-Clause AND OFL-1.1 AND LicenseRef-Custom
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms