On Tuesday, 24 February 2026 at 15:30:39 UTC, H. S. Teoh wrote:
On Tue, Feb 24, 2026 at 03:48:46AM +0000, monkyyy via Digitalmars-d-learn wrote:
Im going to try doing something with fat structs, what sort of syntax and api niceitys would big fat-struct advocates say are nessery?

What's a "fat struct"?


T

In programming, the term "fat struct" (or "fatty struct") refers to a data structure design philosophy, notably advocated by programmer Casey Muratori, that prioritizes data locality, performance, and predictability over object-oriented design principles like deep inheritance hierarchies. [1, 2]

Core Principles

The fat struct approach represents a fundamental difference in how software development priorities are ordered, focusing on efficiency over abstract ideals.

• Packs Related Data: It involves grouping all related data into a single, contiguous block of memory within one structure, rather than spreading it across multiple objects that require pointers and indirection to access. • Prioritizes Cache Efficiency: By keeping frequently accessed data physically close in memory, this design makes better use of modern CPU caches, leading to significant performance improvements. • Avoids Unnecessary Abstraction: It eschews complex object-oriented programming (OOP) patterns, preferring simple control flow and a design that more directly reflects what the computer hardware is actually doing. • Uses Unions Judiciously: While the primary goal is a single structure, unions might be used to save space if some fields are mutually exclusive, though this can make debugging more complex. [2, 3]

Comparison to OOP

The fat struct approach is often contrasted with the traditional OOP paradigm where specialized classes inherit properties and methods from a base class.

• Inheritance vs. Type Property: Instead of creating multiple specialized classes (e.g., and inheriting from ), a single "fat" struct would contain all possible properties (like and ) and use an explicit field to determine which behaviors and data are relevant. • Performance Trade-off: The OOP approach is often seen as more maintainable and easier to extend, while the fat struct approach trades some of that perceived maintainability for raw performance. • Data-Oriented Design: The philosophy is a key component of data-oriented design (DOD), where the focus is on how data is laid out in memory and accessed, rather than modeling real-world entities with class hierarchies. [1, 2, 4, 5]

Practical Implementation Tips

If you are interested in applying these principles, advocates suggest a pragmatic approach:

1. Start with Data Access Patterns: Design your structures around how your code actually uses the data, not in an abstract ideal. 2. Measure Performance: The benefits of this approach should be measurable; benchmark before and after implementation to ensure the trade-off is worthwhile. 3. Document Layout Decisions: Clearly document the rationale behind your memory layouts for future maintainers. [6, 7]

[1] https://orangegnome.com/posts/3633/team-fat-posts
[2] 
https://levelup.gitconnected.com/fatty-structs-casey-muratoris-approach-to-data-structure-design-ad4753caaf6b
[3] https://www.computerenhance.com/p/q-and-a-80-2025-10-31
[4] https://www.yegor256.com/2020/02/19/fat-skinny-design.html
[5] 
https://www.reddit.com/r/roguelikedev/comments/1bv4k7p/any_tutorial_about_dataoriented_programming_for/
[6] 
https://levelup.gitconnected.com/fatty-structs-casey-muratoris-approach-to-data-structure-design-ad4753caaf6b
[7] 
https://levelup.gitconnected.com/fatty-structs-casey-muratoris-approach-to-data-structure-design-ad4753caaf6b

All the content above was generated by AI, I'm just annexing to the post to future readers.

Matheus.

Reply via email to