[Home]  [Edit this page]  [Recent Changes]  [Special Pages]  [Help
CppSharedArray

(C++) boost::shared_array

Boost C++ library class used to manage a [CppPointer | pointer]] to a dynamically allocated array. The managed pointer can be copied freely. Only when the last managed pointer goes out of scope, the array is delete[]-ed.

Example without boost::shared_array

  1. include <cstdlib>
int main() { const int size = std::rand() % 100; int * myArray = new int[size]; //Do stuff with myArray delete[] myArray; //Do not forget to call delete[] !!! }


Example with boost::shared_array

  1. include <cstdlib>
  2. include <boost/shared_array.hpp>
int main() { const int size = std::rand() % 100; boost::shared_array<int> myArray(new int[size]); //Do stuff with myArray //Cool, no need to call delete[] yourself }




last edited (November 16, 2006) by bilderbikkel, Number of views: 1466, Current Rev: 2 (Diff)

[Edit this page]  [Page history]  [What links here]  [Discuss this topic]  [Printer Friendly]  

Members

Username:

Password:


Register
Forgot Password?




Programmers Heaven - for .NET, Java, C/C++ and WEB Developers!
© 1996-2008 Community Networks Ltd. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited. Violators of this policy may be subject to legal action. Please read Terms Of Use and Privacy Statement for more information. Development by Tore Nestenius at .NET Consultant - Synchron Data.