CN103345416A - Method and system for acquiring array length - Google Patents

Method and system for acquiring array length Download PDF

Info

Publication number
CN103345416A
CN103345416A CN2013103203713A CN201310320371A CN103345416A CN 103345416 A CN103345416 A CN 103345416A CN 2013103203713 A CN2013103203713 A CN 2013103203713A CN 201310320371 A CN201310320371 A CN 201310320371A CN 103345416 A CN103345416 A CN 103345416A
Authority
CN
China
Prior art keywords
array
array length
length
described array
intelligent pointer
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN2013103203713A
Other languages
Chinese (zh)
Inventor
李旭
阮航
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
World (Shanghai) Technology Development Co., Ltd.
Original Assignee
Shenzhen Temobi Science and Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shenzhen Temobi Science and Technology Co Ltd filed Critical Shenzhen Temobi Science and Technology Co Ltd
Priority to CN2013103203713A priority Critical patent/CN103345416A/en
Publication of CN103345416A publication Critical patent/CN103345416A/en
Pending legal-status Critical Current

Links

Images

Abstract

The embodiment of the invention discloses a method and a system for acquiring array length. By adopting the method and system, the array length can be accessed through a smart pointer in C++ language, and the operation is simple. The method comprises the following steps of: acquiring array length and array type; reconstructing the smart pointer by utilizing the array length and the array type; and acquiring the array length through the smart pointer.

Description

A kind of method and system of obtaining array length
Technical field
The present invention relates to field of computer technology, be specifically related to a kind of method and system of obtaining array length.
Background technology
C Plus Plus is a kind of Object-oriented Programming Design language, grows up on the basis of C language.A lot of java standard libraries are arranged in C Plus Plus, and it is the C++ programming function that provides the foundation.In existing C ++ in the java standard library, a kind of intelligent pointer: std::auto_ptr is provided, this intelligent pointer is mainly used in common pointer object is encapsulated and operates, particularly, in the boost storehouse of C++, provide shared_array class, array pointer is encapsulated, the operation of access array still only is provided, and the operation of not obtaining array length.Owing to do not know the length of array, when using this intelligent pointer, need remember the length of array or the length of calculating array pointer in addition, thereby bring extra code and extra central processing unit (CPU, Central Processing Unit) to consume.
Summary of the invention
At above-mentioned defective, the embodiment of the invention provides a kind of method and system of obtaining array length, can realize directly obtaining array length by intelligent pointer in C++, and is simple and convenient.
The embodiment of the invention provides a kind of method of obtaining array length, comprising:
Obtain array length and array type;
Utilize described array length and described array type that intelligent pointer is re-constructed;
Obtain described array length by intelligent pointer.
Further, described described array length and the described array type of utilizing re-constructs intelligent pointer, specifically comprises:
Described array length is saved as the value that array encapsulates the array length variable of having set in the class, so that described intelligent pointer obtains described array length by visiting described array length variable;
Create array according to described array length and described array type.
Further, describedly obtain described array length by intelligent pointer, specifically comprise:
Visit described array length variable by intelligent pointer and obtain described array length.
Further, comprise before obtaining array length and array type described:
The array length variable of described array length is set in array encapsulation class.
The embodiment of the invention also provides a kind of system that obtains array length, comprising:
Acquiring unit is used for obtaining array length and array type;
Initialization unit is used for utilizing described array length and described array type that intelligent pointer is re-constructed;
Addressed location is used for obtaining described array length by the intelligent pointer after the initialization.
Further, described initialization unit comprises:
Preserve the unit, be used for described array length is saved as the value of the array length variable that array encapsulation class set, so that described intelligent pointer obtains described array length by visiting described array length variable;
The array creating unit is used for creating array according to described array length and described array type.
Further, described addressed location comprises:
First addressed location is used for visiting described array length variable by intelligent pointer and obtains described array length.
As can be seen from the above technical solutions, the embodiment of the invention has the following advantages:
After obtaining array length and array type in the embodiment of the invention, re-construct according to this array length and array type, make intelligent pointer can directly obtain array length, compared with prior art, the embodiment of the invention can realize in C++ that intelligent pointer directly visits array length, and is simple to operate.
Description of drawings
In order to be illustrated more clearly in the technical scheme of the embodiment of the invention, to do to introduce simply to the accompanying drawing of required use in the embodiment of the invention below, apparently, accompanying drawing in describing below only is some embodiments of the present invention, for those of ordinary skills, under the prerequisite of not paying creative work, can also obtain other accompanying drawing according to these accompanying drawings.
A kind of method flow diagram that obtains array length that Fig. 1 provides for the embodiment of the invention;
A kind of another process flow diagram of method that obtains array length that Fig. 2 provides for the embodiment of the invention;
A kind of system's basic structure synoptic diagram that obtains array length that Fig. 3 provides for the embodiment of the invention;
A kind of another basic structure synoptic diagram of system that obtains array length that Fig. 4 provides for the embodiment of the invention;
A kind of another basic structure synoptic diagram of system that obtains array length that Fig. 5 provides for the embodiment of the invention.
Embodiment
Below in conjunction with the accompanying drawing of the embodiment of the invention, the technical scheme in the embodiment of the invention is clearly and completely described, obviously, described embodiment only is the present invention's part embodiment, rather than whole embodiment.Based on the embodiment among the present invention, those of ordinary skills belong to the scope of protection of the invention not making the every other embodiment that obtains under the creative work prerequisite.
The embodiment of the invention provides a kind of method of obtaining array length, is used for C++ and gets access to array length by intelligent pointer.
As shown in Figure 1, the embodiment of the invention provides a kind of method of obtaining array length, comprising:
Step S10, obtain array length and array type;
Wherein, in C++, can visit array length according to intelligent pointer, at first, need obtain the relevant information of the array of required foundation from the information of user's input, this relevant information can be array length and array type.
Be understandable that array type can be character string string array, int array etc., all array types all are applicable to the embodiment of the invention.
Step S20, utilize described array length and described array type that intelligent pointer is re-constructed;
Wherein, according to the array length that gets access to and array type, utilize array encapsulation class that intelligent pointer is reconstructed and make, just carry out the establishment of actual array, in order to realize the purpose of intelligent pointer visit array length.
Step S30, obtain described array length by intelligent pointer.
Wherein, according to array length and array type, utilize on the boost::shared_pr template base of array encapsulation class intelligent being reconstructed made, and then can utilize the form of intelligent pointer visit array length variable to obtain array length.
Particularly, before above-mentioned steps S10, also comprise step: the array length variable that described array length is set in array encapsulation class.
Wherein, in array encapsulation class, the array length variable length that preserves array length is set, and can be set to public by described array length variable length, and then in whole procedure, can visit this array length variable length.
The embodiment of the invention re-constructs intelligent pointer by utilizing array length and array type, makes it possible to get access to array length by intelligent pointer, and is for C++ provides the more convenient method of obtaining array length, simple to operate.
See also Fig. 2, a kind of another process flow diagram of method that obtains array length that Fig. 2 provides for the embodiment of the invention, as shown in Figure 2, a kind of method of obtaining array length can comprise:
Step 210, obtain array length and array type;
Be understandable that in C++, array encapsulation class is normally defined template<class T〉class JArray, the encapsulation class of array is mainly used in array is encapsulated.As a rule, the array length of each definition can not change, and then can increase an array length variable length in the class by encapsulating in array, and this array length variable length is preserved.Particularly, the access modifier of this array length variable length is set to public public.
Simultaneously, the template class of definition intelligent pointer, template<class AT for example〉class JPtr<JArray<AT 〉, this intelligent pointer can be reconstructed based on the boost::shared_pr template base of C++ array encapsulation class and make, particularly, the building method that needs heavily loaded boost::shared_pr makes intelligent pointer can accept array encapsulation class and re-constructs.
After receiving the relevant information of array, will obtain array length and array type, for example this array length will be taken as x, this array type will be taken as int.
Step 220, described array length is saved as the value of the array length variable of having set in the array encapsulation class, so that described intelligent pointer obtains described array length by visiting described array length variable;
Wherein, when utilizing intelligent pointer reception array encapsulation class to construct, concrete make is:
JPtr<int>P1(new?JArray<int>(x))
Wherein, P1 is intelligent pointer, and array type is int, and array length is x, and x is a positive integer arbitrarily, and expression needs the length of the array of establishment.
According to above-mentioned make, at first array length x is saved as the value of the array length variable length that sets in the array encapsulation class.
Step 230, create array according to described array length and described array type;
Create array according to accessed array length x and array type int, the array of establishment is new int (x).
Step 240, visit described array length variable by intelligent pointer and obtain described array length.
Wherein, utilize the array length variable length in the intelligent pointer visit array encapsulation class then can get access to array length, definition one new array JArray*array in program for example can be JArray*array=P1.array.length by the mode that intelligent pointer is visited this array length so.
What the embodiment of the invention was concrete is according to the array length and the array type that get access to, with the value of array length as the array length variable in the array encapsulation class, and in array encapsulation class, create array according to this array length and array type, and then can be implemented among the C++ by intelligent pointer visit array length, simple to operate.
As shown in Figure 3, the embodiment of the invention also provides a kind of system that obtains array length, can comprise:
Acquiring unit 310 is used for obtaining array length and array type;
Initialization unit 320 is used for utilizing described array length and described array type that intelligent pointer is re-constructed;
Addressed location 330 is used for obtaining described array length by intelligent pointer.
Further, as shown in Figure 4, described initialization unit 320 comprises:
Preserve unit 410, be used for described array length is saved as the value of the array length variable that array encapsulation class set, so that described intelligent pointer obtains described array length by visiting described array length variable;
Array creating unit 420 is used for creating array according to described array length and described array type.
Described addressed location 330 comprises first addressed location 430, is used for visiting described array length variable by intelligent pointer and obtains described array length.
As shown in Figure 5, the system that obtains array length that the embodiment of the invention provides also comprises unit 340 is set, and is used for arranging in array encapsulation class the array length variable of described array length.
Be understandable that, acquiring unit 310 gets access to array length and array type from the array relevant information of user's input, preservation unit 410 in the initialization unit 320 is saved in the array length that gets access in the array length variable that defines in the array encapsulation class, value as the array length variable, array creating unit 420 is carried out actual number according to array length and array type again and is formed and build, addressed location then can carry out the visit of array length by intelligent pointer afterwards, gets access to array length.
As seen, after the embodiment of the invention is obtained array length and array type, re-construct according to this array length and array type, make intelligent pointer can directly obtain array length, can realize in C++ that intelligent pointer directly visits array length, simple to operate.
One of ordinary skill in the art will appreciate that all or part of step that realizes in above-described embodiment method is to instruct relevant hardware to finish by program, described program can be stored in a kind of computer-readable recording medium, the above-mentioned storage medium of mentioning can be ROM (read-only memory), disk or CD etc.
More than a kind of method and system of obtaining array length provided by the present invention are described in detail, for one of ordinary skill in the art, thought according to the embodiment of the invention, part in specific embodiments and applications all can change, in sum, this description should not be construed as limitation of the present invention.

Claims (10)

1. a method of obtaining array length is characterized in that, comprising:
Obtain array length and array type;
Utilize described array length and described array type that intelligent pointer is re-constructed;
Obtain described array length by intelligent pointer.
2. method according to claim 1 is characterized in that, described described array length and the described array type of utilizing re-constructs intelligent pointer, specifically comprises:
Described array length is saved as the value that array encapsulates the array length variable of having set in the class, so that described intelligent pointer obtains described array length by visiting described array length variable;
Create array according to described array length and described array type.
3. method according to claim 2 is characterized in that, describedly obtains described array length by intelligent pointer, specifically comprises:
Visit described array length variable by intelligent pointer and obtain described array length.
4. according to each described method of claim 1~3, it is characterized in that, comprise before obtaining array length and array type described:
The array length variable of described array length is set in array encapsulation class.
5. method according to claim 4 is characterized in that, the attribute of described array length variable is public public.
6. a system that obtains array length is characterized in that, comprising:
Acquiring unit is used for obtaining array length and array type;
Initialization unit is used for utilizing described array length and described array type that intelligent pointer is re-constructed;
Addressed location is used for obtaining described array length by intelligent pointer.
7. system according to claim 6 is characterized in that, described initialization unit comprises:
Preserve the unit, be used for described array length is saved as the value of the array length variable that array encapsulation class set, so that described intelligent pointer obtains described array length by visiting described array length variable;
The array creating unit is used for creating array according to described array length and described array type.
8. system according to claim 6 is characterized in that, described addressed location comprises:
First addressed location is used for visiting described array length variable by intelligent pointer and obtains described array length.
9. according to each described system of claim 6~8, it is characterized in that, also comprise the unit is set, be used for arranging in array encapsulation class the array length variable of described array length.
10. system according to claim 9 is characterized in that, the attribute of described array length variable is public public.
CN2013103203713A 2013-07-26 2013-07-26 Method and system for acquiring array length Pending CN103345416A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN2013103203713A CN103345416A (en) 2013-07-26 2013-07-26 Method and system for acquiring array length

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN2013103203713A CN103345416A (en) 2013-07-26 2013-07-26 Method and system for acquiring array length

Publications (1)

Publication Number Publication Date
CN103345416A true CN103345416A (en) 2013-10-09

Family

ID=49280214

Family Applications (1)

Application Number Title Priority Date Filing Date
CN2013103203713A Pending CN103345416A (en) 2013-07-26 2013-07-26 Method and system for acquiring array length

Country Status (1)

Country Link
CN (1) CN103345416A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106325821A (en) * 2015-07-07 2017-01-11 Tcl集团股份有限公司 Pointer management method and apparatus
CN109117142A (en) * 2018-07-19 2019-01-01 北京理工大学 A kind of fundamental type reconstructing method based on variable association tree

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6105041A (en) * 1996-12-12 2000-08-15 Microsoft Corporation Using three-state references to manage garbage collection of referenced objects
US7165237B2 (en) * 2003-03-20 2007-01-16 Microsoft Corporation Data store for arbitrary data types with type safe storage and retrieval

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6105041A (en) * 1996-12-12 2000-08-15 Microsoft Corporation Using three-state references to manage garbage collection of referenced objects
US7165237B2 (en) * 2003-03-20 2007-01-16 Microsoft Corporation Data store for arbitrary data types with type safe storage and retrieval

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
NOAM: "《http://download.csdn.net/detail/noam/5168506》", 22 March 2013 *
疯狂-的-蜗牛: "《http://blog.csdn.net/mfcing/article/details/7400999》", 27 March 2012 *

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106325821A (en) * 2015-07-07 2017-01-11 Tcl集团股份有限公司 Pointer management method and apparatus
CN106325821B (en) * 2015-07-07 2018-11-06 Tcl集团股份有限公司 A kind of pointer management method and device
CN109117142A (en) * 2018-07-19 2019-01-01 北京理工大学 A kind of fundamental type reconstructing method based on variable association tree
CN109117142B (en) * 2018-07-19 2020-11-24 北京理工大学 Basic type reconstruction method based on variable association tree

Similar Documents

Publication Publication Date Title
TWI709866B (en) Equipment model identification method, device and processing equipment
CN111767143A (en) Transaction data processing method, device, equipment and system
CN111355816B (en) Server selection method, device, equipment and distributed service system
CN109885291A (en) A kind of code automatic generation method and code generator
US10164828B2 (en) Geospatial based management of configuration profiles
CN103150154B (en) The implementation method and device of a kind of application plug
CN111767144B (en) Transaction route determination method, device, equipment and system for transaction data
TWI694700B (en) Data processing method and device, user terminal
CN104683386A (en) Pile service implementation method and device capable of customizing response
Chung et al. Cloud computing system based on wireless sensor network
CN110301131B (en) Context-aware device permissions for hierarchical device collections
CN106557307B (en) Service data processing method and system
CN106095698A (en) OO caching write, read method and device
CN113506364A (en) Model creation method, system, device and storage medium
CN108234299A (en) The information processing method of configurable protocol data gateway and gateway based on model
CN107784073B (en) Data query method for local cache, storage medium and server
CN104166705A (en) Access method and device of database
CN103345416A (en) Method and system for acquiring array length
CN107451070B (en) Data processing method and server
US11030714B2 (en) Wide key hash table for a graphics processing unit
CN111189862B (en) Method, device and system for constructing digital core
CN112966478A (en) Format conversion method and device for table data and storage medium
WO2019047142A1 (en) Method for program patching, device, micro control unit, and terminal device
CN108804088B (en) Protocol processing method and device
CN109254858B (en) Data sharing method, device and equipment of active window and storage medium

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
C53 Correction of patent of invention or patent application
CB02 Change of applicant information

Address after: 19, 01-11 building, 518000 / F, Changhong technology building, 18 South twelve Road, Nanshan District, Guangdong, Shenzhen

Applicant after: SHENZHEN TEMOBI TECHNOLOGY CO., LTD.

Address before: 19, 01-11 building, 518000 / F, Changhong technology building, 18 South twelve Road, Nanshan District, Guangdong, Shenzhen

Applicant before: Shenzhen Temobi Science & Tech Development Co.,Ltd.

COR Change of bibliographic data

Free format text: CORRECT: APPLICANT; FROM: SHENZHEN TEMOBI SCIENCE + TECHNOLOGY CO., LTD. TO: SHENZHEN RONGCHANG TIANXIA TECHNOLOGY CO., LTD.

ASS Succession or assignment of patent right

Owner name: RONGCHUANG TIANXIA (SHANGHAI) TECHNOLOGY DEVELOPME

Free format text: FORMER OWNER: SHENZHEN RONGCHANG TIANXIA TECHNOLOGY CO., LTD.

Effective date: 20150601

C41 Transfer of patent application or patent right or utility model
TA01 Transfer of patent application right

Effective date of registration: 20150601

Address after: The island No. 2500 building, 200082 Shanghai city Yangpu District Siping Road, room 2001

Applicant after: World (Shanghai) Technology Development Co., Ltd.

Address before: 19, 01-11 building, 518000 / F, Changhong technology building, 18 South twelve Road, Nanshan District, Guangdong, Shenzhen

Applicant before: SHENZHEN TEMOBI TECHNOLOGY CO., LTD.

RJ01 Rejection of invention patent application after publication

Application publication date: 20131009

RJ01 Rejection of invention patent application after publication