NET_RefAddress(3)

πŸ“¦
version 3.2.0 Β· 2 versions
, in fedora 43, fedora 44

πŸ’– NET_RefAddress(3) πŸ’–

okay bestie, welcome to the SDL_net3 functions corner of the manual, and today's main character is NET_RefAddress 🫢


✨ NAME ✨

NET_RefAddress β€” add a reference to an NET_Address. that's it, that's the job πŸ’…


🌸 SYNOPSIS 🌸

#include <SDL3_net/SDL_net.h>

NET_Address* NET_RefAddress(NET_Address *address);

πŸ¦‹ DESCRIPTION πŸ¦‹

so here's the tea β˜• β€” multiple pieces of the library can share a single NET_Address, and that includes a background thread that's out there working on resolving. because of that, these objects are reference counted. it's giving "we all agree we still want this thing." everything using it can declare it still wants it, and then drop its reference when it's done. and when the very last reference gets dropped, the object's resources are freed. gone. bye πŸ‘‹βœ¨

this function adds a reference to an NET_Address, which bumps its reference count up by one. no cap πŸ“ˆ

the documentation will tell you when your app has to explicitly unref an address. for example, NET_ResolveHostname() creates addresses that are already referenced, so the caller needs to unref it when done. don't forget, bestie 😭

generally you only have to explicitly ref an address when you've got different parts of your own app that will be sharing an address. in normal usage, you only have to unref things you've created once (kinda like you might free() something), but you are absolutely free to add extra refs if it makes sense. your app, your rules πŸ‘‘

and the best part?? this returns the same address you passed in as a parameter, which makes it super easy to ref and assign in one single step. obsessed:

myAddr = NET_RefAddress(yourAddr);

πŸŽ€ FUNCTION PARAMETERS πŸŽ€

  • address β€” the NET_Address to add a reference to. yeah. that one. the address right there 🫡

🌈 RETURN VALUE 🌈

returns the same address that was passed as a parameter. not a copy, not a new one, the literal same one. iconic behavior honestly ⭐


πŸ”₯ THREAD SAFETY πŸ”₯

it is safe to call this function from any thread. go wild, no vibe check needed πŸ’€βœ¨


πŸ‘‘ AVAILABILITY πŸ‘‘

this function is available since SDL_net 3.0.0. so if you're on 3.0.0 or later, you're slaying πŸ’…


fr fr: this whole ref/unref situation is just malloc/free energy but for shared addresses. you ref when you want in, you unref when you're out, and the last one to leave turns off the lights πŸ•―οΈ

and that's a wrap on the page, babe πŸŽ€ this was pulled straight from the SDL_net manual, version SDL_net 3.2.0 β€” go forth and reference count responsibly, bestie πŸ’–πŸŒΈπŸ¦‹

πŸ“¦ where this page comes from