WO2018227942A1 - 一种基于内存优化的任务执行方法及系统 - Google Patents
一种基于内存优化的任务执行方法及系统 Download PDFInfo
- Publication number
- WO2018227942A1 WO2018227942A1 PCT/CN2017/120186 CN2017120186W WO2018227942A1 WO 2018227942 A1 WO2018227942 A1 WO 2018227942A1 CN 2017120186 W CN2017120186 W CN 2017120186W WO 2018227942 A1 WO2018227942 A1 WO 2018227942A1
- Authority
- WO
- WIPO (PCT)
- Prior art keywords
- task
- tasks
- operation result
- executed
- bit
- Prior art date
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/50—Allocation of resources, e.g. of the central processing unit [CPU]
- G06F9/5005—Allocation of resources, e.g. of the central processing unit [CPU] to service a request
- G06F9/5011—Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals
- G06F9/5016—Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals the resource being the memory
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/48—Program initiating; Program switching, e.g. by interrupt
- G06F9/4806—Task transfer initiation or dispatching
- G06F9/4843—Task transfer initiation or dispatching by program, e.g. task dispatcher, supervisor, operating system
- G06F9/485—Task life-cycle, e.g. stopping, restarting, resuming execution
Definitions
- the invention provides a memory optimization method and, more specifically, to a memory optimization based task execution method and system.
- the overhead of a variable in memory is not very large, but as the number of variables increases, the memory overhead will become larger and larger. When the number of variables is too large, the memory usage will be too large.
- the present invention provides a memory optimization-based task execution method and system that overcomes the above problems or at least partially solves the above problems, and can solve the problem of excessive memory overhead.
- a memory optimization based task execution method comprising:
- the invention has the beneficial effects that only a plurality of binary numbers can be used to distinguish multiple tasks, and the binary numbers corresponding to each task are independent, and the execution of multiple tasks can be determined at the same time, one for each additional one. Tasks, only need to add a bit of binary, compared to the existing use of int type data to store each task, reducing the memory overhead.
- the present invention can also be improved as follows.
- step S2 further includes:
- the binary numbers corresponding to the m types of tasks are bitwise ORed to obtain or operate the result, and each bit of the OR operation result is operated and operated according to the operation result, corresponding to the operation result judgment. Whether the task needs to be executed.
- each bit of the or operation result is performed and operated, and determining whether the corresponding task needs to be performed according to the operation result further includes:
- the task is a function call or a conditional statement.
- step S1 further includes:
- each function corresponds to one bit of a binary number
- the step S2 further includes:
- the binary number corresponding to the m kinds of functions is bitwise and the logical operator is operated and parsed to determine whether the corresponding function needs to be called. When the call is needed, the corresponding function is called.
- step S1 further includes:
- conditional statements For m conditional statements, the m-bit binary number is designed to be represented, and each conditional statement corresponds to one of the binary numbers;
- the step S2 further includes:
- the binary number corresponding to the m conditional statements is subjected to logical operation and analysis by bit, and it is determined whether the corresponding conditional statement needs to be executed. If it is necessary to execute, the corresponding conditional statement is executed.
- the service logic execution process is performed in a terminal, where the terminal is a PC or a mobile terminal, and an operating system of the terminal is an IOS or an Android operating system.
- a memory optimization based task execution system comprising:
- the design module is configured to represent m different types of tasks in the execution process of the business logic, and design a binary number of m bits to represent that one of the binary numbers of each type of task is a positive integer;
- the operation parsing module is configured to perform logical operation and parsing of the logical operators corresponding to the incoming m types of tasks by bits, determine the tasks to be executed, and execute the tasks.
- the operation parsing module includes:
- a first operation parsing unit configured to perform a AND operation on a binary number corresponding to the task of the type and a bitwise operation when m is 1, and determine whether the task of the type needs to be executed according to the operation result;
- a second operation parsing unit configured to perform bit operations or operations on the binary numbers corresponding to the m types of tasks when m ⁇ 2, obtain or operate the result, and perform each operation of the OR operation result with the 1 According to whether the task corresponding to the operation result needs to be executed.
- the task is a function call or a conditional statement.
- an electronic device including a processor, a memory, and a bus is provided;
- the processor and the memory complete communication with each other through the bus;
- the memory stores program instructions executable by the processor, the processor invoking the program instructions to perform the following methods:
- a binary number of m bits is designed to represent that each type of task corresponds to one of the binary numbers, where m is a positive integer;
- the binary numbers corresponding to the tasks of the m types are logically operated and parsed by bits, and the tasks to be executed are determined, and the task is executed.
- FIG. 1 is a flowchart of a memory optimization-based task execution method according to an embodiment of the present invention
- FIG. 2 is a block diagram of a memory execution-based task execution system connection according to another embodiment of the present invention.
- FIG. 3 is a block diagram showing the internal connection of a computing analysis module according to still another embodiment of the present invention.
- FIG. 4 is a block diagram showing the connection of an electronic device according to an embodiment of the present invention.
- a memory optimization-based task execution method including: S1, for designing m different types of tasks in a business logic execution process, designing m-bit binary numbers to represent each The type of task corresponds to a bit in the binary number, where m is a positive integer; S2, the binary number corresponding to the m types of tasks passed in is logically operated and parsed by bit, for the task to be performed Make a decision.
- the conventional method is to define the judgment bit of each task as a common variable, and then Judging this one by one.
- the overhead of a variable in memory is not very large, but as the number of variables increases, the memory overhead will become larger and larger, which will cause excessive memory usage.
- this embodiment proposes a problem of reducing memory overhead.
- m-bit binary numbers are used, and each type of task corresponds to one of the binary numbers.
- Bit where m is a positive integer.
- a business logic implementation involves four different types of tasks, so a 4-bit binary number is designed to represent these four different types of tasks.
- 0001 represents the first type of task
- 0010 represents the second type of task
- 0100 represents the third type of task
- 1000 represents the fourth type of task
- each of the 4 types of tasks occupies one of the 4-bit binary numbers.
- the binary numbers corresponding to the incoming m types of tasks are respectively subjected to logical operator operations and parsing, and the tasks to be performed are determined.
- the one or more tasks are executed.
- the service logic execution process in this embodiment is performed on the terminal, where the terminal may be a PC or a mobile terminal, and the operating system used by the terminal may be an Apple IOS system or an Android operating system.
- the present embodiment is directed to the defects of the prior art, and only needs to use multiple binary numbers to distinguish multiple tasks, and the binary numbers corresponding to each task are independent, and the execution of multiple tasks can be determined at the same time. For each additional task, only one bit of binary is needed. Compared with the existing data of int type to store each task, the memory overhead is reduced.
- the step S2 further includes: when m is 1, performing binary operations on the binary number corresponding to the tasks of the type and performing a bitwise operation, and determining the tasks of the type according to the operation result. Whether it needs to be implemented.
- m the binary numbers corresponding to the m types of tasks are bitwise ORed to obtain or operate the result, and each bit of the OR operation result is operated and operated according to the operation result, corresponding to the operation result judgment. Whether the task needs to be executed.
- the binary number corresponding to the task of the type is operated and operated in a bitwise manner, and it is determined according to the operation result whether the task of the type needs to be executed. . For example, if the binary number corresponding to the type of task is 1, the binary number 1 and 1 are operated and the obtained operation result is 1, and it is determined that the task of the type needs to be executed. If the operation result is 0, the determination is performed. This type of task does not need to be performed.
- the binary numbers corresponding to the respective tasks are first ORed to obtain or operate the results. Then, the OR operation result and the operation are performed in accordance with whether the task corresponding to the first bit of the binary number of the operation result determination or the operation result needs to be executed.
- the binary number of the operation result is shifted to the right by one bit, and the binary number after the right shift is performed by 1 and the operation result is determined according to the operation result to determine whether the task corresponding to the second bit needs to be executed.
- the right or the result of the operation is shifted to the right, and then the operation is performed with 1 to determine whether each corresponding task needs to be executed according to the result of the operation, until all the tasks corresponding to the binary bits are determined.
- the binary type corresponding to the first type of task is 0001
- the binary number corresponding to the second type of task is 0010
- the third type The binary number corresponding to the task is 0100
- the binary number corresponding to the fourth type of task is 1000.
- the binary number corresponding to the four types of tasks is passed in, for example, the first type of task corresponds to the incoming binary number of 0001, and the second type of task corresponds to the incoming binary number of 0000
- the third type of task The corresponding binary number is 0100
- the fourth type of task corresponds to the incoming binary number of 1000.
- the four binary numbers are ORed, and the resulting OR operation result is 1101.
- the obtained or operation results 1101 and 0001 are ANDed to obtain 0001, and then the first task is determined to be executed; then the OR operation result 1101 is shifted to the right by one bit to obtain 0110, and then the operation is performed with 0001 to obtain 0000. , then it is determined that the second task does not need to be executed. In the same way, it is determined that the third task and the fourth type of task need to be executed.
- the above task may be a call to a function or a decision of a conditional statement.
- the step S1 further comprises: designing m-bit binary numbers for the m kinds of functions, each function corresponding to one of the binary numbers.
- the step S2 further includes: performing operation and parsing of the logical operator by bitwise corresponding to the binary number corresponding to the m kinds of functions, determining whether the corresponding function needs to be called, and calling the corresponding function when the call is needed.
- the binary numbers corresponding to m functions are bitwise to perform logical operator operations and parsing, to determine whether each function needs to be called, and if necessary, the corresponding function is called.
- the step S1 when the task is a conditional statement, the step S1 further includes: designing m-bit binary numbers for m conditional statements, each conditional statement corresponding to a binary number One of them.
- the step S2 further includes: performing the operation and analysis of the logical operator by the binary number corresponding to the m conditional statements, determining whether the corresponding conditional statement needs to be executed, and if necessary, executing the corresponding conditional statement.
- a binary number can be designed to represent it.
- the m-bit binary number is designed to distinguish all conditional statements, and each conditional statement occupies one bit of the binary number.
- the binary numbers corresponding to the m conditional statements are subjected to logical operator operations and parsing in bits to determine whether each conditional statement is true, and if so, the conditional statement is executed.
- the embodiment of the present invention uses a binary number to define the execution of each task, and can allocate the memory overhead.
- four variables need to be defined, for example, definition.
- 4 int type data each integer data represents a task.
- only four binary digits are needed to be fully represented, and four tasks can be represented by 0001, 0010, 0100, and 1000, respectively, and the determination of each task is independent, one time can be
- the execution of a task is judged, and the execution of multiple tasks can also be judged at the same time.
- This scheme uses a 4-bit binary number to achieve the traditional goal of using four int types of data.
- a memory optimization based task execution system including a design module 21 and an operation parsing module 22.
- the design module 21 is configured to design m-bit binary numbers to represent m different types of tasks in the execution process of the business logic, and each type of task corresponds to one of the binary numbers, wherein m is positive Integer.
- the operation parsing module 22 is configured to perform logical operation and parsing of the logical operators corresponding to the incoming m types of tasks by bits, determine the tasks to be executed, and execute the tasks.
- the operation parsing module 22 further includes a first operation parsing unit 221 and a second operation parsing unit 222.
- the first operation parsing unit 221 is configured to perform the AND operation on the binary number corresponding to the tasks of the type and the 1-bit operation when m is 1, and determine whether the tasks of the type need to be executed according to the operation result.
- the second operation parsing unit 222 is configured to perform bit operations or operations on the binary numbers corresponding to the m types of tasks when m ⁇ 2, to obtain or operate the result, and perform each bit of the OR operation result with 1 The operation determines whether the task corresponding to the operation result needs to be executed.
- the above task may be a function call or a conditional statement.
- the design module 21 is specifically configured to design m-bit binary numbers for m kinds of functions, and each function corresponds to one bit in the binary number.
- the operation analysis module 22 is specifically configured to perform the operation and analysis of the logical operators by bitwise corresponding to the binary numbers of the m kinds of functions, determine whether the corresponding function needs to be called, and call the corresponding function when the call is needed.
- the design module 21 is specifically configured to design m-bit binary numbers for the m conditional statements, and each of the conditional statements corresponds to one of the binary numbers.
- the calculation analysis module 22 is specifically configured to perform logical operation and analysis on the binary numbers corresponding to the m conditional statements, determine whether the corresponding conditional statements need to be executed, and execute the corresponding conditional statements if necessary.
- an electronic device includes a processor 401, a memory 402, and a bus 403.
- the processor 401 and the memory 402 complete communication with each other through the bus 403. .
- the processor 401 is configured to invoke program instructions in the memory 402 to perform the methods provided by the foregoing method embodiments, for example, including: designing m bits for m different types of tasks in the process of executing business logic.
- the binary number indicates that each type of task corresponds to a bit in the binary number, where m is a positive integer; the binary number corresponding to the m types of tasks passed in, the logical operator operation and parsing are performed bit by bit, Achieve the determination of the tasks that need to be performed.
- the invention discloses a computer program product comprising a computer program stored on a non-transitory computer readable storage medium, the computer program comprising program instructions, the computer being capable of executing the corresponding implementation when the program instructions are executed by the computer
- the intelligent filtering control layout method provided by the example includes, for example, designing m-bit binary number representations for each of the m different types of tasks in the execution of the business logic, and each type of task corresponds to one of the binary numbers. Where m is a positive integer; the binary number corresponding to the m types of tasks passed in, the logical operator operation and parsing are performed bitwise, and the task to be performed is determined.
- the present invention also provides a non-transitory computer readable storage medium storing computer instructions for causing a computer to execute the smart layout control method provided by the corresponding embodiment, for example, including Designing a binary number representation of m bits for m different types of tasks in the execution of business logic, each type of task corresponds to one of the binary numbers, where m is a positive integer; The binary number corresponding to the type of task, the logical operator operation and parsing by bit, to determine the task to be performed.
- the foregoing program may be stored in a computer readable storage medium, and the program is executed when executed.
- the foregoing steps include the steps of the foregoing method embodiments; and the foregoing storage medium includes: a medium that can store program codes, such as a ROM, a RAM, a magnetic disk, or an optical disk.
- the invention provides a memory optimization-based task execution method and system, which uses a binary number to distinguish the execution of multiple tasks, and the binary numbers corresponding to each task are independent, and can simultaneously perform multiple tasks.
- the execution of the decision is made. For each additional task, only one bit of binary is needed. Compared with the existing data of int type, each task is stored, and the memory overhead is reduced when the original function is inconvenient.
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Stored Programmes (AREA)
- Devices For Executing Special Programs (AREA)
Abstract
一种基于内存优化的任务执行方法及系统,所述的方法包括:针对业务逻辑执行过程中的m种不同类型的任务,设计m位的二进制数表示,每一种类型的任务对应二进制数中的一位,其中,m为正整数(S1);将传入的m种类型的任务对应的二进制数,按位进行逻辑操作符的运算和解析,对所需要执行的任务进行判定,并执行该任务(S2)。所述方法及系统只需要采用多位二进制数即可对多个任务进行区分,且每个任务对应的二进制数都是独立的,可以同时对多个任务的执行进行判定,每增加一个任务,只需要增加一位二进制,相比现有的使用int类型的数据来存储每一个任务,降低了对内存的开销。
Description
交叉引用
本申请引用于2017年6月15号提交的专利名称为“一种基于内存优化的任务执行方法及系统”的第201710453005.3号中国专利申请,其通过引用被全部并入本申请。
本发明内存优化领域,更具体地,涉及一种基于内存优化的任务执行方法及系统。
在业务逻辑的开发过程中,经常会涉及到各种任务的执行,对于每一个任务是否执行,都需要进行判断,在开发的过程中,常规的做法是将判断位定义成普通的变量,然后对各个变量逐一进行判定。
通常情况下,一个变量在内存中的开销不是很大,但是随着变量数量的增加,内存的开销会越来越大,当变量的数量过多时,会造成对内存占用过大的问题。
发明内容
本发明提供一种克服上述问题或者至少部分地解决上述问题的基于内存优化的任务执行方法及系统,能够解决内存开销过大的问题。
根据本发明的第一方面,提供了一种基于内存优化的任务执行方法,包括:
S1,针对业务逻辑执行过程中的m种不同类型的任务,设计m位的二进制数表示,每一种类型的任务对应二进制数中的一位,其中,m为正整数;
S2,将传入的m种类型的任务对应的二进制数,按位进行逻辑操作符的运算和解析,实现对所需要执行的任务进行判定。
本发明的有益效果为:只需要采用多位二进制数即可对多个任务进行区分,且每个任务对应的二进制数都是独立的,可以同时对多个任务的执行进行判定,每增加一个任务,只需要增加一位二进制,相比现有的使用int类型的数据来存储每一个任务,降低了对内存的开销。
在上述技术方案的基础上,本发明还可以作如下改进。
进一步的,所述步骤S2进一步包括:
当m为1时,将该种类型的任务对应的二进制数和1按位进行与操作,并根据操作结果判定该种类型的任务是否需要执行;
当m≥2时,将m种类型的任务对应的二进制数按位进行或操作,得到或操作结果,将所述或操作结果的每一位和1进行与操作,根据与操作结果判定对应的任务是否需要执行。
进一步的,所述将或操作结果的每一位和1进行与操作,根据与操作结果判定对应的任务是否需要执行进一步包括:
将所述或操作结果和1进行与操作,根据与操作结果判定或操作结果的第一位对应的任务是否需要执行;
将或操作结果右移一位,再次和1进行与操作,根据与操作结果判定或操作结果的第二位对应的任务是否需要执行;
重复执行上述步骤,直到所述或操作结果中的所有二进制位对应的任务均判定完毕。
进一步的,所述任务为函数调用或条件语句判定。
进一步的,当所述任务为函数调用时,所述步骤S1进一步包括:
针对m种函数,设计m位的二进制数进行表示,每一种函数对应二进制数的一位;
所述步骤S2进一步包括:
将m种函数对应的二进制数按位进行逻辑操作符的运算和解析,判定是否需要调用对应的函数,当需要调用时,对相应的函数进行调用。
进一步的,当所述任务为条件语句判定时,所述步骤S1进一步包括:
针对m种条件语句,设计m位的二进制数进行表示,每一种条件语句对应二进制数中的一位;
所述步骤S2进一步包括:
将m种条件语句对应的二进制数按位进行逻辑操作符的运算和解析,判定对应的条件语句是否需要执行,若需要执行,则对相应的条件语句进行执行。
进一步的,所述业务逻辑执行过程在终端中进行,所述终端为PC或移动终端,所述终端的操作系统为IOS或安卓操作系统。
根据本发明的第二方面,提供了一种基于内存优化的任务执行系统,包括:
设计模块,用于针对业务逻辑执行过程中的m种不同类型的任务,设计m位的二进制数来表示,每一种类型的任务对应二进制数中的一位m为正整数;
运算解析模块,用于将传入的m种类型的任务对应的二进制数按位进行逻辑操作符的运算和解析,对所需要执行的任务进行判定,并执行该任务。
进一步的,所述运算解析模块包括:
第一运算解析单元,用于当m为1时,将该种类型的任务对应的二进制数和1按位进行与操作,并根据操作结果判定该种类型的任务是否需要执行;
第二运算解析单元,用于当m≥2时,将m种类型的任务对应的二进制数按位进行或操作,得到或操作结果,将所述或操作结果的每一位和1进行与操作,根据与操作结果判定对应的任务是否需要执行。
进一步的,所述任务为函数调用或条件语句判定。
根据本发明的第三方面,提供了一种电子设备,包括处理器(processor)、存储器(memory)和总线;
所述处理器和存储器通过所述总线完成相互间的通信;
所述存储器存储有可被所述处理器执行的程序指令,所述处理器调用所述程序指令能够执行如下方法:
针对业务逻辑执行过程中的m种不同类型的任务,设计m位的二进制数来表示,每一种类型的任务对应二进制数中的一位,其中,m为正整数;
将传入的m种类型的任务对应的二进制数按位进行逻辑操作符的运算和解析,对所需要执行的任务进行判定,并执行该任务。
图1为本发明一个实施例的基于内存优化的任务执行方法流程图;
图2为本发明另一个实施例的基于内存优化的任务执行系统连接框图;
图3为本发明又一个实施例的运算解析模块的内部连接框图;
图4为本发明一个实施例的电子设备连接框图。
下面结合附图和实施例,对本发明的具体实施方式作进一步详细描述。以下实施例用于说明本发明,但不用来限制本发明的范围。
参见图1,提供了本发明一个实施例的基于内存优化的任务执行方法,包括:S1,针对业务逻辑执行过程中的m种不同类型的任务,设计m位的二进制数来表示,每一种类型的任务对应二进制数中的一位,其中,m为正整数;S2,将传入的m种类型的任务对应的二进制数按位进行逻辑操作符的运算和解析,对所需要执行的任务进行判定。
在终端上进行整个业务逻辑执行的过程中,包括多种不同类型的任务,在对某个任务是否需要执行的判断过程中,传统的方法是将每一个任务的判断位定义成普通变量,然后对此一一进行判断。一个变量在内存中的开销不算很大,但是随着变量数量的增多,内存的开销会越来越大,会造成内存占用过大的问题。
因此,本实施例提出了一种减小内存开销的问题,针对业务逻辑执行过程中的m种不同类型的任务,采用m位二进制数来表示,每一种类型的任务对应二进制数中的一位,其中,m为正整数。比如,一个业务逻辑执行过程中涉及到4种不同类型的任务,因此,设计4位的二进制数来表示这4种不 同类型的任务。例如,采用0001表示第一种类型的任务,0010表示第二种类型的任务,0100表示第三种类型的任务,1000表示第四种类型的任务,4种类型任务中的每一种类型的任务占用4位二进制数中的一位。
在对某种类型的任务判定是否需要执行的过程中,将传入的m种类型的任务分别对应的二进制数按位进行逻辑操作符的运算和解析,对所需要执行的任务进行判定,当判定出需要执行某个或者多个任务时,对这某个或多个任务进行执行。
需要说明的是,本实施例中的业务逻辑执行过程是在终端上进行的,其中,终端可以为PC或移动终端,终端使用的操作系统可以为苹果IOS系统或安卓操作系统。
本实施例针对现有技术的缺陷,只需要采用多位二进制数即可对多个任务进行区分,且每个任务对应的二进制数都是独立的,可以同时对多个任务的执行进行判定,每增加一个任务,只需要增加一位二进制,相比现有的使用int类型的数据来存储每一个任务,降低了对内存的开销。
在本发明的一个实施例中,所述步骤S2进一步包括:当m为1时,将该种类型的任务对应的二进制数和1按位进行与操作,并根据操作结果判定该种类型的任务是否需要执行。当m≥2时,将m种类型的任务对应的二进制数按位进行或操作,得到或操作结果,将所述或操作结果的每一位和1进行与操作,根据与操作结果判定对应的任务是否需要执行。
其中,当业务逻辑执行过程中只涉及一个任务时,即m=1,将该种类型的任务对应的二进制数和1按位进行与操作,并根据操作结果判定该种类型的任务是否需要执行。比如,该种类型任务对应的二进制数为1,则将该二进制数1和1进行与操作,得到的操作结果为1,则判定该种类型的任务需要执行,若操作结果为0,则判定该种类型的任务无需执行。
另一种情况是,当业务逻辑执行过程中涉及到多种类型的任务需要执行时,即m≥2,将传入的m种类型的任务对应的多个二进制数进行或操作,得到或操作结果,则达到了将每一种类型任务在二进制数中的占用位进行了保留。然后,将或操作结果的每一位和1进行与操作,根据每一位和1进行与 操作后的操作结果判定每一种类型的任务是否需要执行。
在本发明的另一个实施例中,所述将或操作结果的每一位和1进行与操作,根据与操作结果判定对应的任务是否需要执行进一步包括:将所述或操作结果和1进行与操作,根据与操作结果判定或操作结果的第一位对应的任务是否需要执行;将或操作结果右移一位,再次和1进行与操作,根据与操作结果判定或操作结果的第二位对应的任务是否需要执行;重复执行上述步骤,直到所述或操作结果中的所有二进制位对应的任务均判定完毕。
当一个业务逻辑执行过程中涉及到多种不同类型的任务时,先将各个任务对应的二进制数进行或操作,得到或操作结果。然后将或操作结果和1进行与操作,根据与操作结果判定或操作结果的二进制数的第一位对应的任务是否需要执行。第一位判定完毕,则将或操作结果的二进制数右移一位,将右移后的二进制数和1再进行与操作,根据与操作结果来判定第二位对应的任务是否需要执行。以此对或操作结果进行右移,再和1进行与操作,根据与操作结果,判定每一位对应的任务是否需要执行,直到所有的二进制位对应的任务均判定完毕。
例如,在一个业务逻辑执行过程中涉及到多种不同类型的任务时,第一种类型的任务对应的二进制数为0001,第二种类型的任务对应的二进制数为0010,第三种类型的任务对应的二进制数为0100,第四种类型的任务对应的二进制数为1000。当传入这4中类型的任务对应的二进制数时,比如,第一种类型任务对应传入的二进制数为0001,第二种类型任务对应传入的二进制数为0000,第三种类型任务对应传入的二进制数为0100,第四种类型任务对应传入的二进制数为1000。将这4个二进制数进行或操作,得到的或操作结果为1101。将得到的或操作结果1101和0001进行与操作,得到0001,则判定第一种任务时需要执行的;随后将或操作结果1101右移一位,得到0110,再与0001进行与操作,得到0000,则判定第二种任务不需要执行。同理,判定第三种任务和第四种类型的任务均需要执行。
在本实施例中,只需要对二进制位进行操作符的运算和解析,即可判定多种任务中的每一种任务是否需要执行,相比现有的使用int类型变量的方 式一一逐个进行判定,判定的效率高,且减小了内存的开销。
在本发明的一个实施例中,上述的任务可以是函数的调用或者条件语句的判定。其中,当所述任务为函数调用时,所述步骤S1进一步包括:针对m种函数,设计m位的二进制数进行表示,每一种函数对应二进制数中的一位。所述步骤S2进一步包括:将m种函数对应的二进制数按位进行逻辑操作符的运算和解析,判定是否需要调用对应的函数,当需要调用时,对相应的函数进行调用。
比如,在一个业务逻辑执行的过程中,需要调用不同的函数,一个函数对应不同的处理逻辑。因此,针对所有的函数,可以设计二进制数来表示。例如,涉及到m个函数,则设计m位的二进制数来区分所有的函数,每一个函数占用二进制数的一个位。在进行判定和解析的过程中,将m个函数对应的二进制数按位进行逻辑操作符的运算和解析,判定是否需要调用每一个函数,若需要调用,则对相应的函数进行调用。
在本发明的另一个实施例中,当所述任务为条件语句判定时,所述步骤S1进一步包括:针对m种条件语句,设计m位的二进制数进行表示,每一种条件语句对应二进制数中的一位。所述步骤S2进一步包括:将m种条件语句对应的二进制数按位进行逻辑操作符的运算和解析,判定对应的条件语句是否需要执行,若需要执行,则对相应的条件语句进行执行。
比如,在一个业务逻辑执行的过程中,涉及到多个条件语句的判断,一个条件语句对应不同的逻辑处理。因此,针对所有的条件语句,可以设计二进制数来表示。例如,涉及到m个条件语句,则设计m位的二进制数来区分所有的条件语句,每一个条件语句占用二进制数的一个位。在进行判定和解析的过程中,将m个条件语句对应的二进制数按位进行逻辑操作符的运算和解析,判断每一个条件语句是否成立,若成立,则执行该条件语句。
本发明实施例使用二进制数对各个任务的执行情况进行定义,能够将第内存的开销,比如,在一个业务逻辑中,有4个任务需要判定,传统的方式需要定义4个变量,例如,定义4个int类型的数据,每一个整型数据表示一个任务。在java内存中,一个int类型的数据会占用64位,也就是说4 个整型数据对内存的开销是64*4=256位的开销。采用本申请的方案,仅仅需要4位二进制数就能够完整表示了,分别用0001、0010、0100和1000就能表示4种任务了,且每一种任务的判定都是独立的,一次可以对一种任务的执行进行判断,也可以同时实现对多种任务的执行进行判断。本方案使用4位二进制数就能够达到传统的使用4个int类型数据所需要达到的目标。采用本申请方案对内存的开销降低了4/256=98%,实现了对内存的开销大幅度的降低。
参见图2,提供了本发明另一个实施例的基于内存优化的任务执行系统,包括设计模块21和运算解析模块22。其中,设计模块21,用于针对业务逻辑执行过程中的m种不同类型的任务,设计m位的二进制数来表示,每一种类型的任务对应二进制数中的一位,其中,m为正整数。
运算解析模块22,用于将传入的m种类型的任务对应的二进制数按位进行逻辑操作符的运算和解析,对所需要执行的任务进行判定,并执行该任务。
参见图3,运算解析模块22进一步包括第一运算解析单元221和第二运算解析单元222。其中,第一运算解析单元221,用于当m为1时,将该种类型的任务对应的二进制数和1按位进行与操作,并根据操作结果判定该种类型的任务是否需要执行。
第二运算解析单元222,用于当m≥2时,将m种类型的任务对应的二进制数按位进行或操作,得到或操作结果,将所述或操作结果的每一位和1进行与操作,根据与操作结果判定对应的任务是否需要执行。
其中,上述的任务可以为函数的调用或条件语句的判断。当任务为函数的调用时,设计模块21,具体用于针对m种函数,设计m位的二进制数进行表示,每一种函数对应二进制数中的一位。运算解析模块22,具体用于将m种函数对应的二进制数按位进行逻辑操作符的运算和解析,判定是否需要调用对应的函数,当需要调用时,对相应的函数进行调用。
当任务为条件语句的判断,设计模块21具体用于针对m种条件语句,设计m位的二进制数进行表示,每一种条件语句对应二进制数中的一位。运算解析模块22,具体用于将m种条件语句对应的二进制数按位进行逻辑操作 符的运算和解析,判定对应的条件语句是否需要执行,若需要执行,则对相应的条件语句进行执行。
参见图4,为本发明一种电子设备,包括:处理器(processor)401、存储器(memory)402和总线403;其中,所述处理器401和存储器402通过所述总线403完成相互间的通信。
所述处理器401用于调用所述存储器402中的程序指令,以执行上述各方法实施例所提供的方法,例如包括:针对业务逻辑执行过程中的m种不同类型的任务,设计m位的二进制数表示,每一种类型的任务对应二进制数中的一位,其中,m为正整数;将传入的m种类型的任务对应的二进制数,按位进行逻辑操作符的运算和解析,实现对所需要执行的任务进行判定。
本发明公开一种计算机程序产品,该计算机程序产品包括存储在非暂态计算机可读存储介质上的计算机程序,该计算机程序包括程序指令,当程序指令被计算机执行时,计算机能够执行上述对应实施例所提供的智能过滤的控件布局方法,例如包括:针对业务逻辑执行过程中的m种不同类型的任务,设计m位的二进制数表示,每一种类型的任务对应二进制数中的一位,其中,m为正整数;将传入的m种类型的任务对应的二进制数,按位进行逻辑操作符的运算和解析,实现对所需要执行的任务进行判定。
本发明还提供一种非暂态计算机可读存储介质,该非暂态计算机可读存储介质存储计算机指令,该计算机指令使计算机执行上述对应实施例所提供的智能过滤的控件布局方法,例如包括:针对业务逻辑执行过程中的m种不同类型的任务,设计m位的二进制数表示,每一种类型的任务对应二进制数中的一位,其中,m为正整数;将传入的m种类型的任务对应的二进制数,按位进行逻辑操作符的运算和解析,实现对所需要执行的任务进行判定。
本领域普通技术人员可以理解:实现上述方法实施例的全部或部分步骤可以通过程序指令相关的硬件来完成,前述的程序可以存储于一计算机可读取存储介质中,该程序在执行时,执行包括上述方法实施例的步骤;而前述的存储介质包括:ROM、RAM、磁碟或者光盘等各种可以存储程序代码的介质。
以上所描述的实施例仅仅是示意性的,其中作为分离部件说明的单元可 以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部模块来实现本实施例方案的目的。本领域普通技术人员在不付出创造性的劳动的情况下,即可以理解并实施。
通过以上的实施方式的描述,本领域的技术人员可以清楚地了解到各实施方式可借助软件加必需的通用硬件平台的方式来实现,当然也可以通过硬件。基于这样的理解,上述技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品可以存储在计算机可读存储介质中,如ROM/RAM、磁碟、光盘等,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)执行各个实施例或者实施例的某些部分方法。
本发明提供的一种基于内存优化的任务执行方法及系统,巧妙地使用了二进制数对多个任务的执行进行区分,且每个任务对应的二进制数都是独立的,可以同时对多个任务的执行进行判定,每增加一个任务,只需要增加一位二进制,相比现有的使用int类型的数据来存储每一个任务,在保证原有功能不便的情况下,降低了对内存的开销。
最后,本申请的方法仅为较佳的实施方案,并非用于限定本发明的保护范围。凡在本发明的精神和原则之内,所作的任何修改、等同替换、改进等,均应包含在本发明的保护范围之内。
Claims (12)
- 一种基于内存优化的任务执行方法,其特征在于,包括:S1,针对业务逻辑执行过程中的m种不同类型的任务,设计m位的二进制数表示,每一种类型的任务对应二进制数中的一位,其中,m为正整数;S2,将传入的m种类型的任务对应的二进制数,按位进行逻辑操作符的运算和解析,实现对所需要执行的任务进行判定。
- 如权利要求1所述的基于内存优化的任务执行方法,其特征在于,所述步骤S2进一步包括:当m为1时,将该种类型的任务对应的二进制数和1按位进行与操作,并根据操作结果判定该种类型的任务是否需要执行;当m≥2时,将m种类型的任务对应的二进制数按位进行或操作,得到或操作结果,将所述或操作结果的每一位和1进行与操作,根据与操作结果判定对应的任务是否需要执行。
- 如权利要求2所述的基于内存优化的任务执行方法,其特征在于,所述将或操作结果的每一位和1进行与操作,根据与操作结果判定对应的任务是否需要执行进一步包括:将所述或操作结果和1进行与操作,根据与操作结果判定或操作结果的第一位对应的任务是否需要执行;将或操作结果右移一位,再次和1进行与操作,根据与操作结果判定或操作结果的第二位对应的任务是否需要执行;重复执行上述步骤,直到所述或操作结果中的所有二进制位对应的任务均判定完毕。
- 如权利要求3所述的基于内存优化的任务执行方法,其特征在于,所述任务为函数调用或条件语句判定。
- 如权利要求4所述的基于内存优化的任务执行方法,其特征在于,当所述任务为函数调用时,所述步骤S1进一步包括:针对m种函数,设计m位的二进制数进行表示,每一种函数对应二进制 数中的一位;所述步骤S2进一步包括:将m种函数对应的二进制数按位进行逻辑操作符的运算和解析,判定是否需要调用对应的函数,当需要调用时,对相应的函数进行调用。
- 如权利要求4所述的基于内存优化的任务执行方法,其特征在于,当所述任务为条件语句判定时,所述步骤S1进一步包括:针对m种条件语句,设计m位的二进制数进行表示,每一种条件语句对应二进制数中的一位;所述步骤S2进一步包括:将m种条件语句对应的二进制数按位进行逻辑操作符的运算和解析,判定对应的条件语句是否需要执行,若需要执行,则对相应的条件语句进行执行。
- 如权利要求6所述的基于内存优化的任务执行方法,其特征在于,所述业务逻辑执行过程在终端中进行,所述终端为PC或移动终端,所述终端的操作系统为IOS或安卓操作系统。
- 一种基于内存优化的任务执行系统,其特征在于,包括:设计模块,用于针对业务逻辑执行过程中的m种不同类型的任务,设计m位的二进制数来表示,每一种类型的任务对应二进制数中的一位,其中,m为正整数;运算解析模块,用于将传入的m种类型的任务对应的二进制数按位进行逻辑操作符的运算和解析,对所需要执行的任务进行判定。
- 如权利要求8所述的基于内存优化的任务执行系统,其特征在于,所述运算解析模块包括:第一运算解析单元,用于当m为1时,将该种类型的任务对应的二进制数和1按位进行与操作,并根据操作结果判定该种类型的任务是否需要执行;第二运算解析单元,用于当m≥2时,将m种类型的任务对应的二进制数按位进行或操作,得到或操作结果,将所述或操作结果的每一位和1进行与操作,根据与操作结果判定对应的任务是否需要执行。
- 一种电子设备,其特征在于,包括:至少一个处理器、至少一个存储器、通信接口和总线;其中,所述处理器、存储器、通信接口通过所述总线完成相互间的通信;所述通信接口用于该设备与玩具控制系统的通信设备之间的信息传输;所述存储器存储有可被所述处理器执行的程序指令,所述处理器调用所述程序指令能够执行如权利要求1-7任一项所述的方法。
- 一种计算机程序产品,其特征在于,所述计算机程序产品包括存储在非暂态计算机可读存储介质上的计算机程序,所述计算机程序包括程序指令,当所述程序指令被计算机执行时,所述计算机指令使所述计算机执行如权利要求1-7任一项所述的方法。
- 一种非暂态计算机可读存储介质,其特征在于,所述非暂态计算机可读存储介质存储计算机指令,所述计算机指令使所述计算机执行如权利要求1-7任一项所述的方法。
Applications Claiming Priority (2)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201710453005.3A CN107391255A (zh) | 2017-06-15 | 2017-06-15 | 一种基于内存优化的任务执行方法及系统 |
CN201710453005.3 | 2017-06-15 |
Publications (1)
Publication Number | Publication Date |
---|---|
WO2018227942A1 true WO2018227942A1 (zh) | 2018-12-20 |
Family
ID=60332937
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
PCT/CN2017/120186 WO2018227942A1 (zh) | 2017-06-15 | 2017-12-29 | 一种基于内存优化的任务执行方法及系统 |
Country Status (2)
Country | Link |
---|---|
CN (1) | CN107391255A (zh) |
WO (1) | WO2018227942A1 (zh) |
Families Citing this family (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN107391255A (zh) * | 2017-06-15 | 2017-11-24 | 武汉斗鱼网络科技有限公司 | 一种基于内存优化的任务执行方法及系统 |
CN110300309A (zh) * | 2018-03-23 | 2019-10-01 | 北京京东尚科信息技术有限公司 | 视频审核的方法和系统 |
Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101299652A (zh) * | 2008-06-12 | 2008-11-05 | 北京中星微电子有限公司 | 一种确定序列开始位的方法及装置 |
CN102455941A (zh) * | 2010-10-29 | 2012-05-16 | 金蝶软件(中国)有限公司 | 一种基于范式的多任务调度方法、装置及通信终端 |
CN103248712A (zh) * | 2013-05-24 | 2013-08-14 | 杭州东信北邮信息技术有限公司 | 一种多媒体电子屏联播管理方法和系统 |
CN107391255A (zh) * | 2017-06-15 | 2017-11-24 | 武汉斗鱼网络科技有限公司 | 一种基于内存优化的任务执行方法及系统 |
Family Cites Families (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN105045743B (zh) * | 2015-07-27 | 2018-01-23 | 燕山大学 | 一种具备优先级调度的多协议转换方法 |
-
2017
- 2017-06-15 CN CN201710453005.3A patent/CN107391255A/zh active Pending
- 2017-12-29 WO PCT/CN2017/120186 patent/WO2018227942A1/zh active Application Filing
Patent Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101299652A (zh) * | 2008-06-12 | 2008-11-05 | 北京中星微电子有限公司 | 一种确定序列开始位的方法及装置 |
CN102455941A (zh) * | 2010-10-29 | 2012-05-16 | 金蝶软件(中国)有限公司 | 一种基于范式的多任务调度方法、装置及通信终端 |
CN103248712A (zh) * | 2013-05-24 | 2013-08-14 | 杭州东信北邮信息技术有限公司 | 一种多媒体电子屏联播管理方法和系统 |
CN107391255A (zh) * | 2017-06-15 | 2017-11-24 | 武汉斗鱼网络科技有限公司 | 一种基于内存优化的任务执行方法及系统 |
Also Published As
Publication number | Publication date |
---|---|
CN107391255A (zh) | 2017-11-24 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US11106437B2 (en) | Lookup table optimization for programming languages that target synchronous digital circuits | |
EP4325351A2 (en) | Methods and systems for providing high-level operations on a blockchain | |
CN111404883B (zh) | 一种物联网设备通用协议的解析方法及装置 | |
US10042654B2 (en) | Computer-based distribution of large sets of regular expressions to a fixed number of state machine engines for products and services | |
US11775269B2 (en) | Generating a synchronous digital circuit from a source code construct defining a function call | |
CN109902274A (zh) | 一种将json字符串转化为thrift二进制流的方法及系统 | |
US11086668B2 (en) | Method, electronic device and computer program product for processing task | |
CN110941655B (zh) | 一种数据格式转换方法及装置 | |
WO2022247194A1 (zh) | 乘法器、数据处理方法、芯片、计算机设备及存储介质 | |
WO2018227942A1 (zh) | 一种基于内存优化的任务执行方法及系统 | |
CN111090438A (zh) | 一种基于kubernetes的FPGA虚拟化训练的方法、设备及介质 | |
CN110517137A (zh) | 一种生成功能模块化安全合约的方法及系统 | |
CN113703996B (zh) | 基于用户和yang模型分组的访问控制方法、设备及介质 | |
CN111966383A (zh) | 一种操作系统内核兼容性量化分析方法、系统和介质 | |
CN107479870A (zh) | 一种第三方类库调用方法、装置、移动终端及存储介质 | |
CN110825453A (zh) | 基于大数据平台的数据处理方法及装置 | |
CN111914987A (zh) | 基于神经网络的数据处理方法及装置、设备和可读介质 | |
CN110909522B (zh) | 一种数据处理方法、装置和电子设备及介质 | |
CN112882690A (zh) | 一种应用开发方法及装置 | |
CN108920144B (zh) | 一种消息处理方法和装置 | |
CN114138242A (zh) | 基于rpa软件的无代码跨系统接口开发方法 | |
WO2016189721A1 (ja) | ソースコード評価装置及びソースコード評価方法及びソースコード評価プログラム | |
CN116560847B (zh) | 任务处理方法、装置、电子设备以及存储介质 | |
CN110727654B (zh) | 分布式系统的数据提取方法、装置、服务器和存储介质 | |
EP4105862A2 (en) | Data processing method and apparatus, electronic device and storage medium |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
121 | Ep: the epo has been informed by wipo that ep was designated in this application |
Ref document number: 17913423 Country of ref document: EP Kind code of ref document: A1 |
|
NENP | Non-entry into the national phase |
Ref country code: DE |
|
122 | Ep: pct application non-entry in european phase |
Ref document number: 17913423 Country of ref document: EP Kind code of ref document: A1 |