Jinoh Kang (@iamahuman) commented about dlls/ntdll/heap.c:
+struct bin +{
- /* counters for LFH activation */
- LONG count_alloc;
- LONG count_freed;
- LONG enabled;
- /* list of groups with free blocks */
- SLIST_HEADER groups;
- /* array of affinity reserved groups, interleaved with other bins to keep
* all pointers of the same affinity and different bin grouped together,
* and pointers of the same bin and different affinity away from each other,
* hopefully in separate cache lines.
*/
- struct group *(*affinity_group)[BLOCK_SIZE_BIN_COUNT];
I think relying on pointer arithmetic for the stride is quite tricky to understand. Also, I couldn't find any precedent in the Wine code base.
How about using the following helper function instead?
```c static inline struct affinity_group **affinity_group_slot( struct bin *bin, ULONG affinity ) { /* see the struct field comment for details. */ return bin->affinity_groups_base + affinity * BLOCK_SIZE_BIN_COUNT; } ```
Example usage:
```c InterlockedExchangePointer( (void *)affinity_group_slot( bin, affinity ), NULL ) ```
Feel free to choose another name or return type you like.