garrynewman / GWEN

Abandoned: GWEN - GUI Without Extravagant Nonsense.
MIT License
427 stars 102 forks source link

Replace Gwen::Event::Packet with void* #68

Closed Wizzard033 closed 11 years ago

Wizzard033 commented 11 years ago

If you're trying to store user-defined data, the best type to do it with is a void pointer. The current implementation does not fit my needs.

Implemented in a local copy.. ask if you want it.

jswigart commented 11 years ago

This was not a good change. You could have added a void* to the packet structure but replacing packet entirely with void* loses built in type safety and multi field ability of the user data for basic types, not to mention leaks memory for anything you allocate for the user data. I can understand the need to put more complex information in the packet than the types supported, but the fix for that isn't replacing it with void . At a minimum you could add a void \ to the packet. Even better, a little template wrapper could provide a type safe and memory leak safe wrapper around whatever pointer you allocate for the data.

Wizzard033 commented 11 years ago

This is the way other libraries do it so I just emulated them.

I'm sure there is a better way.

EDIT: Also, there is no memory leak here except for when people use it wrong. You have to allocate the data the void pointer points to with new and later delete it.