Skip to Content
For Enterprise
For Government
For Higher Ed
For Individuals
For Marketing
For Enterprise
For Government
For Higher Ed
For Individuals
For Marketing
Explore Skills
Cloud Computing
Microsoft Azure
Amazon Web Services (AWS)
Google Cloud
Cloud Migration
Cloud Deployment
Cloud Platforms
Data Engineering
Data Warehouse
SQL
Apache Spark
Microsoft SQL Server
MySQL
Kafka
Data Lake
Streaming & Messaging
NoSQL Databases
Relational Databases
Data Science
Pandas
R
MATLAB
SAS
D3
Power BI
Tableau
Statistics
Exploratory Data Analysis
Data Visualization
AI & ML
Generative AI
Machine Learning
Artificial Intelligence (AI)
Deep Learning
Reinforcement Learning
Natural Language Processing
TensorFlow
Scikit-Learn
Hyperparameter Tuning
MLOps
Programming Languages
Java
JavaScript
Spring
Python
Go
C#
C++
C
Swift
Rust
Functional Programming
Software Architecture
Object-Oriented
Distributed Systems
Domain-Driven Design
Architectural Patterns
IT/Ops
Kubernetes
Docker
GitHub
Terraform
Continuous Delivery
Continuous Integration
Database Administration
Computer Networking
Operating Systems
IT Certifications
Security
Network Security
Application Security
Incident Response
Zero Trust Model
Disaster Recovery
Penetration Testing / Ethical Hacking
Governance
Malware
Security Architecture
Security Engineering
Security Certifications
Design
Web Design
Graphic Design
Interaction Design
Film & Video
User Experience (UX)
Design Process
Design Tools
Business
Agile
Project Management
Product Management
Marketing
Human Resources
Finance
Team Management
Business Strategy
Digital Transformation
Organizational Leadership
Soft Skills
Professional Communication
Emotional Intelligence
Presentation Skills
Innovation
Critical Thinking
Public Speaking
Collaboration
Personal Productivity
Confidence / Motivation
Features
All features
Verifiable skills
AI Academy
Courses
Certifications
Interactive learning
Live events
Superstreams
Answers
Insights reporting
Radar Blog
Buy Courses
Plans
Sign In
Try Now
O'Reilly Platform
book
LINUX系統程式設計 第二版
by
Robert Love
December 2013
Intermediate to advanced
496 pages
8h 57m
Chinese
GoTop Information, Inc.
Content preview from
LINUX系統程式設計 第二版
332
|
第九章
用
memset()
,直接使用
calloc()
會比較好:
glibc
知道匿名映射已經被填滿零值,而且
calloc()
會對「一個映射不需要明確填入零值」感到滿意。
系統呼叫
munmap()
會釋出一個匿名映射,並把已分配的記憶體釋回核心:
int ret;
/*
釋出
'p'
之後,會釋回
512 KB
的映射
*/
ret = munmap (p, 512 * 1024);
if (ret)
perror ("munmap");
mmap()
、
munmap()
以及映射的相關細節可參考第
4
章。
映射
/dev/zero
其他的
Unix
系統,例如
BSD
,並不具備
MAP_ANONYMOUS
旗標。事實上,它們是透過映射
一個特殊的裝置檔,
/dev/zero
,來實作類似的解決方案。此裝置檔為匿名記憶體提供了
一致的語意。一個映射包含了填滿零值的「寫入時才複製」(
copy-on-write
)頁面;因
此映射
/dev/zero
的行為如同使用匿名記憶體。
Linux
之上總是可以找到一個
/dev/zero
裝置,而且提供映射此檔案與取得填滿零值之記
憶體的能力。的確,引進
MAP_ANONYMOUS
之前,
Linux
程式設計者就是採用此做法。為
了向下相容於較舊版的
Linux
,或是移植到其他
Unix
系統,開發者仍然可以映射
/dev/
zero
,以便取代建立匿名映射的做法。這與「映射任何其他檔案」並無不同:
void *p;
int fd;
/*
開啟
/dev/zero
以備讀取與寫入
*/
fd = open ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial
You might also like
優雅的SciPy|Python科學研究的美學
Juan Nunez-Iglesias, Stéfan van der Walt, Harriet Dashnow
成為卓越程式設計師的38項必修法則
Pete Goodliffe
深入理解運算原理|從簡單的機器到無所不能的程式
Tom Stuart
C++语言导学(原书第2版)
本贾尼 斯特劳斯特鲁普
Publisher Resources
ISBN: 9789862769812