McNamara Timothy Samuel - Rust In Action. Systems Programming Concepts And Techniques.pdf
(
18723 KB
)
Pobierz
Systems programming concepts
and techniques
Timothy Samuel McNamara
MANNING
Raw Pointer
Box<T>
Rc<T>
Arc<T>
The cousins
*
mut T and
*const
T are the free radicals
of the pointer world. Lightning
fast, but wildly unsafe.
Powers
• Speed
• Can interact with
the outside world
Weaknesses
• Unsafe
Store anything in a box. Accepts
almost any type for long-term
storage. The workhorse of a
new, safe programming era.
Powers
• Store a value in
central storage
in a location
called “the heap”
Weaknesses
• Size increase
The reference counted pointer, Rc<T>
is Rust's competent, yet miserly
bookkeeper. It knows who has
borrowed what and when.
Powers
• Shared access
to values
Weaknesses
• Size increase
• Runtime cost
• Not threadsafe
Arc<T> is Rust’s ambassador.
It can share values across threads,
guaranteeing that these will
not interfere with each other.
Powers
• Shared access
to values
• Threadsafe
Weaknesses
• Size increase
• Runtime cost
Cell<T>
RefCell<T>
Cow<T>
String
An expert in metamorphosis,
Cell<T> confers the ability to
mutate immutable values.
Performs mutation on immutable
references with RefCel<T>.
Its mind-bending powers
come with some costs.
Powers
• Interior mutability
• Can be nested
within Rc and Arc,
which only accept
immutable refs
Weaknesses
• Size increase
• Runtime cost
• Lack of compile-
time guarantees
Why write something down when
you only need to read it? Perhaps
you only want to make modifications.
This is the role of Cow (copy on write).
Powers
• Avoids writes
when only read
access is used
Weaknesses
• Possible size
increase
Acting as a guide on how to
deal with the uncertainties of
user input, String shows us how
to build safe abstractions.
Powers
• Grows dynamically
as required
• Guarantees correct
encoding at runtime
Weaknesses
• Can over
allocate size
Powers
• Interior mutability
Weaknesses
• Size increase
• Performance
Arc<T>
RawVec<T>
Unique<T>
Shared<T>
Your program’s main storage system.
Vec<T> keeps your data orderly
as values are created and destroyed.
The bedrock of Vec<T> and
other dynamically sized types.
Understands how to provide a
home for your data as needed.
Powers
• Grows dynamically
as required
• Works with the
memory allocator
to find space
Weaknesses
• Not directly
applicable from
your code
Sole owner of a value,
a unique pointer is guaranteed
to possess full control.
Sharing ownership is hard.
Shared<T> makes life
a little bit easier.
Powers
• Grows dynamically
as required
Weaknesses
• Can over
allocate size
Powers
Weaknesses
• Base for types
• Not appropriate
such as Strings,
for application
requiring exclusive
code directly
possession of values.
Powers
• Shared ownership
• Can align memory
to T’s width, even
when empty
Weaknesses
• Not appropriate
for application
code directly
Rust in Action
Rust in Action
S
YSTEMS PROGRAMMING
CONCEPTS AND TECHNIQUES
T
IM
M
C
N
AMARA
MANNING
S
HELTER
I
SLAND
Plik z chomika:
george.mouflon
Inne pliki z tego folderu:
Ali Atif, Bhatti Baber Majid - Spies In The Bits And Bytes. The Art Of Cyber Threat Intelligence.pdf
(53311 KB)
Adamatzky Andrew (ed.) - Actin Computation. Unlocking The Potential Of Actin Filaments For Revolutionary Computing Systems.pdf
(21268 KB)
Barolli Leonard, Petrakis Euripides G. M., Hussain Farookh (ed.) - Advances In Internet, Data & Web Technologies. The 14th International Conference On Emerging Internet, Data And Web Technologies (EID.pdf
(41071 KB)
Caldwell Craig - Story Structure And Development. A Guide For Animators, VFX Artistis, Game Designers, And XR Creators (Second Edition).epub
(90699 KB)
Agrawal Neha, Kumar Rohit, Tapaswi Shashikala - Cloud Computing Security. Strategies And Best Practices.pdf
(18062 KB)
Inne foldery tego chomika:
Android
Art
Artificial Intelligence
Biology
C(++)
Zgłoś jeśli
naruszono regulamin