demofox,
@demofox@mastodon.gamedev.place avatar

Psst smart pointers still have to have their references cleared, else they leak just like regular pointers.

eniko,
@eniko@peoplemaking.games avatar

@demofox reference cycle garbage collector tho >_>

mtothevizzah,
@mtothevizzah@mastodon.gamedev.place avatar

@demofox Death to implicit behavior.

mmby,
@mmby@mastodon.social avatar

@demofox weak_ptr can 'let go' (as opposed to have shared_ptr in two places and having to coordinate) but I've rarely seen it talked about in any sort of tutorial on smart pointers

demofox,
@demofox@mastodon.gamedev.place avatar

@mmby oh yeah, weak pointers are pretty nice. They were used heavily in the lithtech engine at monolith for networked game objects and it was a real positive experience. The lifetime of these things were real complex, but the weak pointers made that complexity largely invisible.

floooh,
@floooh@mastodon.gamedev.place avatar

@demofox @mmby today I wouldn't consider anything else but generation-counted-index-handles. Gives you weak references with dangling protection, and also encourages to properly separate system internals from the outside world.

Raw pointers are fine inside the system, but only pass handles across system boundaries.

bobbydigitales,
@bobbydigitales@mastodon.gamedev.place avatar

@floooh @demofox @mmby Do you know of a good implementation of this that I could learn from?

floooh,
@floooh@mastodon.gamedev.place avatar

@bobbydigitales @demofox @mmby I use such handles in sokol_gfx.h but the implementation is buried deep in the header unfortunately. But this sample might give you an idea how they're used in the public API (sg_buffer, sg_shader, etc.. are such handles): https://github.com/floooh/sokol-samples/blob/master/sapp/cube-sapp.c

This Zig implementation might be nicer to read, and it's also more 'generic' and flexible:

https://github.com/zig-gamedev/zig-gamedev/tree/main/libs/zpool

jesta88,
@jesta88@mastodon.gamedev.place avatar

@floooh @demofox @mmby This. I'm always surprised how "new" or alien of a concept this is to even senior programmers.

I blame the ubiquity of standard C++ in our industry for this. Your blog post on handles has come in handy a great many times when explaining the concept 🙂.

PetorSFZ,
@PetorSFZ@mastodon.gamedev.place avatar

@floooh @demofox @mmby

There’s been some push back to handles at work actually. The problem is that they make the program harder to debug. With pointers you can easily see the value in the debugger, with a handle just an index somewhere else.

The current compromise is to store a pointer the handle, but only in debug builds. Not sure if I like it.

floooh,
@floooh@mastodon.gamedev.place avatar

@PetorSFZ @demofox @mmby yeah I can see the advantages of carrying a debug-pointer with the handles, but it requires to make the underlying struct public too (which ideally is private to the system that created the handle).

But in general I think "fat handles" that carry additional information in debug mode aren't a bad idea per se.

bobbydigitales,
@bobbydigitales@mastodon.gamedev.place avatar

@floooh @PetorSFZ @demofox @mmby Couldn't you also write code to display your handles correctly in the debugger? I remember Visual Studio can do that.

BartWronski,
@BartWronski@mastodon.gamedev.place avatar

@demofox definitely! and having a smart pointer usage/system without an easy way to track and display reference holders is just asking for long, very frustrating memory usage debugging sessions. :)

demofox,
@demofox@mastodon.gamedev.place avatar

This hot take is 10-20 years too late

  • All
  • Subscribed
  • Moderated
  • Favorites
  • random
  • rosin
  • thenastyranch
  • mdbf
  • DreamBathrooms
  • InstantRegret
  • magazineikmin
  • Youngstown
  • cisconetworking
  • slotface
  • vwfavf
  • everett
  • Durango
  • kavyap
  • GTA5RPClips
  • megavids
  • khanakhh
  • osvaldo12
  • ngwrru68w68
  • normalnudes
  • anitta
  • ethstaker
  • cubers
  • modclub
  • tacticalgear
  • provamag3
  • Leos
  • tester
  • JUstTest
  • All magazines