randrew / layout

Single-file library for calculating 2D UI layouts using stacking boxes. Compiles as C99 or C++.
Other
892 stars 69 forks source link

Fix several g++ warnings and ability to carry along a user pointer #9

Closed joshua-henderson closed 5 years ago

randrew commented 5 years ago

Hi Joshua. Thanks for taking the time to submit this.

The reason layout does not already have a user pointer in the items is that the user is meant to relate the items with their own data by using the ID/index of the item. layouts item IDs are contiguous in the order they are created, so you can simply allocate an array with the same count as the number of items you have, and put your user pointers at the associated indices.

By adding a user pointer to the item data struct, it increases the size of each item from 24 bytes to 32 bytes (on 64-bit, 28 bytes on 32-bit) and increases the alignment requirement from 4 bytes to 8 bytes (on 64-bit). Because most users will not use the user pointers, this ends up as entirely wasted space and memory bandwidth.

joshua-henderson commented 5 years ago

Makes sense. What about the other changes? Would you take an updated pull request removing the user data pointer commit?

randrew commented 5 years ago

Yes, definitely!