Method for multiple entities to efficiently utilize limited sharing simultaneously
Technical Field
The invention relates to the field of computer information processing, in particular to a method for efficiently and simultaneously utilizing limited sharing by a plurality of entities.
Background
Memory is one of the important components in a computer, and is the bridge for external memory to communicate with a CPU. All programs in the computer are operated in the memory, so the performance of the memory has great influence on the computer; the internal memory is also called an internal memory and a main memory, and functions to temporarily store operation data in the CPU and data exchanged with an external memory such as a hard disk; as long as the computer is in operation, the operating system transfers data to be operated to the CPU from the memory for operation, and the CPU transmits the result after the operation is finished, so that the operation of the memory also determines the stable operation of the computer.
When multiple programs access the memory, the problem of the utilization rate of the memory is the direction which people often need to pay attention to, when a plurality of programs access the same memory in the prior art, only one lock is distributed to the memory, the program of the lock is obtained first, the memory can be accessed, other programs wait, the lock is released after the access is finished, and other programs have the opportunity to access the memory; this causes the memory to be occupied by a single program all the time, and if the memory occupied by the program is small, the utilization rate of the memory is reduced, and waste is generated, so that the use method of the memory needs to be improved.
Disclosure of Invention
The invention aims to solve the defects in the prior art, and provides a method for efficiently and simultaneously utilizing limited sharing by a plurality of entities.
In order to achieve the above purposes, the technical scheme adopted by the invention is as follows: a method for efficiently and simultaneously utilizing limited sharing by a plurality of entities comprises a memory, and comprises the following steps:
(i) setting the initial address of a memory as pShareStart, dividing the memory into m small memories, wherein m is a positive integer, and using pos i to respectively represent the difference between the starting address of each small memory and the pShareStart, wherein i is any positive integer between 1 and m;
(ii) using pCurPos i to represent the initial address of the current small memory, and initializing four bytes from the position of pCurPos i +0 to the position of pCurPos i +3 to be 1;
(iii) taking the position from pCurPos i +4 to pCurPos i + x as a data storage area of the current small memory, wherein x is the number of bytes of the current memory;
(iv) when the memory is accessed simultaneously through a plurality of programs arranged in a computer, the programs firstly read the first addresses pCurPos i of a plurality of small memories respectively and identify the contents of bytes pCurPos i +0 to pCurPos i +3 of the current small memory read by the programs respectively, if the bytes pCurPos i +0 to pCurPos i +3 are all in a state of being set to 1, the current memory is in an open state, and the programs can carry out access operation on the currently read small memory.
Further, the relationship among pos i, pCurPos i and pShareStart is as follows:
pCurPos 1=pShareStart+pos 1=pShareStart+0=pShareStart;
pCurPos 2=pShareStart+pos 2=pShareStart+1024*1024*1;
........
pCurPos m=pShareStart+pos m=pShareStart+1024*1024*(m-1)。
compared with the prior art, the invention has the following beneficial effects: the invention takes the first 4 bytes of each memory as a lock, so when accessing each small memory, only lock pCurPos i is needed, and unlock pCurPos i is not needed, thus a plurality of small memories can be accessed simultaneously; when accessing each small memory, the range of each memory is divided into several memories, and the size of each memory can be designed according to the total memory amount and the service requirement; taking the first 4 bytes of each memory as a lock for use, initializing the first 4 bytes of each memory to be 1, and indicating that each memory is in an unlocked state; after each block of memory lock is obtained, the memory is accessed from the position of pCurPos i +4, and the whole block of memory is divided into small memories, so that the use efficiency of the memory can be improved, and the performance of the computer is indirectly improved.
Additional advantages, objects, and features of the invention will be set forth in part in the description which follows and in part will become apparent to those having ordinary skill in the art upon examination of the following or may be learned from practice of the invention. The objectives and other advantages of the invention may be realized and attained by the means of the instrumentalities and combinations particularly pointed out hereinafter.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below, and it is obvious that the described embodiments are a part of the embodiments of the present invention, but not all of the embodiments.
Thus, the following detailed description of the embodiments of the present invention is not intended to limit the scope of the invention as claimed, but is merely representative of selected embodiments of the invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
In the above description of the invention, it is noted that the orientation or positional relationship conventionally used in the manufacture of the invention is for convenience in describing and simplifying the invention, and is not intended to indicate or imply that the device or element so referred to must have a particular orientation, be constructed and operated in a particular orientation, and is therefore not to be construed as limiting the invention. Furthermore, the terms "first," "second," and the like are used merely to distinguish one description from another, and are not to be construed as indicating or implying relative importance.
Further, the term "identical" and the like do not mean that the components are absolutely required to be identical, but may have slight differences; the term "perpendicular" merely means that the positional relationship between the components is more perpendicular than "parallel", and does not mean that the structure must be perfectly perpendicular, but may be slightly inclined.
The following description is presented to disclose the invention so as to enable any person skilled in the art to practice the invention. The preferred embodiments in the following description are given by way of example only, and other obvious variations will occur to those skilled in the art.
A method for efficiently and simultaneously utilizing limited sharing by a plurality of entities comprises a memory, and is characterized by comprising the following steps:
(i) setting the initial address of a memory as pShareStart, dividing the memory into m small memories, wherein m is a positive integer, and respectively representing the difference between the starting address of each small memory and the pShareStart by pos i, wherein i is any positive integer between 1 and m;
(ii) using pCurPos i to represent the initial address of the current small memory, and initializing four bytes from the position of pCurPos i +0 to the position of pCurPos i +3 to be 1;
(iii) taking the position from pCurPos i +4 to pCurPos i + x as a data storage area of the current small memory, wherein x is the number of bytes of the current memory;
(iv) when the memory is accessed simultaneously through a plurality of programs arranged in a computer, the programs firstly read the first addresses pCurPos i of a plurality of small memories respectively and identify the contents of bytes pCurPos i +0 to pCurPos i +3 of the current small memory read by the programs respectively, if the bytes pCurPos i +0 to pCurPos i +3 are all in a state of being set to 1, the current memory is in an open state, and the programs can carry out access operation on the currently read small memory.
The relationship between pos i, pCurPos i and pShareStart is:
pCurPos 1=pShareStart+pos 1=pShareStart+0=pShareStart;
pCurPos 2=pShareStart+pos 2=pShareStart+1024*1024*1;
........
pCurPos m=pShareStart+pos m=pShareStart+1024*1024*(m-1)。
the foregoing shows and describes the general principles, essential features, and advantages of the invention.
It will be understood by those skilled in the art that the present invention is not limited to the embodiments described above, which are merely illustrative of the principles of the invention, but that various changes and modifications may be made without departing from the spirit and scope of the invention, which fall within the scope of the invention as claimed.
The scope of the invention is indicated by the appended claims and their equivalents.