Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

allocate memory for an array

Status
Not open for further replies.

youssef

Programmer
Mar 13, 2001
96
BE
Hi,
I would like to create a Array and allocate memory dynamicly.
How can I do ?



BYTE *pArray;
pArray = new BYTE[6];
pArray+0;
*pArray = 1;
pArray+1;
*pArray = 2;
m_edit2 = *pArray;
pArray+1;
m_edit3 = *pArray;
delete [] pArray;
 
You have many choices:
BYTE *pArray;
pArray = new BYTE[6];
*pArray = 1;
pArray += 1;
*pArray = 2;
m_edit2 = *pArray;
pArray += 1;
*pArray = x;
m_edit3 = *pArray;
delete [] pArray;
////////////or/////////////////////
BYTE *pArray;
pArray = new BYTE[6];
*pArray = 1;
*(pArray + 1) = 2;
m_edit2 = *(pArray + 1);
*(pArray + 2) = x;
m_edit3 = *(pArray + 2);
delete [] pArray;
////////////or/////////////////////
BYTE *pArray;
pArray = new BYTE[6];
pArray[0] = 1;
pArray[1] = 2;
m_edit2 = pArray[1];
pArray[2] = x;
m_edit3 = pArray[2];
delete [] pArray;
John Fill
1c.bmp


ivfmd@mail.md
 
see the first choice will generate a memory leak. After changing the pointer you should restore it:
pArray += 1;
//..do something
pArray -= 1;
delete[] pArray; John Fill
1c.bmp


ivfmd@mail.md
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top