Method and device for executing external script, equipment and medium
By calculating the memory size of the external scripts and continuously saving the script structure, using the Burst compiler to optimize execution, the memory usage and delay of external scripts in the DOTS framework is solved, and the execution speed and user experience are improved.
Patent Information
- Application Number
- CN202510884977.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-30
- Publication Date
- 2025-07-29
- Estimated Expiration
- 2045-06-30
AI Technical Summary
In the prior art, when external scripts are run in the DOTS framework, due to the difficulty of data interaction, the memory usage increases, causing call delays, and affecting the game screen and user experience.
By calculating the memory size based on external scripts, applying for continuous memory space, and saving the script structure continuously, using the Burst compiler to generate native code to execute external scripts, realizing continuous memory pool allocation, and improving cache hit rate and memory running speed.
It significantly improves the execution speed of external scripts, reduces the latency probability, improves the user experience, and makes full use of the performance advantages of the DOTS framework.
Smart Images

Figure CN120386589A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of software technology, and particularly to a method, apparatus, device, and medium for executing an external script. Background Art
[0002] In games, to facilitate dynamic adjustment of content and rules, many works support mods (Mods) to allow players to customize and expand. Mods exist in the form of external scripts or resource packs, and the core function is to allow non-professional developers to modify data, combine rules, or create new mechanisms based on the game framework. To achieve this goal, current games need to build a script interpreter to parse external scripts at runtime and convert them into instruction sets or data structures recognizable by the game.
[0003] The DOTS (Data-Oriented Technology Stack) framework is a data-oriented programming framework provided by Unity. It can improve the performance of program operation. However, since the ECS (Entity-Component-System) architecture in the DOTS framework is a data-oriented architecture and the optimizing compiler Burst has limitations on programming languages, its support for scripts is not very perfect. In particular, there are design differences between object-oriented external scripts and the data-oriented programming method of DOTS. Generally, scripts can only run independently in an object-oriented environment, thus being isolated from the DOTS framework.
[0004] Currently, in the prior art, because scripts and the high-speed DOTS framework run in different environments, their data interaction is relatively difficult, increasing memory occupancy. External scripts cannot utilize the performance advantages of DOTS, resulting in latency in the process of calling external scripts, and further causing poor conditions such as game screen stuttering and long loading times, which affect the user experience. Summary of the Invention
[0005] To solve the problems in the related art, embodiments of the present disclosure provide a method, apparatus, device, and medium for executing an external script.
[0006] In a first aspect, embodiments of the present disclosure provide a method for executing an external script, including: Obtaining one or more instances of script classes based on an external script; Determining the memory size occupied by the script structure corresponding to the instance of the script class according to the memory size occupied by the preset structure corresponding to the script class; Calculating the total memory size occupied by the script structures corresponding to the instances of the one or more script classes according to the memory sizes occupied by the script structures corresponding to the respective instances of the one or more script classes; Allocate memory space according to the calculated total memory size; Save the script structures corresponding to the instances of the one or more script classes in the memory space; Execute the external script by reading the script structure from the memory space.
[0007] According to an embodiment of the present disclosure, obtaining instances of one or more script classes based on an external script includes: Parse the external script to obtain a scope; Convert the scope into the instances of the one or more script classes.
[0008] According to an embodiment of the present disclosure, the scope includes at least one of the following: a scope, key-value pairs, lexical units; The script class includes any one of the following: key-value pairs, conditional judgmentors.
[0009] According to an embodiment of the present disclosure, the memory space is continuous; The saving the script structures corresponding to the instances of the one or more script classes in the memory space includes saving the script structures corresponding to the instances of the one or more script classes continuously in the memory space.
[0010] According to an embodiment of the present disclosure, the preset script structure corresponding to the script class includes: value type data of the script class; and / or a pointer to reference type data of the script class.
[0011] According to an embodiment of the present disclosure, when any instance contains a reference to another instance, a memory pointer of the other instance is stored in the script structure corresponding to the instance.
[0012] According to an embodiment of the present disclosure, the saving the script structures corresponding to the instances of the one or more script classes in the memory space includes: Obtain the memory address of the script structure corresponding to the second instance referenced by the first instance; Assign a value to the memory pointer in the structure of the first instance according to the memory address of the script structure corresponding to the second instance.
[0013] According to an embodiment of the present disclosure, the executing the external script by reading the script structure from the memory space includes: Generate native code based on the script structure by a compiler; Execute the native code to execute the external script.
[0014] In a second aspect, an apparatus for executing an external script provided in an embodiment of the present disclosure includes: A script parsing module, configured to obtain instances of one or more script classes based on an external script; A memory preset module, configured to determine the memory size occupied by the script structure corresponding to the instance of the script class according to the memory size occupied by the preset structure corresponding to the script class; A memory calculation module, configured to calculate the total memory size occupied by the script structures corresponding to the instances of the one or more script classes according to the memory sizes occupied by the script structures corresponding to the instances of the one or more script classes; A memory pool management module, configured to apply for a memory space according to the calculated total memory size; A script structure management module, configured to store the script structures corresponding to the instances of the one or more script classes in the memory space; A script task execution module, configured to execute the external script by reading the script structure from the memory space.
[0015] According to an embodiment of the present disclosure, obtaining the instances of the one or more script classes based on the external script includes: Parsing the external script to obtain a scope; Converting the scope into the instances of the one or more script classes.
[0016] According to an embodiment of the present disclosure, the scope includes at least one of the following: a scope, key-value pairs, lexical units; The script class includes any one of the following: key-value pairs, a conditional judgment device.
[0017] According to an embodiment of the present disclosure, the memory space is continuous; Storing the script structures corresponding to the instances of the one or more script classes in the memory space includes continuously storing the script structures corresponding to the instances of the one or more script classes in the memory space.
[0018] According to an embodiment of the present disclosure, the preset script structure corresponding to the script class includes: value type data of the script class; and / or a pointer to reference type data of the script class.
[0019] According to an embodiment of the present disclosure, when any instance contains a reference to another instance, a memory pointer of the other instance is stored in the script structure corresponding to the instance.
[0020] According to an embodiment of the present disclosure, storing the script structures corresponding to the instances of the one or more script classes in the memory space includes: Obtain the memory address of the script structure corresponding to the second instance referenced by the first instance; Assign a memory pointer in the structure of the first instance according to the memory address of the script structure corresponding to the second instance.
[0021] According to an embodiment of the present disclosure, the executing the external script by reading the script structure from the memory space includes: Generate native code based on the script structure by a compiler; Execute the native code to execute the external script.
[0022] In a third aspect, an embodiment of the present disclosure provides an electronic device, including a memory and a processor, wherein the memory is used to store one or more computer instructions, and the one or more computer instructions are executed by the processor to implement the method described in any one of the first aspects.
[0023] In a fourth aspect, an embodiment of the present disclosure provides a computer-readable storage medium, on which computer instructions are stored, and when the computer instructions are executed by a processor, the method described in any one of the first aspects is implemented.
[0024] According to the technical solution provided by the embodiment of the present disclosure, obtain one or more instances of script classes based on an external script; determine the memory size occupied by the script structure corresponding to the instance of the script class according to the memory size occupied by the preset structure corresponding to the script class; calculate the total memory size occupied by the script structures corresponding to the instances of the one or more script classes according to the memory sizes occupied by the script structures corresponding to the instances of the one or more script classes; apply for a memory space according to the calculated total memory size; save the script structures corresponding to the instances of the one or more script classes in the memory space; execute the external script by reading the script structure from the memory space. The present disclosure changes the original random memory pool allocation to a continuous memory pool allocation through the script structure, greatly improving the computer cache hit rate, effectively improving the memory operation speed, thereby improving the efficiency of converting script logic into highly optimized native code, that is, improving the efficiency of executing the script in the external script. Therefore, when the above solution is applied in the DOTS framework, the execution speed of the program calling the external script can be greatly improved, and the probability of delay caused by calling the external script can be reduced, thereby significantly improving the user experience.
[0025] It should be understood that the above general description and the following detailed description are only exemplary and explanatory, and cannot limit the present disclosure. Description of the Drawings
[0026] In conjunction with the accompanying drawings, through the following detailed description of non-limiting embodiments, other features, objectives, and advantages of the present disclosure will become more apparent. In the drawings: Figure 1 The flowchart showing the external script calling method according to an embodiment of the present disclosure is presented.
[0027] Figure 2 The schematic diagram showing the external script calling method according to an embodiment of the present disclosure Figure 3 The structural block diagram showing the external script calling device according to an embodiment of the present disclosure is presented.
[0028] Figure 4 The structural block diagram showing the electronic device according to an embodiment of the present disclosure is presented.
[0029] Figure 5 The structural schematic diagram showing the computer system suitable for implementing the method according to an embodiment of the present disclosure is presented. Detailed Embodiments
[0030] Hereinafter, exemplary embodiments of the present disclosure will be described in detail with reference to the accompanying drawings so that those skilled in the art can easily implement them. In addition, for clarity, parts irrelevant to the description of the exemplary embodiments are omitted in the drawings.
[0031] In the present disclosure, it should be understood that terms such as "including" or "having" are intended to indicate the existence of the features, numbers, steps, actions, components, parts, or combinations thereof disclosed in this specification, and are not intended to exclude the possibility of the existence or addition of one or more other features, numbers, steps, actions, components, parts, or combinations thereof.
[0032] In addition, it should be noted that, without conflict, the embodiments and features in the embodiments of the present disclosure can be combined with each other. The present disclosure will be described in detail below with reference to the drawings and in conjunction with the embodiments.
[0033] As mentioned above, in current existing game works, to facilitate the dynamic adjustment of content and rules, many works allow players to customize and expand by supporting custom mods. Mods exist in the form of external scripts or resource packs, and their core function is to allow non-professional developers to modify data, combine rules, or create new mechanisms based on the game framework.
[0034] To achieve this goal, the game needs to have a built-in script interpretation framework, which covers three major technical aspects: First, define a standardized script interface and API function library to clarify the logical access points that can be called by the module (such as event triggering, data reading and writing); Second, the script interpreter parses the external script at runtime and converts it into an instruction set or data structure recognizable by the game. For example, the instruction "add a weapon" is disassembled into operation steps such as resource loading and attribute binding; Finally, the sandbox isolation mechanism is used to restrict the access rights of the module to the core code to avoid crashes caused by logical conflicts.
[0035] Traditional script interpreters are usually based on single-threaded logic (such as MonoBehaviours) and cannot fully utilize the computing power of multi-core CPUs, resulting in complex logics (such as physical simulation, AI decision-making, etc.) becoming performance bottlenecks. DOTS is a high-performance programming paradigm, whose core goal is to break through the performance bottlenecks of traditional object-oriented programming (OOP) through data-oriented design, multi-threaded parallel computing, and efficient memory management, and significantly improve the running efficiency of the game. Currently, because the script and the high-speed DOTS framework run in different environments, their data interaction is relatively difficult. The external script cannot utilize the performance advantages of DOTS, and the data structures are stored in memory randomly, increasing the memory occupancy and reducing the cache hit rate, resulting in latency during the call process of the external script, and then causing poor conditions such as game screen stuttering and long loading times, which affect the user experience.
[0036] To solve the above problems, the present disclosure provides a method, device, and equipment for executing external scripts, which can be compatible with the DOTS framework, so as to fully utilize the performance advantages of the DOTS framework and achieve high-speed execution of external scripts. The solutions of the embodiments of the present disclosure are not only applicable to game scenarios, but also applicable to the call of external scripts in other software scenarios. For the sake of easy understanding, the embodiments of the present disclosure will be mainly described for game scenarios below.
[0037] Figure 1 The flowchart of the external script call method according to an embodiment of the present disclosure is shown. As Figure 1 shown, the external script call method includes the following steps S101 - S106: In step S101, one or more instances of script classes are obtained based on the external script; In step S102, according to the memory size occupied by the preset structure corresponding to the script class, the memory size occupied by the script structure corresponding to the instance of the script class is determined; In step S103, according to the memory sizes occupied by the script structures corresponding to the instances of the one or more script classes, the total memory size occupied by the script structures corresponding to the instances of the one or more script classes is calculated; In step S104, memory space is allocated according to the calculated total memory size; In step S105, the script structures corresponding to the instances of the one or more script classes are stored in the memory space; In step S106, the external script is executed by reading the script structure from the memory space.
[0038] According to an embodiment of the present disclosure, the external script is written according to a preset writing specification.
[0039] Exemplarily, taking the external json - structured script in a game with the DOTS architecture as an example, the writing specification may include: defining keywords and values through key - value pairs (Binding), where the value can be a single lexical unit (Token) or a scope enclosed by curly braces {}, and this scope can contain other key - value pairs. According to an embodiment of the present disclosure, multiple lexical units rather than key - value pairs can also be enclosed by curly braces {} to represent intervals, arrays, etc. Scopes, key - value pairs, and lexical units can be collectively referred to as constructs.
[0040] According to an embodiment of the present disclosure, in step S101, obtaining instances of one or more script classes based on the external script may include: parsing the external script to obtain a scope; converting the scope into the instances of the one or more script classes.
[0041] According to an embodiment of the present disclosure, the external script is parsed into a scope, which nests other constructs inside.
[0042] After obtaining the scope, the scope is converted into an instance of a script class. The script class may include any one of the following: key - value pairs, conditional judgmentors.
[0043] The following takes the external Trigger (conditional judgmentor) script with a json structure in a game with the DOTS architecture as an example for illustration. The Trigger script is used to judge whether a condition holds and can include multiple types. For example: 1. Ordinary trigger: trigger name = parameter Such as is_male = true / / Judge as male The parameter can be a complex parameter, Such as has_opinion_modifier = { target = xx type = modifier_type } / / Judge having a specific favorability modification type for a certain character 2. Numeric comparison trigger: trigger name >>= =<=< parameter Such as age >= 16 3. Switch the current object and then make a judgment Such as father = { is_alive = true } / / Determine whether the father is still alive 4. Traverse the list trigger, and compare the number and value of the objects that meet the conditions in the list Such as every_child = { is_adult = true Is_married = false count>1 } / / Determine that the number of adult and unmarried children is greater than 1 5. Logical trigger, determine whether multiple composite conditions meet a certain logical relationship Such as NOR = { is_adult = true Is_married = false } / / Determine that being adult and being unmarried cannot hold simultaneously When parsing the Trigger script, the key in a key-value pair is parsed as a condition keyword, and the value is parsed as a condition parameter. For example, is_male = false, where is_male is the condition keyword and false is the condition parameter. This script determines that the current character is not male. Conditions can be defined nested. For example, NOR = { is_male = false is_adult =true} means that the two conditions of not being male and being an adult cannot be satisfied simultaneously. Therefore, a Trigger can also contain sub-Triggers, and determine whether the current Trigger is true based on the results of the sub-Triggers. A base class TriggerBase can be designed, and the above various types of Triggers are all subclasses of TriggerBase. When converting to an instance of the script class, determine which subclass instance the parsed Construct should be further converted to based on the parsed condition keyword.
[0044] Specifically, each of the above types of Triggers can be respectively converted into the following script classes: SingleTrigger, ValueCompareTrigger, ContextChangeTrigger, ListTrigger, LogicTrigger. From the script structure, it can be seen that ContextChangeTrigger, ListTrigger, and LogicTrigger contain multiple TriggerBases as sub-conditions.
[0045] In step S102, according to the memory size occupied by the preset structure corresponding to the script class, determine the memory size occupied by the script structure corresponding to the instance of the script class.
[0046] According to an embodiment of the present disclosure, each script class may have a corresponding preset structure, and the preset structure has a plurality of preset fields and occupies a preset memory space. According to an embodiment of the present disclosure, the preset structure corresponding to the script class includes: the value type data of the script class; and / or a pointer to the reference type data of the script class.
[0047] By setting a preset script structure for each script class, after parsing and converting the external script to obtain an instance of the script class, the total memory size occupied by the script structure corresponding to the instance obtained by converting the external script can be quickly calculated according to the number of instances of each script class and the memory size occupied by the preset structures respectively corresponding to each script class.
[0048] In the above example of the external Trigger script, design the corresponding script structure according to the structure of each subclass. For example: The SingleTrigger class inherits from TriggerBase and contains triggerName (trigger name) and argument (parameter). The preset structure SingleTriggerStruct corresponding to the SingleTrigger class contains three fields: triggerBaseStruct, triggerName, and argument. Among them, the class recognition information (for example, enumeration) used to distinguish the current trigger type is stored in triggerBaseStruct; triggerName is used to store the trigger name; argument is used to store the parameter of the trigger.
[0049] According to an embodiment of the present disclosure, when any instance contains a reference to another instance, a memory pointer of the other instance is stored in the script structure corresponding to the instance. Since the memory space required to store the memory pointer is determined, storing the memory pointer of the script structure of the referenced instance in the structure instead of directly storing the referenced instance can achieve references to various different instances while ensuring that the memory space occupied by the script structure remains unchanged.
[0050] In step S103, according to the memory sizes occupied by the script structures corresponding to the instances of the one or more script classes, calculate the total memory size occupied by the script structures corresponding to the instances of the one or more script classes.
[0051] Exemplarily, assume that the preset structure of script class A occupies X bytes, the preset structure of script class B occupies Y bytes, 3 instances of script class A and 2 instances of script class B are obtained by converting the external script. Then, the script structures corresponding to the instances obtained by converting the external script altogether occupy 3X + 2Y bytes.
[0052] In step S104, apply for a memory space according to the calculated total memory size.
[0053] In the above example, the calculated total memory size is 3X + 2Y bytes. Therefore, apply for a memory space with a size of 3X + 2Y bytes. According to an embodiment of the present disclosure, this memory space can be a continuous memory space.
[0054] In step S105, save the script structures corresponding to the instances of the one or more script classes in the memory space.
[0055] According to an embodiment of the present disclosure, the script structures corresponding to the instances of the one or more script classes can be continuously saved in the memory space. After saving the script structures, the memory address of the script structure of the referenced instance can be obtained and assigned to the script structure of the instance acting as the reference party.
[0056] Taking two instances M (referred to as the first instance) and instance N (referred to as the second instance) with a reference relationship as an example, assume that the first instance references the second instance. Then, the memory address of the script structure of the second instance can be obtained and assigned to the memory pointer in the structure of the first instance for saving the script structure of the referenced instance.
[0057] According to an embodiment of the present disclosure, the structure can be memory-aligned, thereby effectively reducing the occupation of memory space. And after memory alignment, access to the data in the structure can be completed through a single memory access. Embodiments of the present disclosure are directed to large-scale numerical computing scenarios, and change the random memory pool allocation method in the prior art to a continuous memory pool allocation through a script structure. The continuously stored structure will trigger memory locality preloading when loaded, greatly improving the computer cache hit rate and effectively increasing the memory operation speed. Therefore, this solution can effectively reduce the occupation of memory space, while improving the cache hit rate and enhancing the data access efficiency.
[0058] In step S106, the external script is executed by reading the script structure from the memory space.
[0059] According to an embodiment of the present disclosure, the executing the external script by reading the script structure from the memory space includes: generating a task structure including a task interface or a parallel loop task interface according to the external script logic; creating a script structure array and a result array according to the script structure and the task structure; compiling the script structure array and the result array into external script native array code by a compiler; scheduling and running the external script native array code to execute the external script.
[0060] Exemplarily, a structure implementing the IJob or IJobParallelFor interface can be generated according to the external script logic, and the external script structure array and the result array are wrapped as a NativeArray (external script native array code compatible with the Burst compiler); then the Burst Job is scheduled in the main thread to execute the external script.
[0061] Figure 2 Shows a specific example of converting an external script into a script structure.
[0062] As Figure 2 shown, the external script text is: trigger = { NOR = { is_male = false age>16 } } This script describes a composite judgment condition, requiring that the two conditions of not being male and being older than 16 cannot hold simultaneously.
[0063] Two scopes, Scope_1 and Scope_2, are obtained by parsing an external script. Among them, Scope_1 contains Scope_2 which describes a composite condition, and Scope_2 contains Bindings of two simple conditions.
[0064] Three instances, Trigger_1, Trigger_2, and Trigger_3, are obtained by converting the scopes. In an object-oriented framework, these three instances are randomly stored, and Trigger_1 holds references to Trigger_2 and Trigger_3.
[0065] Determine the memory size occupied by the corresponding preset structure according to the script classes to which Trigger_1, Trigger_2, and Trigger_3 belong respectively, calculate the total memory occupied by the script structures corresponding to these three instances, and apply for a whole block of memory space.
[0066] Generate the script structures corresponding to Trigger_1, Trigger_2, and Trigger_3 respectively and store them continuously in the memory space. Since Trigger_1 references Trigger_2 and Trigger_3, the memory pointers of the script structures of Trigger_2 and Trigger_3 are saved in the script structure of Trigger_1.
[0067] The reason why the data-oriented architecture of DOTS has high performance is the way it is designed for the CPU cache, storing data that may be used simultaneously in consecutive positions in memory, thus greatly improving the CPU cache hit rate. However, the object-oriented implementation usually saves data through pointers or references, and the positions of the data itself in memory are random. At the same time, the Burst compiler restricts most types in C# to only value types and pointers.
[0068] Therefore, in order to make good use of the advantages of DOTS, the embodiments of the present disclosure store the structures obtained by script conversion in continuous memory, so that when executing, reading and writing the content of the script has a high cache hit rate like DOTS, and at the same time, it can also support Burst compilation.
[0069] To parse a user-defined scripting language (rather than a general-purpose language such as lua), a script parser needs to be designed. Designing a script parser in the DOTS framework is a very difficult task. Therefore, the embodiments of the present disclosure do not directly parse the script into a script structure, but first parse it into instances of various script classes in an object-oriented manner, and then convert the instances into script structures. In other words, the script structure becomes a middleware connecting the object-oriented script and the DOTS framework.
[0070] According to an embodiment of the present disclosure, the Burst compiler can compile programming language code into more efficient machine code. It can generate corresponding native code for different platform types and perform optimizations at the underlying level of the code during compilation, such as vectorization, inlining optimization, instruction scheduling, etc. In the embodiment of the present disclosure, during the execution of the external script, the Burst compiler is used to optimize and accelerate the native array code segment of the external script containing complex operations, thereby obtaining better performance than using other compilers to optimize and accelerate such code segments, so as to improve the execution speed when the program calls the external script.
[0071] Figure 3 FIG. shows a structural block diagram of an external script calling device according to an embodiment of the present disclosure. Among them, the device can be implemented as part or all of an electronic device through software, hardware, or a combination of both.
[0072] As Figure 3 shown, the external script calling device 200 includes: A script parsing module 201, configured to obtain instances of one or more script classes based on the external script; A memory preset module 202, configured to determine the memory size occupied by the script structure corresponding to the instance of the script class according to the memory size occupied by the preset structure corresponding to the script class; A memory calculation module 203, configured to calculate the total memory size occupied by the script structures corresponding to the instances of the one or more script classes according to the memory sizes occupied by the script structures corresponding to the instances of the one or more script classes; A memory pool management module 204, configured to apply for a memory space according to the calculated total memory size; A script structure management module 205, configured to save the script structures corresponding to the instances of the one or more script classes in the memory space; A script task execution module 206, configured to execute the external script by reading the script structure from the memory space.
[0073] According to an embodiment of the present disclosure, the obtaining of instances of one or more script classes based on the external script includes: Parsing the external script to obtain a scope; Converting the scope into the instances of the one or more script classes.
[0074] According to an embodiment of the present disclosure, the scope includes at least one of the following: scope, key-value pair, lexical unit; The script class includes any one of the following: key-value pair, conditional judge.
[0075] According to an embodiment of the present disclosure, the memory space is continuous; Saving the script structures corresponding to the instances of the one or more script classes in the memory space includes saving the script structures corresponding to the instances of the one or more script classes continuously in the memory space.
[0076] According to an embodiment of the present disclosure, the preset script structure corresponding to the script class includes: the value type data of the script class; and / or a pointer to the reference type data of the script class.
[0077] According to an embodiment of the present disclosure, when any instance contains a reference to another instance, the memory pointer of the other instance is stored in the script structure corresponding to the instance.
[0078] According to an embodiment of the present disclosure, saving the script structures corresponding to the instances of the one or more script classes in the memory space includes: Obtaining the memory address of the script structure corresponding to a second instance referenced by a first instance; Assigning a value to the memory pointer in the structure of the first instance according to the memory address of the script structure corresponding to the second instance.
[0079] According to an embodiment of the present disclosure, executing the external script by reading the script structure from the memory space includes: Generating native code based on the script structure by a compiler; Executing the native code to execute the external script.
[0080] The present disclosure also discloses an electronic device, Figure 4 Showing a structural block diagram of an electronic device according to an embodiment of the present disclosure.
[0081] As Figure 4 shown, the electronic device includes a memory and a processor, wherein the memory is used to store one or more computer instructions, and wherein the one or more computer instructions are executed by the processor to implement the method according to an embodiment of the present disclosure.
[0082] Figure 5 Showing a structural schematic diagram of a computer system suitable for implementing the method according to an embodiment of the present disclosure.
[0083] As Figure 5As shown, the computer system includes a processing unit that can execute various methods in the above embodiments according to a program stored in a read-only memory (ROM) or a program loaded from a storage section into a random access memory (RAM). In the RAM, various programs and data required for the operation of the computer system are also stored. The processing unit, ROM, and RAM are connected to each other via a bus. An input / output (I / O) interface is also connected to the bus.
[0084] The following components are connected to the I / O interface: an input section including a keyboard, a mouse, etc.; an output section including a cathode ray tube (CRT), a liquid crystal display (LCD), etc. and a speaker, etc.; a storage section including a hard disk, etc.; and a communication section including a network interface card such as a LAN card, a modem, etc. The communication section performs a communication process via a network such as the Internet. A drive is also connected to the I / O interface as needed. A removable medium, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive as needed so that a computer program read from it can be installed into the storage section as needed. Among them, the processing unit can be implemented as a processing unit such as a CPU, a GPU, a TPU, an FPGA, an NPU, etc.
[0085] In particular, according to an embodiment of the present disclosure, the method described above can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product that includes a computer program tangibly embodied on a machine-readable medium, the computer program including program code for performing the above method. In such an embodiment, the computer program can be downloaded and installed from a network through the communication section, and / or installed from a removable medium.
[0086] The flowcharts and block diagrams in the accompanying drawings illustrate the possible architectures, functions, and operations of systems, methods, and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagram may represent a module, a program segment, or a part of code that contains one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks may occur in a different order than marked in the accompanying drawings. For example, two consecutive blocks shown may actually be executed substantially in parallel, and they may sometimes be executed in the reverse order, depending on the functions involved. It should also be noted that each block in the block diagram and / or flowchart, and combinations of blocks in the block diagram and / or flowchart, can be implemented by a dedicated hardware-based system that performs the specified functions or operations, or can be implemented by a combination of dedicated hardware and computer instructions.
[0087] The units or modules involved in the embodiments described in the present disclosure can be implemented in software or in programmable hardware. The described units or modules can also be provided in a processor, and the names of these units or modules do not, in some cases, constitute a limitation on the units or modules themselves.
[0088] As another aspect, the present disclosure also provides a computer-readable storage medium, which can be the computer-readable storage medium included in the electronic device or computer system in the above embodiments; or can exist separately and be a computer-readable storage medium not assembled into the device. The computer-readable storage medium stores one or more programs, and the one or more programs are used by one or more processors to execute the methods described in the present disclosure.
[0089] The above description is only a preferred embodiment of the present disclosure and an explanation of the technical principles applied. Those skilled in the art should understand that the scope of the invention involved in the present disclosure is not limited to the technical solutions formed by the specific combination of the above technical features, and should also cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the inventive concept. For example, the technical solutions formed by mutually replacing the above features with the technical features (but not limited to) having similar functions disclosed in the present disclosure.
Claims
1. A method for executing an external script, characterized in that, including: obtaining instances of one or more script classes based on an external script; determining the memory size occupied by the script structure corresponding to the instance of the script class according to the memory size occupied by the preset structure corresponding to the script class; calculating the total memory size occupied by the script structures corresponding to the instances of the one or more script classes according to the memory sizes occupied by the script structures corresponding to the respective instances of the one or more script classes; applying for a memory space according to the calculated total memory size; storing the script structures corresponding to the respective instances of the one or more script classes in the memory space; executing the external script by reading the script structure from the memory space.
2. The method for executing an external script according to claim 1, wherein The obtaining instances of one or more script classes based on an external script includes: parsing the external script to obtain a scope; converting the scope into the instances of the one or more script classes.
3. The method for executing an external script according to claim 2, wherein: the scope includes at least one of the following: scope, key-value pair, lexical unit; the script class includes any one of the following: key-value pair, conditional judge.
4. The method for executing an external script according to claim 1, wherein: the memory space is continuous; the storing the script structures corresponding to the respective instances of the one or more script classes in the memory space includes continuously storing the script structures corresponding to the respective instances of the one or more script classes in the memory space.
5. The method for executing an external script according to claim 1, wherein The preset script structure corresponding to the script class includes: value type data of the script class; and / or a pointer to reference type data of the script class.
6. The method for executing an external script according to claim 1, wherein When any instance contains a reference to another instance, the memory pointer of the other instance is stored in the script structure corresponding to the instance.
7. The method for executing an external script according to claim 6, wherein The storing the script structures corresponding to the respective instances of the one or more script classes in the memory space includes: obtaining the memory address of the script structure corresponding to the second instance referenced by the first instance; assigning a value to the memory pointer in the structure of the first instance according to the memory address of the script structure corresponding to the second instance.
8. The method for executing an external script according to claim 1, characterized in that, The executing the external script by reading the script structure from the memory space includes: generating native code based on the script structure by a compiler; executing the native code to execute the external script.
9. An apparatus for executing an external script, characterized in that, including: a script parsing module configured to obtain instances of one or more script classes based on an external script; a memory preset module configured to determine the memory size occupied by the script structure corresponding to the instance of the script class according to the memory size occupied by the preset structure corresponding to the script class; a memory calculation module configured to calculate the total memory size occupied by the script structures corresponding to the instances of the one or more script classes according to the memory sizes occupied by the script structures corresponding to the respective instances of the one or more script classes; a memory pool management module configured to apply for a memory space according to the calculated total memory size; a script structure management module configured to store the script structures corresponding to the respective instances of the one or more script classes in the memory space; The script task execution module is configured to execute the external script by reading the script structure from the memory space.
10. An electronic device, characterized in that, It includes a memory and a processor; wherein, the memory is used to store one or more computer instructions, and the one or more computer instructions are executed by the processor to implement the method according to any one of claims 1-8.
11. A computer-readable storage medium having computer instructions stored thereon, characterized in that, When the computer instructions are executed by the processor, the method according to any one of claims 1-8 is implemented.
Citation Information
Patent Citations
Method and device for uploading resource files by game engine, and computer
CN102799456A
Script code execution method and device, storage medium and equipment
CN114489859A
Virtual article display method and device, storage medium and electronic equipment
CN116051230A
Script data processing method and device based on game system, equipment and medium
CN116521181A
Vehicle digital twin instance simulation operation system and method
CN117390854A