File content processing method and device, electronic equipment and storage medium
By using fixed-size blocks to store file content in memory and on disk, and operating only on the memory blocks that need to be modified, the problem of long file editing time and low efficiency in the prior art is solved, and a more efficient file modification and writing process is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- CHINA UNITED NETWORK COMM GRP CO LTD
- Filing Date
- 2021-12-09
- Publication Date
- 2026-06-23
AI Technical Summary
In existing technologies, when editing the contents of files on a disk, insertion or deletion operations are time-consuming and inefficient, especially when operating at positions other than the beginning and end of the file, which requires overall adjustment of the file contents, resulting in increased CPU execution time and long writing time.
File content is stored using fixed-size memory blocks and disk blocks. Operations are performed only on the memory blocks that need to be modified, while other blocks remain unchanged. The modified memory block content is then synchronized to the corresponding disk blocks, keeping the disk blocks unchanged.
It reduces CPU execution time, improves file modification efficiency, and reduces the time required for write operations, thereby improving overall operational efficiency.
Smart Images

Figure CN116257168B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data processing technology, and in particular to a method, apparatus, electronic device, and storage medium for processing document content. Background Technology
[0002] Due to the rapid development of computer science and technology, the cost of disk storage has gradually decreased, and the storage space has become larger and larger. This has led people to focus not only on the storage space and cost of disks, but also on the storage efficiency of disks.
[0003] When editing a file on disk, the process first involves reading the file content from the disk into memory. Then, the operating system writes the file content to memory. Finally, the modified file content in memory is synchronized to the disk. In existing technology, during the write operation to memory, if insertion or deletion occurs at any position other than the beginning or end of the file, the file content after the insertion or deletion point must be rearranged, consuming CPU time and reducing efficiency. Furthermore, writing the edited file content from memory to disk requires rewriting the file from memory to disk, making the write process time-consuming and inefficient. Summary of the Invention
[0004] This application provides a method, apparatus, electronic device, and storage medium for processing file content, in order to solve the problems of long processing time and low efficiency when editing file content on a disk in the prior art.
[0005] Firstly, this application provides a method for processing document content, including:
[0006] In response to a file content modification instruction, a second memory block to be modified is determined from a plurality of first memory blocks stored in memory.
[0007] Based on the file content modification instructions, the file content in the second memory block is modified to obtain the target memory block.
[0008] The file content in the second disk block corresponding to the second memory block is replaced with the file content in the target memory block, while keeping the other disk blocks in the disk unchanged. The disk includes multiple first disk blocks that correspond one-to-one with the first memory block, and the other disk blocks are the disk blocks in the first disk blocks other than the second disk block.
[0009] Optionally, the file content in the second memory block is modified according to the file content modification instructions to obtain the target memory block, including:
[0010] Based on the file content modification instructions, the file in the second memory block is modified, and the memory blocks in memory that have changed are identified.
[0011] The memory block that has changed is identified as the target memory block.
[0012] Optionally, the file content modification command is used to instruct the insertion of file content.
[0013] After modifying the file content in the second memory block according to the file content modification instructions, the memory blocks in memory that have changed are identified, including:
[0014] Based on the file content modification instructions, determine the insertion position of the file content to be inserted.
[0015] Based on the insertion position, the second memory block is divided into a first sub-memory block and a second sub-memory block.
[0016] Insert the contents of the file to be inserted into the first sub-memory block, and modify the storage location of the second sub-memory block.
[0017] The changed memory blocks are determined based on the first sub-memory block after the file content is inserted and the second sub-memory block after the position is modified.
[0018] Optionally, based on the first sub-memory block after inserting file content and the second sub-memory block after modifying its position, the changed memory blocks are determined, including:
[0019] If the sum of the number of bytes of the file content to be inserted and the number of bytes of the original file content in the first sub-memory block is greater than the preset storage space size corresponding to the file content in the memory block, then a new memory block is created.
[0020] The remaining content of the file to be inserted, obtained after inserting the content of the file to be inserted into the first sub-memory block, is then inserted into the new memory block.
[0021] The first sub-memory block after inserting the file content, the second sub-memory block after modifying its position, and the new memory block after inserting the file content are identified as the memory blocks that have changed.
[0022] Optionally, determining the changed memory blocks based on the first sub-memory block after inserting file content and the second sub-memory block after modifying its position also includes:
[0023] In the first sub-memory block after inserting file content, the second sub-memory block after modifying its position, and the new memory block after inserting file content, it is determined whether there is a third memory block whose file content has fewer bytes than a first preset value, wherein the first preset value is less than or equal to half of the preset storage space size corresponding to the file content in the memory block.
[0024] If it exists, then determine whether the number of bytes of the file content in the fourth memory block is less than the first preset value. The fourth memory block is the memory block before the third memory block and / or the memory block after the third memory block.
[0025] If the number of bytes of the file content in the fourth memory block is less than the first preset value, then the third memory block and the fourth memory block are merged to obtain the first merged memory block.
[0026] The changed memory blocks are updated using the first merged memory block.
[0027] Optionally, the file content modification command is used to instruct the deletion of file content.
[0028] After modifying the file content in the second memory block according to the file content modification instructions, the memory blocks in memory that have changed are identified, including:
[0029] According to the file content modification instruction, the target file content in the second memory block is deleted, and the other file content in the second memory block except for the target file content is shifted to obtain the modified second memory block.
[0030] Based on the modified second memory block, determine the memory blocks that have changed.
[0031] Optionally, based on the modified second memory block, the changed memory blocks are determined, including:
[0032] Determine whether the number of bytes of the file content in the modified second memory block is less than a first preset value. The first preset value is less than or equal to half of the preset storage space size corresponding to the file content in the memory block.
[0033] If the number of bytes of the file content in the modified second memory block is less than the first preset value, and the number of bytes of the file content in the fifth memory block is less than the first preset value, then the file content in the modified second memory block and the fifth memory block are merged to obtain a second merged memory block; the fifth memory block is the memory block preceding the modified second memory block and / or the memory block following the modified second memory block.
[0034] The second merged memory block is identified as the memory block that has changed.
[0035] Secondly, this application provides a document content processing apparatus, comprising:
[0036] The determination module is used to determine the second memory block to be modified from multiple first memory blocks stored in memory in response to a file content modification instruction.
[0037] The modification module is used to modify the file content in the second memory block according to the file content modification instructions to obtain the target memory block.
[0038] The replacement module is used to replace the file content in the second disk block corresponding to the second memory block with the file content in the target memory block, while keeping other disk blocks in the disk unchanged. The disk includes multiple first disk blocks that correspond one-to-one with the first memory block, and the other disk blocks are the disk blocks in the first disk blocks other than the second disk block.
[0039] Optional, modify the module, specifically for:
[0040] Based on the file content modification instructions, the file in the second memory block is modified, and the memory blocks in memory that have changed are identified.
[0041] The memory block that has changed is identified as the target memory block.
[0042] Optionally, the file content modification command is used to instruct the insertion of file content.
[0043] Modify the module, specifically for:
[0044] Based on the file content modification instructions, determine the insertion position of the file content to be inserted.
[0045] Based on the insertion position, the second memory block is divided into a first sub-memory block and a second sub-memory block.
[0046] Insert the contents of the file to be inserted into the first sub-memory block, and modify the storage location of the second sub-memory block.
[0047] The changed memory blocks are determined based on the first sub-memory block after the file content is inserted and the second sub-memory block after the position is modified.
[0048] Optional, modify the module, specifically for:
[0049] If the sum of the number of bytes of the file content to be inserted and the number of bytes of the original file content in the first sub-memory block is greater than the preset storage space size corresponding to the file content in the memory block, then a new memory block is created.
[0050] The remaining content of the file to be inserted, obtained after inserting the content of the file to be inserted into the first sub-memory block, is then inserted into the new memory block.
[0051] The first sub-memory block after inserting the file content, the second sub-memory block after modifying its position, and the new memory block after inserting the file content are identified as the memory blocks that have changed.
[0052] Optional, modify the module, specifically for:
[0053] In the first sub-memory block after inserting file content, the second sub-memory block after modifying its position, and the new memory block after inserting file content, it is determined whether there is a third memory block whose file content has fewer bytes than a first preset value, wherein the first preset value is less than or equal to half of the preset storage space size corresponding to the file content in the memory block.
[0054] If it exists, then determine whether the number of bytes of the file content in the fourth memory block is less than the first preset value. The fourth memory block is the memory block before the third memory block and / or the memory block after the third memory block.
[0055] If the number of bytes of the file content in the fourth memory block is less than the first preset value, then the third memory block and the fourth memory block are merged to obtain the first merged memory block.
[0056] The changed memory blocks are updated using the first merged memory block.
[0057] Optionally, the file content modification command is used to instruct the deletion of file content.
[0058] Modify the module, specifically for:
[0059] According to the file content modification instruction, the target file content in the second memory block is deleted, and the other file content in the second memory block except for the target file content is shifted to obtain the modified second memory block.
[0060] Based on the modified second memory block, determine the memory blocks that have changed.
[0061] Optional, modify the module, specifically for:
[0062] Determine whether the number of bytes of the file content in the modified second memory block is less than a first preset value. The first preset value is less than or equal to half of the preset storage space size corresponding to the file content in the memory block.
[0063] If the number of bytes of the file content in the modified second memory block is less than the first preset value, and the number of bytes of the file content in the fifth memory block is less than the first preset value, then the file content in the modified second memory block and the fifth memory block are merged to obtain a second merged memory block; the fifth memory block is the memory block preceding the modified second memory block and / or the memory block following the modified second memory block.
[0064] The second merged memory block is identified as the memory block that has changed.
[0065] Thirdly, this application provides an electronic device, including: a memory and a processor;
[0066] Memory is used to store computer programs.
[0067] A processor is used to read a computer program stored in memory and execute the file content processing method described in the first aspect according to the computer program in memory.
[0068] Fourthly, this application provides a readable storage medium having a computer program stored thereon, the computer program storing computer execution instructions, which, when executed by a processor, are used to implement the file content processing method as described in the first aspect above.
[0069] Fifthly, embodiments of this application also provide a computer program product, including a computer program that, when executed by a processor, implements the file content processing method described in the first aspect.
[0070] The file content processing method, apparatus, electronic device, and storage medium provided in this application, in response to a file content modification instruction, determine a second memory block to be modified from a plurality of first memory blocks stored in memory, and modify the file content in the second memory block according to the file content modification instruction to obtain a target memory block. The file content corresponding to the second disk block on the disk corresponding to the second memory block is replaced with the file content corresponding to the target memory block, while keeping other disk blocks on the disk unchanged. The disk includes a plurality of first disk blocks that correspond one-to-one with the first memory blocks, and the other disk blocks are the disk blocks in the first disk blocks excluding the second disk block. In this application, because the file content is stored in fixed-size blocks, the time taken for the entire modification process is reduced and the efficiency is improved. Moreover, when modifying the file content in memory, only the memory block to be modified is operated on, while other memory blocks remain unchanged, thereby reducing CPU execution time and improving execution efficiency. In addition, during the process of writing the modified file content in memory to the disk, it is only necessary to synchronize the file content in the target memory block after modification to the corresponding disk block, while other disk blocks in the disk remain unchanged. This avoids the phenomenon in the prior art where all memory blocks in memory need to be rewritten to the disk after a write operation, thereby reducing the time required for write operations and improving file operation efficiency. Attached Figure Description
[0071] Figure 1 This application provides a schematic diagram of a file storage structure on a disk, as illustrated in an embodiment of the present application.
[0072] Figure 2 This application provides a schematic diagram of the structure of a disk block according to an embodiment of the present application;
[0073] Figure 3 This application provides a schematic diagram of a file storage structure in memory.
[0074] Figure 4 This is a schematic diagram of the structure of a memory block provided in an embodiment of this application;
[0075] Figure 5 A flowchart illustrating a method for processing document content provided in an embodiment of this application;
[0076] Figure 6 This is a schematic diagram illustrating an insertion operation on the contents of a second memory block file, provided as an embodiment of this application.
[0077] Figure 7 This is a schematic diagram illustrating the merging of memory blocks after an insertion operation, as provided in an embodiment of this application.
[0078] Figure 8 This is a schematic diagram illustrating a deletion operation on the contents of a second memory block file, provided as an embodiment of this application.
[0079] Figure 9 This is a schematic diagram illustrating the merging of memory blocks after a deletion operation, as provided in an embodiment of this application.
[0080] Figure 10 This is a schematic diagram illustrating how file content is written from a memory block to a disk block after an insertion operation, as provided in an embodiment of this application.
[0081] Figure 11 This is a schematic diagram illustrating how file content is written from a memory block to a disk block after a deletion operation, as provided in an embodiment of this application.
[0082] Figure 12 This is a schematic diagram of the structure of a document content processing device provided in an embodiment of this application;
[0083] Figure 13 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application.
[0084] The accompanying drawings illustrate specific embodiments of this application, which will be described in more detail below. These drawings and descriptions are not intended to limit the scope of the concept in any way, but rather to illustrate the concept of this application to those skilled in the art through reference to particular embodiments. Detailed Implementation
[0085] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this application as detailed in the appended claims.
[0086] First, let me explain the terms used in this application:
[0087] Disk block: A disk block is an abstraction of N sectors on a disk. Figure 1 This is a diagram illustrating the storage structure of files on a disk, such as... Figure 1 As shown, a file is split into multiple non-contiguous disk blocks for storage, and each disk block has a fixed storage space. Figure 2 This is a schematic diagram of the disk block structure, such as... Figure 2 As shown, each disk block is divided into a file content area, a file content terminator, a blank area, a marker indicating that the file content is less than half full, and the sector address of the next disk block. For example, four sectors can be abstracted into one disk block, and each disk block occupies a size of 2KB. The file content area occupies 0-2030 bytes, the file content terminator occupies 1 byte, the marker indicating that the file content is less than half full occupies 1 byte, the sector address of the next disk block occupies 8 bytes, and the remaining bytes are represented by whitespace characters and located in the blank area.
[0088] Memory blocks: A memory block is an abstraction of contiguous memory units stored in a memory buffer on disk. Figure 3 This refers to the file's storage structure in memory, whose structure and storage space size are consistent with disk blocks, such as... Figure 3 As shown, a file is split into multiple non-contiguous memory blocks in memory, and each memory block has a fixed storage space. Figure 4 A schematic diagram of the memory block structure, such as Figure 4 As shown, each memory block is divided into a file content area, a file content terminator, a blank area, a marker indicating that the file content is less than half full, and the memory address of the next memory block.
[0089] Whitespace character: Empty bytes in a disk block / memory block, excluding valid characters.
[0090] File content terminator: An identifier that follows the file content and indicates the end of the current block of file content.
[0091] File content less than half flag: When the file content in a disk block / memory block is less than half of the file content area storage space, this flag is set to determine whether disk blocks / memory blocks can be merged after the operation is completed.
[0092] Next sector address: The address that identifies the starting sector of the next disk block / memory block containing the file content.
[0093] Next memory address: In memory storage, this is the starting address of the next memory block where the file content is located.
[0094] The technical solutions provided in this application can be applied to scenarios where disk file content is inserted or deleted, and especially to scenarios where file content stored in memory or on disk in the form of data blocks is modified.
[0095] Existing file systems, when performing file editing operations, first need to read the file content from the disk into memory, then the operating system performs write operations on the file content in memory, and finally copy the edited file content in memory to the disk. During the write operation of the file content in memory, if insertion or deletion operations occur at any position other than the beginning and end of the file, after an insertion operation, new file content is inserted, and the original file content after the insertion point needs to be shifted forward; after a deletion operation, the original file content is deleted, and the original file content after the deletion point needs to be adjusted forward. This large-scale forward or backward shifting of file content consumes CPU time and reduces execution efficiency. Furthermore, during the process of writing the edited file content in memory to the disk, all file content in memory must be rewritten to the disk, even if the file has only undergone minor changes, making the write process time-consuming and inefficient.
[0096] To address the above issues, files are stored in fixed-size blocks in both memory and disk. This involves dividing memory into multiple memory blocks with identical storage space, and dividing the disk into multiple disk blocks with identical storage space. When modifying the file content in memory, only the specific memory block is operated on, while other memory blocks remain unchanged. This reduces CPU execution time and improves efficiency. Similarly, when writing the modified file content from memory to disk, only the content of the target memory block needs to be synchronized to the corresponding disk block, while other disk blocks remain unchanged. This reduces write time and improves efficiency. By storing file content in fixed-size blocks, the entire modification process is time-efficient and highly effective.
[0097] The technical solution of this application and how it solves the above-mentioned technical problems will be described in detail below with specific embodiments. These specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described again in some embodiments. The embodiments of this application will be described below with reference to the accompanying drawings.
[0098] Figure 5 This is a flowchart illustrating a method for processing file content according to an embodiment of this application. This method can be executed by software and / or hardware devices, such as electronic devices like terminals or servers. For example, please refer to [link to example]. Figure 5 As shown, the methods for processing the content of this file may include:
[0099] S501, In response to a file content modification instruction, determine the second memory block to be modified from among a plurality of first memory blocks stored in memory.
[0100] In this step, the file is typically split into multiple non-contiguous memory blocks for storage. Each memory block has a fixed storage size. The specific structure of the memory blocks can be found in [link to relevant documentation]. Figure 3 and Figure 4 As shown in the diagram. Each memory block stored in memory is the first memory block, and the second memory block can be understood as the memory block where the file content will be modified.
[0101] For example, the file content modification command can be triggered by the user through a touch display screen, or by an input device such as a mouse or keyboard of an electronic device, or by voice. The specific triggering method of the file content modification command is not limited in this embodiment.
[0102] S502. Modify the file content in the second memory block according to the file content modification instruction to obtain the target memory block.
[0103] For example, the file content in the second memory block can be modified according to the file content modification instruction, the changed memory block in memory can be identified, and the changed memory block can be identified as the target memory block. The file content modification instruction can be used to instruct the file content to be inserted or deleted.
[0104] Specifically, after the electronic device modifies the file content in the second memory block according to the file content modification instruction, it can identify all memory blocks in the first memory block whose content has changed. In this way, subsequent processing can focus only on the memory blocks whose content has changed, while the memory blocks whose content has not changed remain unchanged. This reduces the amount of data processed and improves the efficiency of file modification.
[0105] The following sections will explain in detail how to determine the changed memory blocks in memory when file content modification instructions are used to indicate insertion or deletion operations on file content.
[0106] In one possible implementation, a file content modification instruction can be used to instruct the insertion of file content. For example, based on this instruction, the insertion position of the file content to be inserted can be determined. Then, based on the insertion position, the second memory block is divided into a first sub-memory block and a second sub-memory block. The file content to be inserted is then inserted into the first sub-memory block, and the storage position of the second sub-memory block is modified. Based on the first sub-memory block after the insertion and the second sub-memory block after the modification, the changed memory block is determined.
[0107] Specifically, if the sum of the number of bytes of the file content to be inserted and the number of bytes of the original file content in the first sub-memory block is greater than the preset storage space size corresponding to the file content in the memory block, a new memory block is created. The remaining file content after inserting the file content into the first sub-memory block is then inserted into the new memory block. The first sub-memory block after inserting the file content, the second sub-memory block after modifying its position, and the new memory block after inserting the file content are defined as the changed memory blocks.
[0108] In this step, there is a one-to-one correspondence between file content and byte count. The byte count represents the amount of storage space occupied by the file content in the memory block. A new memory block can be understood as a newly inserted free memory block, which does not occupy any bytes.
[0109] Specifically, Figure 6 This is a diagram illustrating the insertion operation of file content into the second memory block, as shown below. Figure 6 As shown, when performing an insertion operation on the second memory block 601, the position of the file content to be inserted is first located. At the position of the file content to be inserted, the second memory block 601 is split into two memory blocks. That is, the file content before the insertion position in the second memory block remains in the second memory block 601. Since the file content in the second memory block 601 has changed, the second memory block 601 is renamed as the first sub-memory block 602. The file content after the insertion position in the second memory block 601 is placed into a new free memory block, which is named the second sub-memory block 603, and the storage location of the second sub-memory block 603 is modified. Next, the file content to be inserted is sequentially inserted after the existing file content in the first sub-memory block 602. At this time, if the storage space of the first sub-memory block 602 is exhausted, but there is still uninserted file content to be inserted, the uninserted file content to be inserted is inserted into a new free memory block, which is named the new memory block 604. The first sub-memory block 602 after inserting the file content, the second sub-memory block 603 after modifying its position, and the new memory block 604 after inserting the file content are identified as the memory blocks that have changed.
[0110] For example, if each memory block has a storage space of 2KB and the file content area has a storage space of 2030 bytes, and if the file content in the second memory block occupies bytes 1-1698, and it is necessary to insert 788 bytes of content after byte 1066, then the file content in the second memory block is divided into two memory blocks at the insertion point. Bytes 1-1066 of the file content remain in the original second memory block and are renamed the first sub-memory block. Bytes 1067-1098 of the file content are stored in a new free memory block. In the first sub-memory block, the memory address of the second sub-memory block is modified. Bytes 1-964 of the file content to be inserted are inserted after bytes 1-1066 of the original content in the first sub-memory block. At this point, the storage space of the file content area in the first sub-memory block is full. Bytes 965-788 of the file content to be inserted are then inserted into another new free memory block, which is named the new memory block. Bytes 965-788 of the file content to be inserted are then inserted into bytes 1-178 of the file content area in the new memory block. The insertion operation is now complete.
[0111] In this embodiment, when inserting file content, it is only necessary to determine the second memory block according to the insertion position, and divide the second memory block into a first sub-memory block and a second sub-memory block according to the insertion position. The file content to be inserted is inserted into the first sub-memory block and the new memory block. Only the first sub-memory block, the second sub-memory block and the new memory block need to be operated on, and other memory blocks do not need to be operated on, which can reduce CPU execution time and improve execution efficiency.
[0112] Furthermore, since a memory block changes after the insertion operation, the memory address of the next memory block stored within that block will also change. See also... Figure 6When the first sub-memory block 602 after inserting file content, the second sub-memory block 603 after modifying its position, and the new memory block 604 after inserting file content are determined to be memory blocks that have changed, the memory addresses of these three memory blocks change. Therefore, the memory addresses of the next memory blocks stored in the memory blocks preceding the first sub-memory block 602 after inserting file content, the memory blocks preceding the first sub-memory block 602 after inserting file content, and the new memory blocks 604 after inserting file content will change. At the same time, when the second memory block 601 is split into the second sub-memory block 603, the file content after the insertion position in the second memory block 601 is placed into a new free memory block. The free memory block after inserting file content changes from a free memory block to the second sub-memory block 603 containing file content, and the memory address of the next memory block stored therein will also change. Finally, the memory addresses stored in the first sub-memory block 602 after inserting the file content, the second sub-memory block 603 after modifying its position, the new memory block 604 after inserting the file content, and the memory block 605 preceding the first sub-memory block 602 after inserting the file content are all modified accordingly.
[0113] Furthermore, to reduce memory block usage, memory blocks with smaller file sizes can be merged. The specific steps are as follows: First, determine if a third memory block exists in the first sub-memory block after inserting file content, the second sub-memory block after modification, and the new memory block after inserting file content. The file content in the first sub-memory block, the second sub-memory block after modification, and the new memory block after inserting file content, has a file content size less than a first preset value (the first preset value is less than or equal to half the preset storage space size corresponding to the file content in the memory block). If such a block exists, then determine if the file content size in the fourth memory block is less than the first preset value. The fourth memory block is the memory block preceding and / or following the third memory block. If the file content size in the fourth memory block is less than the first preset value, then merge the third and fourth memory blocks to obtain a first merged memory block. Use the first merged memory block to update the changed memory blocks.
[0114] Specifically, Figure 7 This is a diagram illustrating the merging of memory blocks after an insertion operation, as shown below. Figure 7As shown, firstly, it is determined whether the number of bytes of the file content in the changed memory block is less than a first preset value, that is, half of the preset storage space size corresponding to the file content in the memory block. If it is less, then the memory block is the third memory block 702. The memory block 703 before and / or the memory block 707 after the third memory block 702 is defined as the fourth memory block. It is further determined whether the number of bytes of the file content in the fourth memory block is also less than the first preset value. If the fourth memory block 707 is less than the first preset value, then the third memory block 702 and the fourth memory block 707 are merged to obtain the first merged memory block 704. At the same time, a memory block 705 is released.
[0115] Furthermore, if a first merged memory block exists, the memory address of the next memory block stored within that block will also change. See also... Figure 7 When a first merged memory block 704 exists, the memory addresses of the next memory blocks stored in the first merged memory block 704, the memory block 703 preceding the first merged memory block, and the memory blocks 701 and 706 preceding other changed memory blocks may change. The stored memory addresses that need to be modified should be modified accordingly.
[0116] In this scheme, after the insertion operation, the changed memory block is merged with the adjacent memory block, which can reduce the memory block occupation and release free memory blocks.
[0117] In another possible implementation, file content modification instructions can be used to instruct the deletion of file content. For example, based on the file content modification instructions, the target file content in the second memory block can be deleted, and the other file content in the second memory block except for the target file content can be shifted to obtain a modified second memory block. Based on the modified second memory block, the memory blocks that have changed are determined.
[0118] For example, the content of the target file can be understood as the content of the file to be deleted.
[0119] Specifically, Figure 8 This is a schematic diagram illustrating a deletion operation on the contents of a second memory block file, provided as an embodiment of this application. Figure 8 As shown, after deleting the target file content in the second memory block, the modified second memory block 801 is obtained, and the file content after the deleted file content in the second memory block is adjusted forward.
[0120] For example, each memory block has a storage space of 2KB, and the file content area has a storage space of 2030 bytes. If the file content in the second memory block occupies bytes 1-1698, and the file content corresponding to bytes 6-18 needs to be deleted, then after deleting the file content corresponding to bytes 6-18, the file content corresponding to bytes 19-1698 will be moved forward, and the deletion operation will be completed.
[0121] In this solution, when performing a deletion operation, it is only necessary to find the memory block containing the file content to be deleted, delete the file content in that memory block, and leave the file content in other memory blocks unchanged. This reduces CPU execution time and improves execution efficiency.
[0122] Furthermore, after the file content is modified, the memory address of the next memory block stored in the memory block will also change. That is, if the file content in the second memory block 801 is deleted, the memory address of the second memory block 801 will change, and the memory address of the next memory block stored in the previous memory block 802 of the second memory block 801 will change accordingly. The memory address that needs to be modified will be modified accordingly.
[0123] Furthermore, to reduce memory block usage, memory blocks with smaller file sizes can be merged. Specifically, it's determined whether the number of bytes in the modified second memory block is less than a first preset value, which is less than or equal to half the preset storage space size corresponding to the file content in the memory block. If the number of bytes in the modified second memory block is less than the first preset value, and the number of bytes in the fifth memory block is also less than the first preset value, then the modified second memory block and the fifth memory block are merged to obtain a second merged memory block. The fifth memory block is the memory block preceding and / or following the modified second memory block. The changed memory blocks are then updated using the second merged memory block.
[0124] Specifically, Figure 9 This is a diagram illustrating the merging of memory blocks after a deletion operation, as shown below. Figure 9 As shown, firstly, it is determined whether the number of bytes of the file content in the modified second memory block 901 and the preceding memory block 903 and / or the following memory block 902 is less than a first preset value, that is, half of the preset storage space size corresponding to the file content in the memory block. If both the modified second memory block 901 and the following memory block 902 are less than the preset value, then the two memory blocks 901 and 902 are merged to obtain the second merged memory block 904, and at the same time, a memory block 905 is released.
[0125] Furthermore, when a second merged memory block exists, the memory address of the next memory block stored within that block will also change. See also Figure 9 After merging two memory blocks 901 and 902, the memory addresses stored in the second merged memory block 904 and the memory block 903 preceding the second merged memory block may change.
[0126] In this scheme, after the deletion operation, the deleted memory block is merged with the adjacent memory blocks, which can reduce the memory block usage and release free memory blocks.
[0127] S503. Replace the file content in the second disk block corresponding to the second memory block with the file content in the target memory block, while keeping other disk blocks in the disk unchanged. The disk includes multiple first disk blocks that correspond one-to-one with the first memory block, and the other disk blocks are the disk blocks in the first disk blocks other than the second disk block.
[0128] In this step, there is a one-to-one correspondence between disk blocks on the disk and memory blocks in memory. Before replacing the file content in a disk block, each disk block stored on the disk can be considered as the first disk block, corresponding to the first memory block. The second disk block can be understood as the disk block whose file content will be replaced, corresponding to the second memory block.
[0129] For example, Figure 10 This is a schematic diagram illustrating how file content is written from a memory block to a disk block after an insertion operation, as provided in an embodiment of this application. Figure 11 This application provides a schematic diagram illustrating the writing of file content from a memory block to a disk block after a deletion operation, as shown in the embodiment of the present application. Figure 10 and Figure 11 As shown, the file content in the changed memory block replaces the file content in the corresponding disk block; the file content in other unchanged memory blocks does not need to be rewritten to the disk block. For example, see... Figure 10When writing file content from memory blocks to disk blocks after an insertion operation, if the first sub-memory block 1001 after inserting the file content, the second sub-memory block 1002 after modifying its position, and the new memory block 1003 after inserting the file content are changed memory blocks that have not been merged, the disk blocks corresponding to these three changed memory blocks include one original disk block 1004 and two newly added free disk blocks 1005 and 1006. The file content in the original disk block 1004 is replaced with the file content in the first sub-memory block 1001 after inserting the file content. The file content in the second sub-memory block 1002 after modifying its position and the new memory block 1003 after inserting the file content are written to the two newly added free disk blocks 1005 and 1006, respectively. Other disk blocks remain unchanged. See also Figure 11 When the file content is written from the memory block to the disk block after the deletion operation, the second memory block is deleted but not merged, resulting in the target memory block 1101. The file content in the original disk block 1102 is replaced with the file content in the target memory block 1101, while the other disk blocks remain unchanged.
[0130] Furthermore, based on the changed disk blocks, the sector address of the next disk block stored in the corresponding disk block is modified. For example, see... Figure 10 The process of writing file content from a memory block to a disk block shows that the disk blocks whose sector addresses need to be modified include an existing disk block 1005 corresponding to the three changed memory blocks, two newly added free disk blocks 1005 and 1006, and the disk block 1007 preceding the existing disk block. See also... Figure 11 The process of writing the file content from the memory block to the disk block shows that the disk blocks whose sector addresses need to be modified for the next disk block include the original disk block 1102 and the disk block preceding the original disk block 1103. Finally, the sector addresses that need to be modified are modified accordingly.
[0131] In this solution, since the speed of running in memory is much faster than that of running on disk, file modification operations are all performed in memory blocks. After modifying the file content in the memory block, the modified file content in the memory block replaces the file content in the corresponding disk block, which can reduce the time taken for the entire operation process.
[0132] The file content processing method provided in this application, in response to a file content modification instruction, determines a second memory block to be modified from multiple first memory blocks stored in memory. Based on the file content modification instruction, the file content in the second memory block is modified to obtain a target memory block. The file content in the second disk block corresponding to the second memory block is replaced with the file content in the target memory block, while keeping other disk blocks unchanged. The disk includes multiple first disk blocks that correspond one-to-one with the first memory blocks, and the other disk blocks are the disk blocks in the first disk blocks excluding the second disk block. In this application, when modifying the file content in memory, only the specific memory block is operated on, while other memory blocks remain unchanged, which reduces CPU execution time and improves execution efficiency. Simultaneously, during the process of writing the modified file content in memory to the disk, only the file content in the modified target memory block needs to be synchronized to the corresponding disk block, while other disk blocks remain unchanged, thereby reducing the writing time and improving efficiency. By storing the file content in fixed-size blocks, the entire modification process is time-efficient and efficient.
[0133] Figure 12 This is a schematic diagram of the structure of a file content processing device 120 provided in an embodiment of this application. For example, please refer to [link to example diagram]. Figure 12 As shown, the document content processing device 120 includes:
[0134] The determination module 1201 is used to determine the second memory block to be modified from a plurality of first memory blocks stored in memory in response to a file content modification instruction;
[0135] Modification module 1202 is used to modify the file content in the second memory block according to the file content modification instruction to obtain the target memory block;
[0136] The replacement module 1203 is used to replace the file content in the second disk block corresponding to the second memory block with the file content in the target memory block, while keeping other disk blocks in the disk unchanged. The disk includes multiple first disk blocks that correspond one-to-one with the first memory block, and the other disk blocks are the disk blocks in the first disk blocks other than the second disk block.
[0137] Optionally, modify module 1202, specifically for:
[0138] Based on the file content modification instructions, the file in the second memory block is modified, and the memory blocks in memory that have changed are identified.
[0139] The memory block that has changed is identified as the target memory block.
[0140] Optionally, the file content modification command is used to instruct the insertion of file content.
[0141] Modify module 1202, specifically for:
[0142] Based on the file content modification instructions, determine the insertion position of the file content to be inserted.
[0143] Based on the insertion position, the second memory block is divided into a first sub-memory block and a second sub-memory block.
[0144] Insert the contents of the file to be inserted into the first sub-memory block, and modify the storage location of the second sub-memory block.
[0145] The changed memory blocks are determined based on the first sub-memory block after the file content is inserted and the second sub-memory block after the position is modified.
[0146] Optionally, modify module 1202, specifically for:
[0147] If the sum of the number of bytes of the file content to be inserted and the number of bytes of the original file content in the first sub-memory block is greater than the preset storage space size corresponding to the file content in the memory block, then a new memory block is created.
[0148] The remaining content of the file to be inserted, obtained after inserting the content of the file to be inserted into the first sub-memory block, is then inserted into the new memory block.
[0149] The first sub-memory block after inserting the file content, the second sub-memory block after modifying its position, and the new memory block after inserting the file content are identified as the memory blocks that have changed.
[0150] Optionally, modify module 1202, specifically for:
[0151] In the first sub-memory block after inserting file content, the second sub-memory block after modifying its position, and the new memory block after inserting file content, it is determined whether there is a third memory block whose file content has fewer bytes than a first preset value, wherein the first preset value is less than or equal to half of the preset storage space size corresponding to the file content in the memory block.
[0152] If it exists, then determine whether the number of bytes of the file content in the fourth memory block is less than the first preset value. The fourth memory block is the memory block before the third memory block and / or the memory block after the third memory block.
[0153] If the number of bytes of the file content in the fourth memory block is less than the first preset value, then the third memory block and the fourth memory block are merged to obtain the first merged memory block.
[0154] The changed memory blocks are updated using the first merged memory block.
[0155] Optionally, the file content modification command is used to instruct the deletion of file content.
[0156] Modify module 1202, specifically for:
[0157] According to the file content modification instruction, the target file content in the second memory block is deleted, and the other file content in the second memory block except for the target file content is shifted to obtain the modified second memory block.
[0158] Based on the modified second memory block, determine the memory blocks that have changed.
[0159] Optionally, modify module 1202, specifically for:
[0160] Determine whether the number of bytes of the file content in the modified second memory block is less than a first preset value. The first preset value is less than or equal to half of the preset storage space size corresponding to the file content in the memory block.
[0161] If the number of bytes of the file content in the modified second memory block is less than the first preset value, and the number of bytes of the file content in the fifth memory block is less than the first preset value, then the file content in the modified second memory block and the fifth memory block are merged to obtain a second merged memory block; the fifth memory block is the memory block preceding the modified second memory block and / or the memory block following the modified second memory block.
[0162] Update the changed memory blocks in the second merged memory block.
[0163] Figure 13 This is a schematic diagram of the structure of an electronic device 130 provided in an embodiment of this application. For example, please refer to [link / reference]. Figure 13 As shown, the electronic device 130 may include a processor 1301 and a memory 1302; wherein,
[0164] Memory 1302 is used to store computer programs.
[0165] The processor 1301 is used to read the computer program stored in the memory 1302 and execute the file content processing method in the above embodiment according to the computer program in the memory 1302.
[0166] Optionally, the memory 1302 can be either standalone or integrated with the processor 1301. When the memory 1302 is a device independent of the processor 1301, the electronic device 130 may further include a bus for connecting the memory 1302 and the processor 1301.
[0167] Optionally, this embodiment also includes a communication interface, which can be connected to the processor 1301 via a bus. The processor 1301 can control the communication interface to realize the acquisition and transmission functions of the aforementioned electronic device 130.
[0168] For example, in this embodiment of the application, the electronic device 130 can be a terminal or a server, which can be set according to actual needs.
[0169] The electronic device 130 shown in this application embodiment can execute the technical solution of the file content processing method in the above embodiment. Its implementation principle and beneficial effects are similar to those of the file content processing method. Please refer to the implementation principle and beneficial effects of the file content processing method. It will not be repeated here.
[0170] This application also provides a computer-readable storage medium storing computer-executable instructions. When a processor executes the computer-executable instructions, it implements the technical solution of the file content processing method in the above embodiments. The implementation principle and beneficial effects are similar to those of the file content processing method, and can be found in the implementation principle and beneficial effects of the file content processing method, which will not be repeated here.
[0171] This application also provides a computer program product, including a computer program. When the computer program is executed by a processor, it implements the technical solution of the file content processing method in the above embodiments. Its implementation principle and beneficial effects are similar to those of the file content processing method. Please refer to the implementation principle and beneficial effects of the file content processing method. It will not be repeated here.
[0172] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of modules is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple modules or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the mutual coupling or direct coupling or communication connection shown or discussed may be indirect coupling or communication connection through some interfaces, devices, or units, and may be electrical, mechanical, or other forms.
[0173] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs. Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated units described above can be implemented in hardware or in a combination of hardware and software functional units.
[0174] The integrated modules described above, implemented as software functional modules, can be stored in a computer-readable storage medium. These software functional modules, stored in a storage medium, include several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) or processor to execute some steps of the methods of the various embodiments of this application.
[0175] It should be understood that the aforementioned processor can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), etc. A general-purpose processor can be a microprocessor or any conventional processor. The steps of the method disclosed in this invention can be directly manifested as being executed by a hardware processor, or executed by a combination of hardware and software modules within the processor.
[0176] The memory may include high-speed RAM, and may also include non-volatile storage (NVM), such as at least one disk storage device, and may also be a USB flash drive, external hard drive, read-only memory, disk or optical disc, etc.
[0177] The bus can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. Buses can be categorized as address buses, data buses, control buses, etc. For ease of illustration, the buses shown in the accompanying drawings are not limited to a single bus or a single type of bus.
[0178] The aforementioned computer-readable storage medium can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic storage, flash memory, magnetic disk, or optical disk. The storage medium can be any available medium accessible to general-purpose or special-purpose computers.
[0179] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features therein. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of this application.
Claims
1. A method of processing file content, characterized by, The file content is stored in a plurality of first memory blocks of fixed size in the memory, and is stored in a plurality of first disk blocks of fixed size corresponding to the first memory blocks in the disk, comprising: In response to a file content modification instruction, determining a second memory block to be modified from the plurality of first memory blocks stored in the memory; After modifying the file in the second memory block according to the file content modification instruction, determining a memory block changed in the memory as a target memory block; Replacing the file content in a second disk block corresponding to the second memory block in the disk with the file content in the target memory block, and keeping other disk blocks in the disk unchanged, the disk comprising a plurality of first disk blocks corresponding to the first memory blocks one by one, and the other disk blocks being disk blocks other than the second disk block in the first disk blocks; The file content modification instruction is used to indicate an insertion operation on the file content; and after modifying the file content in the second memory block according to the file content modification instruction, determining the memory block changed in the memory, comprising: According to the file content modification instruction, determining an insertion position of the file content to be inserted; According to the insertion position, dividing the second memory block into a first sub-memory block and a second sub-memory block; Inserting the file content to be inserted into the first sub-memory block, and modifying the storage position of the second sub-memory block; If the sum of the byte number of the file content to be inserted and the byte number of the original file content of the first sub-memory block is greater than a preset storage space size corresponding to the file content in the memory block, a new memory block is created; Inserting the remaining file content to be inserted obtained after inserting the file content to be inserted into the first sub-memory block into the new memory block; The first sub-memory block after inserting the file content, the second sub-memory block after modifying the position, and the new memory block after inserting the file content are determined as the changed memory block; Respectively determining whether there is a third memory block with a byte number of file content less than a first preset value in the first sub-memory block after inserting the file content, the second sub-memory block after modifying the position, and the new memory block after inserting the file content, the first preset value being less than or equal to half of the preset storage space size corresponding to the file content in the memory block; If there is, determining whether the byte number of the file content in a fourth memory block is less than the first preset value, the fourth memory block being a previous memory block of the third memory block and / or a next memory block of the third memory block; If the byte number of the file content in the fourth memory block is less than the first preset value, merging the third memory block and the fourth memory block to obtain a first merged memory block; Updating the changed memory block with the first merged memory block.
2. The method of claim 1, wherein, The file content modification instruction is also used to indicate a deletion operation on the file content; and after modifying the file content in the second memory block according to the file content modification instruction, determining the memory block changed in the memory, further comprising: According to the file content modification instruction, the target file content in the second memory block is deleted, and other file content in the second memory block is shifted, so as to obtain a modified second memory block; According to the modified second memory block, the changed memory block is determined.
3. The method of claim 2, wherein, The method according to the modified second memory block, the changed memory block is determined, and the method comprises the steps that: It is judged whether the byte number of the file content in the modified second memory block is less than a first preset value, and the first preset value is less than or equal to half of the preset storage space size corresponding to the file content in the memory block; If the byte number of the file content in the modified second memory block is less than the first preset value, and the byte number of the file content in the fifth memory block is less than the first preset value, the file content in the modified second memory block and the fifth memory block is combined, so as to obtain a second combined memory block; the fifth memory block is the previous memory block of the modified second memory block and / or the next memory block of the modified second memory block; The second combined memory block is determined as the changed memory block.
4. An apparatus for processing contents of a file, characterized by, The file content is stored in a plurality of first memory blocks with fixed size in the memory, and is stored in a plurality of first disk blocks with fixed size corresponding to the first memory blocks in the disk, and the method comprises the steps that: A response module is configured to, in response to a file content modification instruction, determine a second memory block to be modified from a plurality of first memory blocks stored in the memory; A modification module is configured to, after modifying the file in the second memory block according to the file content modification instruction, determine a changed memory block in the memory; and determine the changed memory block as a target memory block; A replacement module is configured to replace the file content in a second disk block corresponding to the second memory block in the disk with the file content in the target memory block, and keep other disk blocks in the disk unchanged, the disk comprises a plurality of first disk blocks corresponding to the first memory blocks one by one, and the other disk blocks are disk blocks other than the second disk block in the first disk blocks; The file content modification instruction is used to indicate an insertion operation on the file content; and the modification module is specifically configured to: According to the file content modification instruction, determine an insertion position of the file content to be inserted; According to the insertion position, divide the second memory block into a first sub-memory block and a second sub-memory block; Insert the file content to be inserted into the first sub-memory block, and modify the storage position of the second sub-memory block; If the sum of the byte number of the file content to be inserted and the byte number of the original file content of the first sub-memory block is greater than the preset storage space size corresponding to the file content in the memory block, a new memory block is created; Insert the remaining file content to be inserted obtained after inserting the file content to be inserted into the first sub-memory block into the new memory block; The first sub-memory block after inserting the file content, the second sub-memory block after modifying the position, and the new memory block after inserting the file content are determined as the changed memory block. Determine whether a third memory block with file content less than a first preset value exists in the first sub-memory block after the file content is inserted, the second sub-memory block after the modification position is modified, and the new memory block after the file content is inserted, the first preset value being less than or equal to half of a preset storage space size corresponding to the file content in the memory block; If the third memory block exists, determine whether the file content in a fourth memory block is less than the first preset value, the fourth memory block being a previous memory block of the third memory block and / or a next memory block of the third memory block; If the file content in the fourth memory block is less than the first preset value, merge the third memory block and the fourth memory block to obtain a first merged memory block; Update the changed memory block by using the first merged memory block.
5. An electronic device, comprising: The method comprises: a memory and a processor; the memory is configured to store a computer program; the processor is configured to read the computer program stored in the memory, and execute the method according to any one of claims 1-3 based on the computer program in the memory.
6. A readable storage medium, having stored thereon a computer program, characterized in that, The computer program stores computer execution instructions, and the computer execution instructions are executed by the processor to implement the method according to any one of claims 1-3.