프로토타입 메소드에서는 입력 배열을 작성해야 합니다. 이 배열은 올바르게 작성 및 관리되어야 합니다.
배열이 입력 매개변수로 사용되면 작성하고 채워져야 함을 의미합니다.
다음 예제는 생성된 스텁에서 필요한 nillable 단순 배열 유형의 일반적인 사용을 보여 줍니다. 배열은 메소드에 대한 입력 배열의 예제입니다. 이 예제에서는 배열에 각각 0, 1, 2의 값을 가진 세 개의 요소가 들어 있다고 가정합니다.
// Need an input array of 3 elements. int iArraySize = 3; // Final object type to be passed as an input parameter to the web service. xsd__int_Array iInputArray; // Preparatory array that contains the values to be passed. Note that the // array is an array of pointers of the required type. xsd__int ** ppiPrepArray = new xsd__int*[iArraySize]; // Loop used to populate the preparatory array. for( int iCount = 0 ; iCount < iArraySize ; iCount++) { // Each element in the array of type pointers is filled with a pointer to an // object of the required type. In this example we have chosen the value of // each element to be the same as the current count and so have passed this // value to the new instance of the pointer. ppiPrepArray[iCount] = new xsd__int( iCount); } // Set the contents of the final object to contain the elements of the // preparatory array. iInputArray.set( ppiPrepArray, iArraySize); … Call the web service(s) that use the input array … // No longer require iInputArray. Delete the preparatory array held within. for( int iCount = 0 ; iCount < iArraySize ; iCount++) { // Delete each pointer in the pointer array. delete ppiPrepArray[iCount]; ppiPrepArray[iCount] = NULL; } // Delete the array of pointers and then set the value to NULL so that it // cannot be reused. delete [] ppiPrepArray; ppiPrepArray = NULL;
메소드 리턴 시 iInputType이 제거될 수 있습니다. iInputType이 포인터(piInputType)로 작성되었으면 클라이언트 사용자 코드가 iInputType 삭제를 기억해야 합니다. 그렇지 않으면 해당 코드로 인해 메모리 누수가 발생합니다.