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系統程式設計 第二版
342
|
第九章
選擇記憶體分配機制
本章提到了各式各樣的記憶體分配機制,可能會讓程式設計者無法確定,哪個是最適合
自己的解決方案。多數情況下,
malloc()
是你的最佳選擇。然而,有時另一種做法才是
比較好的選擇。表
9-2
整理出了選擇分配機制的指導方針。
表
9-2
Linux
的記憶體分配機制
分配機制
優點
缺點
malloc()
容易、簡單、常用。
所傳回的記憶體未必填滿零值。
calloc()
簡化陣列的分配,所傳回的記憶體填
滿零值。
如果不是分配陣列,介面過於複雜。
realloc()
調整既有分配的尺寸。
只能用於調整既有分配的尺寸。
brk()
與
sbrk()
可對堆積進行內部的控制。
對多數用戶而言太過低階。
匿名記憶體分配
容易使用、可共享、允許開發者調整
保護等級以及提供警告訊息;是大型
映射的優選項目。
是小型分配的次優選項目;為優選項目
時,
malloc()
會自動使用匿名記憶體映
射。
posix_memalign()
分配記憶體並對齊任何適當的邊界。
相對較新,因此移植性令人質疑;必須
密切關注對齊問題,否則會有很大的殺
傷力。
memalign()
與
valloc()
相較於
posix_memalign()
,較常用在
其他的
Unix
系統上。
並非
POSIX
標準,所提供的對齊控制
不如
posix_memalign()
。
alloca()
分配速度非常快,不需要明確釋出記
憶體;非常適合小型的分配。
不會傳回錯誤,不適合大型的分配,在
某些
Unix
系統上會出問題。
可變長度陣列
如同
alloca()
,但會在陣列離開有效 ...
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