When should I create an object in C + + and when should I create it directly with new?

Source: Internet
Author: User

What is the best time to create an object?

You can use the following conditions for new
1 when the number of applicants is uncertain

2 when large space is required

3. dynamic New, non-dynamic without new,



like when you read a file.

You can define an array of BYTE pbuff[4000*1024]; used to store file data

this way, if the file is very small, it will waste memory space, the file is very large, the file data can not be read all

So when you read a file, you need to open up a piece of memory based on the size of the file

BYTE *pbuff = new Byte[size] makes this piece of memory just right to hold the file data

like this, we need new.



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

When should I create an object in C + + and when should I create it directly with new?

Related Article

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.