Dynamic compilation mechanism of objects in compile-time and run-time, OC

Source: Internet
Author: User

Compile-time

Compile-time as the name implies is the time to compile. What do you mean by compiling? The compiler helps you translate the source code into code that the machine can recognize. (This is, of course, only in the general sense that it may actually be a language that is translated into an intermediate state. For example, Java has only the JVM-recognized bytecode, and in C # There are only MSIL that the CLR recognizes. There are also linker. Assembler. For ease of understanding we can collectively refer to the compiler)

The compilation is simply to do some translation work , such as checking the man you have careless writing the wrong keyword. What is the lexical analysis, A process such as parsing. Just like a teacher. Check the student's composition for typos and wrong sentences. If you find anything wrong, the compiler will tell you. If you use Microsoft VS, click Build. Then start compiling, if there is errors or warning information below, That's what the compiler checks out. The so-called error is the compile-time error, the process of what type of check is called compile-time type check, or static type check (so-called static is not put the real code in memory to run, but just the code as text to scan). So sometimes some people say that it's definitely wrong to allocate memory at compile time.

Run-time

The so-called runtime is the code that runs. is loaded into memory. (Your code is a dead guy before it's loaded into memory on disk.) The Run-time type check is not the same as the previous compile-time type check (or static type check). Instead of simply scanning the code, do some things in memory and make some judgments.

1, why OC can not sizeof an object size? Structures that are similar in class structure can Because of the dynamic inheritance of OC compiler mechanism, dynamic inheritance mechanism, that is, at compile time can not determine the size of the parent class, only at run time to determine the size of the parent class,

The Sizeo is manipulated in the stack, and the value of sizeof is calculated when it is compiled.

And the stack does not know the size of the object's parent, so you cannot use sizeof to calculate the size of the object 2, why OC can not declare the object to static space, such as the stack, and similar to the structure of the class can be the stack is generated after the compilation, the result is a binary machine file, that is, the assembly stack has been generated So the stack can not put the object, because the stack is not known when the size of the parent class stack is described by the assembly code instructions Why the structure can be directly sent to calculate sizeof, can also be directly declared to the static space? Why can a struct be directly sizeof, whether defined in a stack or in a heap? Because the size of the struct is known when it is defined in the heap, the struct is exposed to the stack that the code that invokes it is generating. is because the struct-defined header file directly exposes the structure's properties to the stack, so it can be declared directly to the static space

In a word, the details of the parent class are closed to the stack that calls its subclasses, and the struct is exposed relative to the stack that called it.

The dynamic inheritance compilation mechanism in OC is not to expose the details of the parent class to the stack of the calling subclass at compile time, but to expose the details of the parent class to the stack of the calling subclass at runtime.

Dynamic compilation mechanism of objects in compile-time and run-time, OC

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.