Beginning Rust by Carlo Milanesi
Author:Carlo Milanesi
Language: eng
Format: epub
Publisher: Apress, Berkeley, CA
This, in a 64-bit system, may print:
0x1 0 0
0x7fbf95e20020 4 1
0x7fbf95e20020 4 2
0x7fbf95e20020 4 3
0x7fbf95e20020 4 4
0x7fbf95e20020 8 5
0x7fbf95e20020 8 6
0x7fbf95e20020 8 7
0x7fbf95e20020 8 8
0x7fbf95e2a000 16 9
0x7fbf95e2a000 16 10: aaaaaaaaaa
The as_ptr function (to be read “as pointer”) returns the address of the heap-allocated buffer containing the characters of the string .
Notice that when the string is empty, such address is simply 1, which is an invalid memory address, because no buffer is allocated for a string just created as empty.
When one ASCII character is added, a 4-byte buffer is allocated at an address represented by the hexadecimal number 7fbf95e20020.
Adding three other characters, no reallocations are required because the buffer is large enough.
When the fifth character is added, a reallocation is required, but, as the memory immediately following the buffer is still free, the buffer may be simply extended to 8 bytes, so avoiding the overhead of allocating a new buffer, copying the four used bytes, and deallocating the previous buffer.
Again, adding 3 other characters, no reallocations are required, but when the ninth character is added, not only the buffer is to be extended to 16 bytes, but it has to be relocated, as, presumably, not every one of the 8 next bytes is free.
At the end, the string uses 10 bytes.
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Coding Theory | Localization |
Logic | Object-Oriented Design |
Performance Optimization | Quality Control |
Reengineering | Robohelp |
Software Development | Software Reuse |
Structured Design | Testing |
Tools | UML |
Deep Learning with Python by François Chollet(11824)
Hello! Python by Anthony Briggs(9351)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(9322)
The Mikado Method by Ola Ellnestam Daniel Brolund(9288)
Dependency Injection in .NET by Mark Seemann(8836)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(7836)
Grails in Action by Glen Smith Peter Ledbrook(7286)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7265)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7097)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(5933)
Kotlin in Action by Dmitry Jemerov(4617)
Practical Vim (for Kathryn Amaral) by Drew Neil(3718)
Cracking the GRE Premium Edition with 6 Practice Tests, 2015 (Graduate School Test Preparation) by Princeton Review(3582)
Linux Device Driver Development Cookbook by Rodolfo Giometti(3335)
Learn Windows PowerShell in a Month of Lunches by Don Jones(3224)
Learning Java by Patrick Niemeyer & Daniel Leuck(2861)
Learning React: Functional Web Development with React and Redux by Banks Alex & Porcello Eve(2822)
Mastering Java 9 by Dr. Edward Lavieri(2565)
Learning Concurrency in Python by Elliot Forbes(2540)