What Is Code Reuse?
Code reuse is a programming technique that reduces time and resources to develop software. When you develop code for reuse, the code serves multiple purposes. The technique involves modularization, which enables multiple individuals to develop code for various system components independently and in parallel. The technique also simplifies software distribution.
A software library is an example of code reuse. A library can contain code for several functions, each having specific behavior. To use a library, you need to know only the interface, which is the specification for calling the library functions.
Reusable code can be reentrant. You can invoke, interrupt, and reinvoke reentrant code. Reentrant code resides in shared memory. Instances of data associated with each use of the code are unique and preserved. Multiple calls to a reusable, reentrant function, for example, can access the function code with each call maintaining a unique data set.
Applications of code reuse include:
Switching between implementations of a function.
Intellectual property protection.
Overriding library behavior with a custom implementation.
Implementing a library that is based on standard library functions.
Execution speed improvement.
The code generator supports code reuse and reentrancy. You can use key Simulink® componentization techniques to partition a model into design components that you simulate, generate code for, and verify independently. You can save individual components as subsystems, libraries, referenced models, or combinations of these elements from which you can generate code. For example, the code generator produces reusable function code from library subsystems and export-function models.
- What Is Reentrant Code? (Embedded Coder)
- Choose a Componentization Technique for Code Reuse (Embedded Coder)