WebSphere Message Service Clients: Web Services Client for C++, Version 1.1 Operating Systems: Linux, Windows

Deep copying

Web Services Client for C++ supports deep copying. Deep copying is where, when setting a value on a complex type, the set method makes a private copy of the original data. Subsequent modification or deletion of the original data does not affect the complex type, and the application must delete the original data to prevent memory leaks.

//This is an example of deep copying.
ComplexType * complexType = new ComplexType();
xsd__string aStringType = new char[9];
strcpy(aStringType, "Welcome!");
complexType->setaStringType(aStringType); 
// Note: By default deep copying will take place.
delete [] aStringType; 
// This object is no longer required by the generated objects so can be deleted 
// at the earliest opportunity.

Result result = ws.useComplexType(complexType);

delete complexType;

// This is an example of explicitly deep copying.
ComplexType * complexType = new ComplexType();
xsd__string aStringType = new char[9];
strcpy(aStringType, "Welcome!");
complexType->setaStringType(aStringType, true); 
// Note: Use of additional parameter set to 'true' indicates deep copying is to 
// take place.
delete [] aStringType; 
// This object is no longer required by the generated objects so can be deleted 
// at the earliest opportunity.

Result result = ws.useComplexType(complexType);

delete complexType;
Note: Web Services Client for C++ does not support shallow copying, which is where, when setting a value on a complex type, the set method maintains a reference (or pointer) to the original data. The original data should not be modified and must not be deleted during the lifecycle of the complex type (that is, until the complex type is deleted). The application must delete the original data to prevent memory leaks.
// This is an example of shallow copying
ComplexType * complexType = new ComplexType();
xsd__string aStringType = new char[9];
strcpy(aStringType, "Welcome!");
complexType->setaStringType(aStringType, false); 
// Note: Use of additional parameter set to 'false' indicates shallow 
// copying is to take place.

Result result = ws.useComplexType(complexType);

delete complexType;
delete [] aStringType; 
// This object MUST NOT be deleted until generated object has been deleted.
Related reference
XML built-in simple types
Arrays of simple type
Complex types and arrays of complex type
Summary of rules

Reference topic

Terms of Use | Rate this page

Last updated: 24 Mar 2006

© Copyright IBM Corporation 2005, 2006. All Rights Reserved.