Cocos2d-cocos2d: Value instance sharing

Source: Internet
Author: User

650) This. width = 650; "src =" http: // 183.61.143.148/group1/m00/02/18/tz2plfqb3cozvu1eaadqgyc0bzg837.png "/>

Added in v3.0beta

It is defined in the header file "ccvalue. H" of "cocos2dx_root/Cocos/base. Recommended tutorialsCocos2d-x from scratch video tutorial

Class value;

Cocos2d: value is a number of basic types (INT, float, double, bool, unsigned char, char *, and STD: string) and STD: vector, STD :: the packaging types of unordered_map and STD: unordered_map classes.

You can put the basic classes mentioned above into the cocos2d: value object to convert them to the corresponding type, and vice versa.

Cocos2d: The underlying value uses a unified variable to save any basic type value, which saves more memory. Before the cocos2d-x v3.0beta, the basic type packages such as ccbool, ccfloat, ccdouble, and ccinteger were used, but they will be discarded.

Note: When processing basic types and containers, use cocos2d: vector, cocos2d: map and cocos2d: value.

Memory Management

Cocos2d: the memory of the value is released by its destructor. Therefore, use the recommended best practices when using cocos2d: value.

Cocos2d: value contains the following data members:


650) This. width = 650; "src =" http: // 183.61.143.148/group1/m00/02/18/tz2plfqb3egqdnwjaaavxab7cbm641.png "/>

In the code snippet, _ basedata, _ strdata and _ type are released by the compiler and Their destructor, while cocos2d :: value destructor are responsible for releasing pointer members (_ vectordata, _ mapdata and intkeymapdata ).

Note: cocos2d: value cannot use retain/release and refcount memory management like other cocos2d types

Best use

1. cocos2d: Value and the new template container (cocos2d: vector and cocos2d: Map) are better than cocos2d: ccbool, cocos2d: ccfloat, cocos2d: ccdouble, cocos2d: ccstring, cocos2d: ccinteger and old objective-C-style containers (cocos2d: ccarray and cocos2d: ccdictionary ).

2. When you want to use the aggregation of basic types, package the basic types into cocos2d: value, and then combine them with the template container cocos2d: vector and cocos2d: map. Want to know moreMobile Internet tutorialFor more information, log on to the E-mentor Yiyou network.


This article is from the blog, please be sure to keep this source http://yuguotianqing.blog.51cto.com/9292883/1555670

Cocos2d-cocos2d: Value instance sharing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.