Method for processing data and related device

By dynamically adjusting the number of length fields based on array size, the method optimizes memory usage and reduces garbage collection, addressing inefficiencies in programming languages with fixed 32-bit array length limitations.

WO2026084607A1PCT designated stage Publication Date: 2026-04-23HUAWEI TECH CO LTD +1
View PDF 4 Cites 0 Cited by

Patent Information

Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
HUAWEI TECH CO LTD
Filing Date
2024-10-14
Publication Date
2026-04-23

AI Technical Summary

Technical Problem

Existing programming languages face inefficiencies in memory usage due to the fixed 32-bit array length limitation, leading to excessive memory consumption and frequent garbage collection, especially in resource-sensitive scenarios like terminals and clouds, as arrays often exceed the 32-bit limit.

Method used

Implement a method to dynamically adjust the number of length fields based on the array length, using one or more length fields to indicate array length, reducing overhead by matching the number of fields with the array size, thereby optimizing memory usage.

Benefits of technology

This approach allows arrays of any length to be efficiently managed, reducing memory consumption and minimizing garbage collection frequency, enhancing performance in resource-constrained environments.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure IMGF000003_0001
    Figure IMGF000003_0001
  • Figure IMGF000005_0001
    Figure IMGF000005_0001
  • Figure IMGF000006_0001
    Figure IMGF000006_0001
Patent Text Reader

Abstract

Embodiments of the present application provide a method for processing data and related devices. The method includes: obtaining an array index of an array access operation, where the array access operation is configured to access an element within an array; determining whether the array index exceeds a length of the array according to К length field(s) carried by an object of the array, where each length field among the К length field(s) corresponds to a length threshold, the each length field among the К length field(s) carries a piece of length information for indicating the length of the array, К is a positive integer greater than or equal to 1. According to the embodiments of the present application, an array length of arrays with any length may be indicated.
Need to check novelty before this filing date? Find Prior Art

Description

[0001] METHOD FOR PROCESSING DATA AND RELATED DEVICE

[0002] TECHNICAL FIELD

[0003] Embodiments of the present application relate to the field of information technology, more specifically, related to a method for processing data and related devices.

[0004] BACKGROUND

[0005] In computer programming languages, an array type indicates that consecutive data of the same type is stored in a memory, and the number of data stored is a length of the array. A program obtains the data in a corresponding position of the array through an index. When an index length exceeds an array length, the data cannot be obtained or the program breaks down. To prevent this problem, some programming languages may check whether the index length exceeds the array length when accessing an array. If the index length exceeds the array length, an array index out-of-bounds error is thrown. This mechanism is called the array index out-of-bounds check mechanism.

[0006] To implement the out-of-bounds array check, the length of the array needs to be stored in the array. In some programming languages, a 32-bit int type is used to represent the index. Therefore, the array length cannot exceed 231- 1. In a corresponding runtime implementation, a 32-bit storage array length. However, with the development of current technologies, especially in scenarios of high-performance computing and artificial intelligence (Al) large models, the array length often exceeds 231- 1. Therefore, in the design of programming languages in a 32-bit system, the array length is also designed to be no more than 231- 1. However, in a 64-bit system, the maximum array length is 2s3- 1. The runtime implementation uses 64- bit to store the array length.

[0007] However, this method causes an extra 32-bit (4 bytes) memory occupation for each array. For most arrays in the program, the length does not exceed 231- 1, and even some arrays have only a few elements. Therefore, each array occupies an extra 4 bytes memory. In resource-sensitive scenarios such as terminals and clouds, too much memory is consumed, increasing a garbage collection (GC) frequency and affecting user experience. In addition, applications cannot run properly due to insufficient memory.

[0008] SUMMARY

[0009] Embodiments of the present application provide a method for processing data and related devices, which may indicate an array length of arrays with any length.

[0010] According to a first aspect, an embodiment of the present application provides a method for processing data. The method includes: obtaining an array index of an array access operation, where the array access operation is configured to access an element within an array; determining whether the array index exceeds a length of the array according to K length field(s) carried by an object of the array, where each length field among the K length field) s) corresponds to a length threshold, the each length field among the K length field(s) carries a piece of length information for indicating the length of the array, K is a positive integer greater than or equal to 1.

[0011] According to the aforementioned technical solution, the object of the array may include one or more length fields for indicating the length of the array. Under this case, the length of arrays with any length may be indicated by the one or more length fields. Meanwhile, the number of the length field may be matched with the length of the array. For example, when the length of the array is less than or equal to a length threshold corresponding to a first length field, the object of the array may only cany one length field; when the length of the array is greater than the length threshold corresponding to the first length field, while the length of the array is less than or equal to a length threshold corresponding to a second length field, the object of the array may carry two length fields. Therefore, an overhead for indicating the array length may be adjusted according to the array length, and the overhead may be saved.

[0012] In a possible design of the first aspect, when the length of the array is less than a first length threshold, K is equal to 1, when the length of the array is greater than or equal to the first length threshold, K is a positive integer greater than or

[0013] DESCRIPTION OF DRAWINGS

[0014] FIG. 1 illustrates a data processing method provided by some embodiments of the present application.

[0015] FIG. 2 illustrates a data processing method provided by some embodiments of the present application.

[0016] FIG. 3 illustrates an example of an array.

[0017] FIG. 4 illustrates an example of an array.

[0018] FIG. 5 illustrates a data processing method provided by some embodiments of the present application.

[0019] FIG. 6 illustrates a data processing method provided by some embodiments of the present application.

[0020] FIG. 7 is a schematic block diagram of an electronic device according to some embodiments of the present application.

[0021] FIG. 8 is a schematic block diagram of an electronic device according to some embodiments of the present application.

[0022] DESCRIPTION OF EMBODIMENTS

[0023] The following describes the technical solutions in the present application with reference to the accompanying drawings.

[0024] The terms such as "first" and "second" below are merely for a descriptive purpose, and cannot be understood as indicating or implying relative importance, or implicitly indicating a quantity of indicated technical features. Therefore, the PC17RU2024 / 000320 features defined by "first" and "second" can explicitly or implicitly include one or more features.

[0025] As used herein, "at least one" means one or more, and "a plurality of' means two or more, "and / or" describes an association relationship of associated objects, and indicates that there may be three relationships. For example, A and / or B may indicate cases includes “only A”, “both A and B”, and “only B”, where A and B may be singular or plural. The character " / " generally indicates that the associated objects are in an OR relationship. "At least one of the following items" or a similar expression thereof refers to any combination of these items, including any combination of a single item or a plurality of items. For example, “at least one of a, b, or c” may represent a, b, c, “a and b”, “a and c”, “b and c”, or “a, b and c”, where a, b, and c may be a single or multiple form.

[0026] Embodiments of the present application are applied to a runtime implementation of a programming language, and code written in the programming language is finally executed on computer hardware in two modes. One is an executable file that can be directly executed, such as an ELF file in Linux or a PE file in Windows. It contains executable instructions and runtime implementation of the program, and the present invention is included as a part of the runtime. Go, Rust, and the like are such execution modes. The second is a manner in which loading and execution need to be performed by using a virtual machine. Program code is first compiled by a compiler into a file in an intermediate format. For example, the Java language corresponds to Java bytecode, and then the bytecode is loaded and executed by a virtual machine. The present invention is included in a virtual machine, for example, a Hotspot virtual machine of Java.

[0027] There are no limitations on the programming language in the embodiments of the present application. For example, the programming language may be Java, C#, JavaScript, Python, Rust, Golang, or the like.

[0028] Embodiments of the present application may include two stages. The first stage is configured to allocate an array, and the first stage may be referred to as array allocation. The second stage is configured to execute codes including the allocated array, and the second stage may be referred to as code execution.

[0029] In some embodiments, the array allocation and the code execution may be performed by different computer device. For example, a first computer device is configured to perform the array allocation, while a second computer device is configured to perform the code execution. The first computer device may be a physical computer device (e.g., a personal computer, a laptop, a workstation computer, or the like) or a virtual machine (VM) running on a physical computer device. Similarly, the second computer device may be a physical computer device or a VM. In some embodiments, the first computer device may perform the array allocation and transmit codes including the allocated array to the second computer device. Correspondingly, the second computer device may receive the codes from the first device and perform the code execution. In some other embodiments, the first computer device may perform the array allocation and upload the codes including the allocated array to a third computer device (e.g., a server, a network attached storage (NAS), a workstation computer, or the like). The second computer device may download the codes from the third computer device and perform the code execution.

[0030] In some other embodiments, both the array allocation and the code execution may be performed by a single computer device. For example, the computer device may perform the array allocation and store the codes including the allocated array. Then, the computer device may read the codes and perform the array execution. Similarly, the computer device may be a physical computer device or a VM.

[0031] FIG. 1 illustrates a data processing method provided by some embodiments of the present application. The data processing method illustrated in FIG. 1 may be the aforementioned array allocation. The data processing method illustrated in FIG. 1 may be performed by a computer device or a component of a computer device (e.g., a processor, a system on chip (SoC), or the like). For convenience, it is assumed that the data processing method is performed by a computer device.

[0032] 101, The computer device obtains a length of an array.

[0033] 102, The computer device determines K length field(s) according to the length of the array.

[0034] When the length of the array is less than a first length threshold, K is equal to 1. In other words, when the length of the array is less than the first length threshold, the computer device may determine one length field. The length field carries a piece of length information.

[0035] In some embodiments, the length information is a value of the length of the array. In other words, the length field carries a value, and the value is the length of the array. For example, if the length of the array is 0x07C8, the value carried by the length field will be 0x07C8.

[0036] When the length of the array is greater than or equal to the first length threshold, K is a positive integer greater than or equal to 2, and a value of K is determined according to the length of the array. Table 1 illustrates a relation between the length of the array and the value of K. It should be understood that FIG. 3 and FIG. 4 are used to illustrate length information carried by the first length field and / or the second length field and constitute no limitation on a relation between the length filed and other fields. For example, both FIG. 3 and FIG. 4 illustrate that an array instance is directly after the first length field. However, in some embodiments, one or more fields may be inserted between the first length field and the array instance. In some embodiments, as illustrated in FIG. 4, the second length field is after the array instance. In some other embodiments, the second length field may be before the first length field. Under this case, an offset of the second length filed is fixed, which makes it easier to determine a position of the second length field.

[0037] FIG. 5 illustrates a data processing method provided by some embodiments of the present application. The method illustrated in FIG. 5 may be performed by a computer device or a component of a computer device (e.g., a processor, a system on chip (SoC), or the like). For convenience, it is assumed that the data processing method is performed by a computer device.

[0038] 501, The computer device obtains an array index of an array access operation.

[0039] The array access operation is configured to access an element within an array. For example, the array access operation may be configured to retrieve or modify a value of an element in the array by specifying its index.

[0040] For example, in some embodiments, the computer device may obtain a subscript of the array carried by the array access operation. The subscript of the array may be the array index.

[0041] 502, The computer device determines whether the array index exceeds a length of the array according to K length field) s) carried by an object of the array.

[0042] Each length field among the K length field(s) corresponds to a length threshold, the each length field among the K length field(s) carries a piece of length information for indicating the length of the array, K is a positive integer greater than or equal to 1.

[0043] When the length of the array is less than a first length threshold, K is equal to 1, where the first length threshold is a length threshold corresponding to a first length filed among the K length field) s). When the length of the array is greater than or equal to the first length threshold, K is a positive integer greater than or equal to 2, and a value of K is determined according to the length of the array. Details about the value of the K and the threshold may refer to aforementioned embodiments, and we will not elaborate further for the sake of conciseness.

[0044] The computer device may determine whether the array index is greater than or equal to a value indicated by a first length information. The first length information is a piece of length information carried by the first length field among the K length field) s). Similarly, for convenience, a piece of length information carried by a second length field among the K length field(s) may be referred to as a second length information, a piece of length information carried by a third length field among the K length field(s) may be referred to as a third length information, and the like.

[0045] In some embodiments, each piece of the length information is a value, and the value is configured to indicates the length of the array.

[0046] For example, the computer device determines that whether the array index is less than the first length information. When the array index is less than the first length information, the computer device may obtain a result where the array index does not exceed the length of the array (hereinafter referred to as a positive result). When the first length information is equal to a preset value, the computer device may determine whether the array index is less than the second length information. When the array index is less than the second length information, the computer device may obtain the positive result. When the second length information is equal to a preset value, the computer device may determine whether the array index is less than the third length information. In general, when K is a positive integer greater than equal to 2, the computer device may determine K-l piece) s) of length information carried by preceding K-l length field(s) (that is the first length information to the (K-l)thlength information) is equal to K-l preset value(s) respectively, and the computer device determines whether the array index exceeds the length of the array according to the Kthlength information. When the array index is less than the Kthlength information, the computer device may obtain the positive result; when the array index is greater than or equal to the Kthlength information, the computer device may obtain a result where the array index exceeds the length of the array (hereinafter referred to as a negative result). It should be understood that the processor 802 may be an integrated circuit chip and has a signal processing capability. In an implementation process, steps of the foregoing method embodiments may be completed by using a hardware integrated logic circuit in the processor, or by using instructions in a form of software. The processor may be a general purpose processor, a central processing unit (CPU), a system on chip (SoC) or another programmable logic device, a discrete gate or transistor logic device, or a discrete hardware component. The processor may implement or perform the methods, the steps, and the logical block diagrams that are disclosed in the embodiments of the present application. The general purpose processor may be a microprocessor, or the processor may be any conventional processor or the like. The steps of the methods disclosed with reference to the embodiments of the present application may be directly performed and completed by the processor, or may be performed and completed by using a combination of hardware in the processor and a software module / unit. The software module / unit may be located in a mature storage medium in the art, such as a random access memory, a flash memory, a readonly memory, a programmable read-only memory, an electrically erasable programmable memory, or a register. The storage medium is located in the memory, and the processor reads information in the memory and completes the steps of the foregoing methods in combination with hardware in the processor.

[0047] It may be understood that the memory 803 in the embodiments of the present application may be a volatile memory or a nonvolatile memory, or may include both a volatile memory and a nonvolatile memory. The nonvolatile memory may be a read-only memoiy (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory. The volatile memory may be a random access memory (RAM) and is used as an external cache. By way of example rather than limitation, many forms of RAMs may be used, and are, for example, a static random access memory (SRAM), a dynamic random access memory (DRAM), a synchronous dynamic random access memory (SDRAM), a double data rate synchronous dynamic random access memory (DDR SDRAM), an enhanced synchronous dynamic random access memory (ESDRAM), a synchronous link dynamic random access memory (SLDRAM), and a direct rambus random access memory (DR RAM).

[0048] The present application provides a computer readable storage medium including instructions. When the instructions run on an electronic device, the electronic device is enabled to perform the aforementioned method.

[0049] The present application provides a chip system. The chip system includes a communication interface and a processing circuit, and the communication interface is configured to obtain to-be-processed data, and the processing circuit is configured to process the to-be-processed data according to the aforementioned method.

[0050] The present application provides a computer program product. When the computer program product runs on an electronic device, the electronic device is enabled to perform the aforementioned method.

[0051] A person of ordinary skill in the art may be aware that, in combination with the examples described in the embodiments disclosed in this specification, units and algorithm steps can be implemented by electronic hardware or a combination of computer software and electronic hardware. Whether the functions are performed by hardware or software depends on particular applications and design constraints of the technical solutions. A person skilled in the art may use different methods to implement the described functions for each particular application, but it should not be considered that the implementation goes beyond the scope of this application.

[0052] It may be clearly understood by a person skilled in the art that, for the purpose of convenient and brief description, for a detailed working process of the foregoing system, apparatus, and unit, refer to a corresponding process in the foregoing method embodiment. Details are not described herein again.

[0053] In the several embodiments provided in this application, it should be understood that the disclosed system, apparatus, and method may be implemented in other manners. For example, the described apparatus embodiment is merely an example. For example, the unit division is merely logical function division and may be other division in actual implementation. For example, a plurality of units or components may be combined or integrated into another system, or some features may be ignored or not performed. In addition, the displayed or discussed mutual couplings or direct couplings or communication connections may be implemented through some interfaces. The indirect couplings or communication connections between the apparatuses or units may be implemented in electronic, mechanical, or other forms. The units described as separate parts may be or may not be physically separate, and parts displayed as units may be or may not be physical units, may be located in one position, or may be distributed on a plurality of network units. Some or all of the units may be selected based on actual requirements to achieve the objectives of the solutions of the embodiments.

[0054] In addition, functional units in the embodiments of this application may be integrated into one processing unit, or each of the units may exist alone physically, or two or more units are integrated into one unit.

[0055] When the functions are implemented in a form of a software functional unit and sold or used as an independent product, the functions may be stored in a computer readable storage medium. Based on such an understanding, the technical solutions in this application essentially, or the part contributing to the prior art, or some of the technical solutions may be implemented in a form of a software product. The computer software product is stored in a storage medium, and includes several instructions for instructing a computer device (which may be a personal computer, a server, a network device, or the like) to perform all or some of the steps of the methods described in the embodiments of this application. The foregoing storage medium includes: any medium that can store program code, such as a USB flash drive, a removable hard disk, a read-only memory (Read-Only Memory, ROM), a random access memory (Random Access Memory, RAM), a magnetic disk, or an optical disc.

[0056] The foregoing descriptions are merely specific implementations of this application, but are not intended to limit the protection scope of this application. Any variation or replacement readily figured out by a person skilled in the art within the technical scope disclosed in this application shall fall within the protection scope of this application. Therefore, the protection scope of this application shall be subject to the protection scope of the claims.

Claims

PCI7RU2024 / 000320CLAIMS1. A method for processing data, comprising: obtaining an array index of an array access operation, wherein the array access operation is configured to access an element within an array; determining whether the array index exceeds a length of the array according to K length field(s) carried by an object of the array, wherein each length field among the K length field(s) corresponds to a length threshold, the each length field among the K length field(s) carries a piece of length information for indicating the length of the array, K is a positive integer greater than or equal to 1.

2. The method according to claim 1 wherein when the length of the array is less than a first length threshold, K is equal to 1, when the length of the array is greater than or equal to the first length threshold, K is a positive integer greater than or equal to 2, wherein the first length threshold is a length threshold corresponding to a first length field among the K length field(s).

3. The method according to claim 2, wherein when K is a positive integer greater than or equal to 2, the determining whether the array index exceeds a length of the array according to K length field(s), comprises: determining K-l piece(s) of length information carried by preceding K-l length field(s) is equal to K-l preset value(s) respectively; determining whether the array index exceeds the length of the array according to a piece of length information carried by a Kthlength field among the K length field(s), wherein the piece of length information carried by the K111length field is a value of the length of the array.

5. The method according to claim 4, wherein Nj is equal to 2h4.

6. The method according to claim 5, wherein K is equal to 2.

7. An electronic device, comprising: an obtaining unit, configured to obtain an array index of an array access operation, wherein the array access operation is configured to access an element within an array; a determining unit, configured to determine whether the array index exceeds a length of the array according to K length field(s) carried by an object of the array, wherein each length field among the K length field(s) corresponds to a length threshold, the each length field among the K length field(s) carries a piece of length information for indicating the length of the array, K is a positive integer greater than or equal to 1.

8. The electronic device according to claim 7, wherein when the length of the array is less than a first length threshold, K is equal to 1, when the length of the array is greater than or equal to the first length threshold, K is a positive integer greater than or equal to 2, wherein the first length threshold is a length threshold corresponding to a first length field among the K length field(s).

9. The electronic device according to claim 8, wherein when K is a positive integer greater than or equal to 2, the determining unit is specifically configured to: determine K-l piece(s) of length information carried by preceding K-l length field(s) is equal to K-l preset value(s) respectively; determine whether the array index exceeds the length of the array according to a piece of length information carried by a Kthlength field among the K length field(s), wherein the piece of length information carried by the K,hlength field is a value of the length of the array.

10. The electronic device according to any one of claims 7 to 9, wherein a jthlength field among the K length field(s) occupies Nj bits, and a length threshold corresponding to the j,hlength field is 2NJ-1-1 , wherein j=l, ..., K, and Nj is determined according to j.

11. The method according to claim 10, wherein Nj is equal to 2J’4.

12. The method according to claim 11, wherein K is equal to 2.

13. An electronic device, comprising a memory and a processor, wherein the memory is configured to store instructions, and the processor is configured to invoke the instructions from the memory and run the instructions, so that the electronic device performs the method according to any one of claims 1 to 6.

14. A chip system, comprising a communication interface and a processing circuit, wherein the communication interface is configured to obtain to-be-processed data, and the processing circuit is configured to process the to-be-processed data according to the method according to any one of claims 1 to 6.

15. A computer readable storage medium, wherein the computer readable storage medium stores instructions, and when the instructions run on an electronic device, the electronic device is enabled to perform the method according to any one of claims 1 to 6.

16. A computer program product, wherein when the computer program product runs on an electronic device, the electronic device is enabled to perform the method according to any one of claims 1 to 6.

Citation Information

Patent Citations

  • Method and apparatus for efficient implementation of discontiguous objects

    US20050149346A1

  • Instruction folding for a stack-based machine

    US20070277021A1

  • Method and system for dynamic memory management

    US20120278581A1

  • Systems And Methods Of Memory And Access Management

    US20150227414A1