TAILIEUCHUNG - ANSI/ISO C++ Professional Programmer's Handbook phần 9

Tham khảo tài liệu 'ansi/iso c++ professional programmer's handbook phần 9', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | ANSI ISO C Professional Programmer s Handbook - Chapter 11 - Memmory Management Put differently the statement C p new C is transformed by the compiler into something similar to the following include new using namespace std class C . void new throw bad_alloc C p reinterpret_cast C new char sizeof step 1 allocate raw memory try new p C step 2 construct the objects on previously allocated buffer catch . catch any exception thrown from C s constructor r delete p free the allocated buffer throw re-throw the exception of C s constructor Alignment Considerations The pointer that is returned by new has the suitable alignment properties so that it can be converted to a pointer of any object type and then used to access that object or array. Consequently you are permitted to allocate character arrays into which objects of other types will later be placed. For example include new include iostream include string using namespace std class Employee private string name int age public Employee Employee void func use a pre allocated char array to construct an object of a different type char pc new char sizeof Employee Employee pemp new pc Employee construct on char array .use pemp pemp- Employee Employee explicit destruction file D Cool Stuff old ftp 1 1 ch11 11 von 23 14 46 34 ANSI ISO C Professional Programmer s Handbook - Chapter 11 - Memmory Management delete pc It might be tempting to use a buffer that is allocated on the stack to avoid the hassle of deleting it later char pbuff sizeof Employee Employee p new pbuff Employee undefined behavior However char arrays of automatic storage type are not guaranteed to meet the necessary alignment requirements of objects of other types. Therefore constructing an object of a preallocated buffer of automatic storage type can result in undefined behavior. Furthermore creating a new object at a storage location that was previously occupied by a const object with static or automatic storage type also results in .

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.