Vline [-1] = vline [width] = 128 what is the negative address of the array?

Source: Internet
Author: User

Recently, the algorithm is a function that involves converting RGB to YUV data. This common error occurs:

Unsigned char * vline = (New unsigned char [width + 2]); // + 1;
// Uline [-1] = uline [width] = 128; // 16-bit binary representation of-1: 1111 1111 1111 1111
At this time, uline mem points to the address 0xffff.
Delet [] vline;

Result: If you drop the row with a value of 128, the correct result is correct. If you do not stop the row, the heap memory error message is generated;

Cause:

1. The addresses of-1,-2,-3, and-4 represent the allocation header information. Otherwise, free (x) can be released without knowing the size;

2. vline points to the dynamically allocated address, but it is assigned a value, resulting in vline pointing to a constant space address, read-only data segment, rather than the heap region, the memory allocated to the constant address can be automatically released only after the program exits.

: A pointer pointing to a fixed length and fixed content. It does not change, so you do not need to release it. In addition, you cannot release it automatically when the program ends.

 

Solution:

1.

Point = new char [5];
Point = "FDA"; // if this sentence is canceled, I don't know why.
--------------------------------------------------------------------------
Point = "FDA"
Should be changed:
Memmove (point, "FDA", 3 );
Or:
Strcpy (point, "FDA ");
Add:
# Include "string. H"
2. Point [0] = 'F'; point [1] = 'D'; point [2] = 'a ';
Attached relevant information:
Http://dearymz.blog.163.com/blog/static/205657420062271155250/
Http://bbs.csdn.net/topics/390359048
Http://zhidao.baidu.com/link? Url = o9US18FIs-JuvBOQgNTL1diMNfiyRoGvOGHMlKoDZCGMu1UApWeIVuy-8UO4MV-0Jlryiz05jaKvK4RQfDRh0a
Http://wenku.baidu.com/link? Url = several common errors of KrHpusbOUWu25UK0WbNdP3ZDsBT_jKe4nptbEu8h6cbULhVVHB_R5RLm8zl_oSE6-by5QG3jay9-o8lQOVDDP6Gq3-oNvuCJu2HATkz8Er7 delet
Http://bbs.pediy.com/showthread.php? T = 176091 delet Problems

Http://bbs.csdn.net/topics/300170474 A [-1] Problem

Http://blog.csdn.net/daniel_ice/article/details/6857019 Assembly interpretation array and fetch Array

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.