"EXP2" on issues that need to pay attention to in-memory within the function

xiaoxiao2021-03-05  28

Char * buff; int LENTH = INTVAL; newFunc (?, intVal); // What should I write here? // newfunc () How should I declare?

Let's talk about the statement and definition of the newfunc () function first, the declaration is as follows:

INT newfunc (char ** buff, int buffsize);

Defined as follows:

INT newFunc (char ** buff, int buffsize)

{

Char * tempbuff = null; // If directly * buff = new char [buffsize];

// If the application fails, * buff is required to NULL

Try {

Tempbuff = new char [buffsize];

}

Catch (...) {

Return -1;

}

* BUFF = Tempbuff; // After the memory application is successful, the memory is handed over to the outside.

Return 0;

}

INT newFunc (char ** buff, int buffsize)

{

Char * tempbuff = null; // If directly * buff = new char [buffsize];

// If the application fails, * buff is required to NULL

Try {

Tempbuff = new char [buffsize];

}

Catch (...) {

Return -1;

}

* BUFF = Tempbuff; // After the memory application is successful, the memory is handed over to the outside.

Return 0;

}

Parameters BUFF is a secondary pointer

The method of calling newFunc () is as follows:

NewFunc (* buff, intVal);

转载请注明原文地址:https://www.9cbs.com/read-33769.html

New Post(0)