计算机专业毕业设计论文外文文献中英文翻译(Object).pdf
文本预览下载声明
外文资料
Object landscapes and lifetimes
Technically, OOP is just about abstract data typing, inheritance, and
polymorphism, but other issuescan be at least as important. The remainder of this
section will cover these issues.
One of the most important factors is the way objects are createdand destroyed.
Where is the data for an object and how is the lifetime of the object controlled? There
are different philosophies at work here. C++ takes the approach that control of
efficiency is the most important issue, so it gives the programmer a choice. For
maximum run-time speed, the storage and lifetime can be determined while the
program is being written, by placing the objects on the stack (these are sometimes
called automatic or scoped variables) or in the static storage area. This places a
priority on the speed of storage allocation and release,and control of these can be
very valuable in some situations. However,you sacrifice flexibility because you must
know the exact quantity, lifetime, and type of objects while youre writing the
program. If you are trying to solve a more general problem such as computer-aided
design, warehouse management, or air-traffic control, this is too restrictive.
The second approach is to create objects dynamically in a pool of memory called
the heap. In this approach, you dont know until run-time how many objects you need,
what their lifetime is, or what their exact type is. Those are determined at the spur of
the moment while the program is running. If you need a new object, you simply make
it on the heap at the point that you need it. Because the storage is managed
dynamically, at run-time, the amount of time required to allocate storage onthe heap
is significantly longer than the time to create storage on the stack. (Creating storage
on the stack is often a single assembly instructio
显示全部