V
V
Vitaly2017-10-29 16:28:02
C++ / C#
Vitaly, 2017-10-29 16:28:02

Is it possible to save memory when copy-pasting?

Imagine such an example. There are several functions that partially repeat the functionality, for example, they contain the same array assignment loop. There can be many such repetitions, which affects the size of the executable file and the speed of its loading into RAM. Are there ways to compile (let's say) a reference method? I mean this example:

<раздел "a">
<command 1>
<command 2>
...
</a>

<функция "f">
<command 1>
<alias "a">
<command n>
...
</f>

Here, a certain set of commands is defined in a separate section, and when loading a function into the call stack, some of the commands will be taken from it, and not duplicated for each function separately. I hope I explained clearly.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Arseniy Efremov, 2017-10-29
@vitali1995

In the general case, this task is not solvable due to the difference in execution contexts.
To achieve a similar effect, people came up with functions, after all. I think you know that a function is basically a call statement wrapped in extra code to create an isolated context. If you don't want this behavior, then why not just use regular jmp/call instructions and write in goto style? Then separate sections of the code will rely on certain assumptions about the context and be reused, depending on it. But keep in mind that this approach is extremely complex and is the source of a large number of errors.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question