惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

K
Kaspersky official blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
AI
AI
SecWiki News
SecWiki News
宝玉的分享
宝玉的分享
Scott Helme
Scott Helme
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Engineering at Meta
Engineering at Meta
博客园 - 叶小钗
The GitHub Blog
The GitHub Blog
Microsoft Azure Blog
Microsoft Azure Blog
N
News and Events Feed by Topic
Cloudbric
Cloudbric
B
Blog
Cisco Talos Blog
Cisco Talos Blog
V
Vulnerabilities – Threatpost
N
News and Events Feed by Topic
V
Visual Studio Blog
A
Arctic Wolf
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
U
Unit 42
S
Security @ Cisco Blogs
博客园 - 聂微东
T
Threat Research - Cisco Blogs
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Apple Machine Learning Research
Apple Machine Learning Research
Y
Y Combinator Blog
G
GRAHAM CLULEY
L
LINUX DO - 热门话题
量子位
NISL@THU
NISL@THU
Webroot Blog
Webroot Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
T
Troy Hunt's Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
T
Tenable Blog
月光博客
月光博客
S
Security Affairs
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
The Hacker News
The Hacker News
Spread Privacy
Spread Privacy
D
Docker
www.infosecurity-magazine.com
www.infosecurity-magazine.com
雷峰网
雷峰网
博客园 - 司徒正美
T
The Exploit Database - CXSecurity.com
Hugging Face - Blog
Hugging Face - Blog
Help Net Security
Help Net Security
D
DataBreaches.Net

Inside Nutrient

A guide to the invisible work behind documents Introducing Nutrient Documents for Salesforce: Native document generation and signing Document AI vs. traditional OCR: Choosing between OCR, AI, and hybrid pipelines PDF SDK compliance and security evaluation checklist for enterprise teams (2026) Invariant Corp replaces paper processes with Nutrient Workflow and scales without limits What is process mapping? A complete guide Nutrient vs. Conga Composer for Salesforce document generation (2026) Document routing: How to automate document distribution The CTO’s AI playbook: Why accountability architecture beats orchestration Compliance workflow automation: Why built-in compliance is table stakes Workflow diagrams: Examples, symbols, and how to build one that actually runs Digital forms: Replace paper forms with automated workflows Approval workflow software: How to automate approvals Why document-centric automation is different The CEO’s AI playbook: Why decision architecture beats model selection Nutrient SDK product updates for Q1 2026 PDF redaction verification: How to prove sensitive data is permanently removed What is a VPAT? The complete guide to accessibility conformance reports What is PDF/UA? The accessible PDF standard explained Salesforce eSignatures: Generate, sign, and track documents in one flow Online document viewer: Options, tradeoffs, and how to embed one Document viewer for web apps: React, Vue, Angular (2026) Best document viewers in 2026: A buyer’s guide How to edit a PDF in Python: Add text, images, and annotations Nutrient advances Workflow platform with agentic AI for enterprise-grade speed and consistency in document-heavy operations How to create a Salesforce quote template from opportunity data The business case for accessibility: Five ways it drives enterprise value Python PDF library comparison (2026): 7 libraries for developers Why your AI agent hallucinates PDF table data PDF.js limitations: When to upgrade to a commercial PDF SDK How Subject scaled 5× with Nutrient’s PDF SDK without rebuilding its document layer I replaced our sales training with an AI coach that runs in Slack — here’s what broke Redirecting to: https://securitybuzz.com/cybersecurity-news/why-enterprise-permissions-are-ais-most-dangerous-inheritance/ Nutrient .NET SDK vs. iText Core: Complete comparison for .NET developers DocuVieware: Support’s most frequently asked setup questions Introducing Nutrient Workflow How to convert PDF to Word in C# (.NET) When email and spreadsheets stop working: Work order approval workflows for field teams on the move Compliance with confidence: Why document-centric automation is the foundation of your mission Nutrient expands AI Assistant, automating multistep document workflows inside any application What is document generation? A developer’s guide to PDF generation Document Converter data flow and how real-time watermarks skip the queue PDF/UA compliance guide: Requirements, standards, and best practices Computers still can’t understand you How Athena Intelligence built AI agents for regulated enterprises with Nutrient’s document infrastructure How to convert HTML to PDF (2026): 4 methods from browser print to SDK How to build a document extraction pipeline with Nutrient Vision API OCR vs. intelligent document processing: Choosing the right document extraction engine Beyond OCR: How document intelligence eliminates manual processing in regulated industries Nutrient vs. IronPDF: Complete comparison for .NET developers Nutrient vs. Aspose.PDF: Complete comparison for .NET developers Redirecting to: https://fortune.com/2026/02/19/openclaw-who-is-peter-steinberger-openai-sam-altman-anthropic-moltbook/ Lufthansa Systems uses Nutrient to deliver reliable, scalable PDF rendering for pilots worldwide Nutrient vs. Syncfusion: Complete comparison for .NET developers React’s useTransition: The hook you’re probably using wrong First City Monument Bank streamlines banking processes with Nutrient Workflow Redirecting to: https://www.sdcexec.com/warehousing/automation/article/22957364/nutrient-workflow-automation-the-missing-link-in-supply-chain-efficiency The complete guide to digital signatures: PAdES, CAdES, and XAdES explained Nutrient Python SDK: Production-grade document processing for Python Introducing agentic document editing for web applications with AI Assistant Nutrient vs. QuestPDF: Complete comparison for .NET developers How we fixed the GdPicture license expiration (and what to do if you’re affected) Red team security testing with agentic AI The future of healthcare document automation Best healthcare workflow software compared Nutrient SDK product updates for Q4 2025 How Harvey scaled legal document workflows 50 percent MoM without rebuilding infrastructure HIPAA-compliant document management in hospitals How we optimized rendering performance while handling thousands of annotations in React — Part 2 Automated PII removal with Nutrient API Redirecting to: https://www.devopsdigest.com/2026-low-code-no-code-predictions Redirecting to: https://www.kmworld.com/Articles/Editorial/ViewPoints/Leaders-predict-AI-to-continue-permeating-all-aspects-of-KM-in-2026-172594.aspx What are deep agents and how do they solve complex problems? Whipping up document magic: Your easy-bake recipe for Vue and Nutrient Web SDK 🧁 What I’ve learned about product iteration planning while building SDKs Passwordless document signing: Three-layer security guide New zip folder functionality streamlines file management in Document Automation Server The keyboard shortcuts playbook: Taking control of keyboard events in Nutrient Web SDK From experienced engineer to AI beginner: My unexpected journey AI-assisted manual testing: Handling Safari’s PDF rendering and UI quirks How to keep a 20-year-old SDK up to date How we optimized rendering performance while handling thousands of annotations in React — Part 1 Nutrient announces new executive hires to accelerate next phase of growth High performance UI using web workers Automate document conversion at scale with Python and Nutrient DCS From curiosity to PLG (and AI): My journey to understanding product-led growth Prost to progress: One year as Nutrient Pigeon usage at Nutrient: Bridging native SDKs to Flutter Modernizing CI build servers: How to migrate from Chef to Ansible Unix man pages: AI-friendly documentation since 1971 Consistent hashing for even load distribution Best AI redaction APIs: Complete comparison guide for 2025 Why AI document redaction matters for modern security From coding to coordinating: How AI transformed my workflow What is intelligent document processing (IDP)? A complete guide Enterprise PDF SDKs: Best PSPDFKit (now Nutrient) alternatives Nutrient SDK product updates for Q3 2025 GdPicture support best practices Redacting sensitive data with Nutrient AI redaction API How AI is transforming the customer experience at Nutrient: From instant answers to intelligent support
Structure Padding in C++
Patrik Weiskircher · 2024-09-03 · via Inside Nutrient

Structs and classes are a fundamental part of C++ and are used to group related data together. This article will look at one aspect of them that’s often overlooked: memory padding. Understanding how data is laid out in memory can help you write more efficient code and optimize the performance of your programs.

Because padding and memory layout is the same between structs and classes, this post will use the term struct, but everything that applies to structs also applies to classes.

What Is a Struct?

A struct is a user-defined data type that allows you to combine data into one group. It looks like this:

struct name {

std::string first_name;

std::string last_name;

};

The example above defines a struct called name that contains two members: first_name and last_name. The members of a struct can be of any data type, including other structs or classes. For example, you can use the struct like this:

// A method that prints out the members of the struct.

void print_name(const name& name) {

std::cout << "First name: " << name.first_name << std::endl;

std::cout << "Last name: " << name.last_name << std::endl;

}

int main(int argc, char **argv) {

// Create an instance of the struct and initialize its members.

name my_name{.first_name = "Patrik", .last_name = "Weiskircher"};

// Call a method with the struct as an argument.

print_name(my_name);

}

There are many ways to initialize and pass a struct around (this post uses C++20’s designated initializers(opens in a new tab)), but that’s not the focus of this article. You can find more information about structs in the C++ documentation(opens in a new tab).

Memory Padding

Data is stored in memory. For example, a uint32_t will take up four bytes in memory. How this is stored is dependent on many rules(opens in a new tab). We won’t be going too much into detail here — this could be the topic of many blog posts. But one thing that’s important to know about is padding.

In structs, padding is the space that’s added between the members to allow efficient access to the data by the CPU. Here’s an example:

struct my_second_struct {

// bool == 1 byte

bool first_flag;

// bool == 1 byte

bool second_flag;

// uint32_t == 4 bytes

uint32_t first_value;

};

The struct above has two Booleans and one 32-bit integer. Together, they take up six bytes. But if padding and memory layout in structs were this easy, we wouldn’t need to read a blog post about it. Let’s see how big this struct really is:

#include <iostream>

#include <cstdint>

struct my_second_struct {

bool first_flag;

bool second_flag;

uint32_t first_value;

};

int main(int argc, char **argv) {

std::cout << sizeof(my_second_struct) << std::endl;

}

Put this in a file and compile it. On my Apple silicon Mac, it looks like this:

$ clang++ -o padding padding.cpp

$ ./padding

8

The result is eight bytes. Why’s that? The CPU likes to read data in chunks of certain sizes — for example, four bytes. To make access as efficient as possible, the compiler adds padding between the members. In this case, the compiler adds two bytes of padding after the two Boolean members to make sure that the 32-bit integer is properly aligned.

padding graph

This can also be seen with the clangd plugin(opens in a new tab) in Visual Studio Code.

clangd showing padding

Why Should You Know About Padding?

Padding is important to understand because it can affect the size of your data structures and how they’re laid out in memory. This can have an impact on the performance of your program, especially if you’re working with large data structures or need to optimize memory usage.

As an example, say you’re tasked with adding another Boolean to the struct above. Let’s call it bool very_very_important. You now have to decide where to add it. I personally like to add things at the bottom unless they’re related. That would result in this:

struct my_third_struct {

bool first_flag;

bool second_flag;

uint32_t first_value;

bool very_very_important;

};

How big is the struct now? Let’s look using Visual Studio Code again.

clangd showing the new size

It’s now 12 bytes! The compiler added three bytes of padding after the very_very_important member to make sure the whole struct is properly aligned. Now imagine this struct is used in an array with 1 million elements. That’s 3 million bytes of wasted memory!

But there’s a better way:

struct my_third_struct {

bool first_flag;

bool second_flag;

bool very_very_important;

uint32_t first_value;

};

If you add the Boolean to the other Booleans — where there’s already padding — you get a new Boolean for free.

clangd showing the optimized size

Conclusion

Understanding how data is laid out in memory can help you write more efficient code and optimize the performance of your programs. By being aware of padding and how it affects the size and layout of your data structures, you can make better decisions about how to organize your data and improve the performance of your programs.