NlMakesis Y-Browser Y-Tasks
Hi ,
Can we deaclare an array of pointer to objcets like this in symbian:
int i=0; anArray[i++]=AClass:NewLC();
where anArray is declared as :
AClass* anArray[10];
Of course you can. The only think you have to keep in mind is memory management. In this case, what exactly will you put on CS (probably a TCleanupItem...)
pirosl
Instead of defining your own TCleanupItem, you might want to take a look at CleanupArrayDeletePushL function defined in e32base.h:
int* array = new(ELeave) int[10];CleanupArrayDeletePushL(array);// use arrayCleanupStack::PopAndDestroy(); // calls delete [] array
Of course, for an array that is member of a C-class you have to explicitly call array deletion operator when deleting it.
Jari
What is the point in doing so when there are existing SYmbian arrays that are safer to use and will be compatible with the cleanup stack?
If you want the simplicity of plain fixed size arrays and the safety of the bounds checking arrays, use TFixedArray:
http://www.symbian.com/developer/techlib/v70sdocs/doc_source/reference/cpp/FixedSizeArrays/TFixedArrayClass.html http://www.symbian.com/developer/techlib/v70sdocs/doc_source/reference/cpp/FixedSizeArrays/UsingTFixedArray.guide.html
However, if you have an unknown or large number of array elements or need dynamic arrays, do as Numpty Alert suggests - use the dynamic arrays.
Forum posts: 981
Of course you can.
The only think you have to keep in mind is memory management. In this case, what exactly will you put on CS (probably a TCleanupItem...)
pirosl
Forum posts: 32
Instead of defining your own TCleanupItem, you might want to take a look at CleanupArrayDeletePushL function defined in e32base.h:
int* array = new(ELeave) int[10];
CleanupArrayDeletePushL(array);
// use array
CleanupStack::PopAndDestroy(); // calls delete [] array
Of course, for an array that is member of a C-class you have to explicitly call array deletion operator when deleting it.
Jari
Forum posts: 151
What is the point in doing so when there are existing SYmbian arrays that are safer to use and will be compatible with the cleanup stack?
Forum posts: 607
If you want the simplicity of plain fixed size arrays and the safety of the bounds checking arrays, use TFixedArray:
http://www.symbian.com/developer/techlib/v70sdocs/doc_source/reference/cpp/FixedSizeArrays/TFixedArrayClass.html
http://www.symbian.com/developer/techlib/v70sdocs/doc_source/reference/cpp/FixedSizeArrays/UsingTFixedArray.guide.html
However, if you have an unknown or large number of array elements or need dynamic arrays, do as Numpty Alert suggests - use the dynamic arrays.