1 // Created on: 2009-09-23
2 // Copyright (c) 2009-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
15 #ifndef _NCollection_LocalArray_HeaderFile
16 #define _NCollection_LocalArray_HeaderFile
18 #include <Standard.hxx>
19 #include <Standard_TypeDef.hxx>
21 //! Auxiliary class optimizing creation of array buffer
22 //! (using stack allocation for small arrays).
23 template<class theItem> class NCollection_LocalArray
27 // 1K * sizeof (theItem)
28 static const size_t MAX_ARRAY_SIZE = 1024;
30 NCollection_LocalArray (const size_t theSize)
36 NCollection_LocalArray ()
39 ~NCollection_LocalArray()
44 void Allocate (const size_t theSize)
47 if (theSize > MAX_ARRAY_SIZE)
48 myPtr = (theItem*)Standard::Allocate (theSize * sizeof(theItem));
53 operator theItem*() const
60 NCollection_LocalArray (const NCollection_LocalArray& );
61 NCollection_LocalArray& operator= (const NCollection_LocalArray& );
67 if (myPtr != myBuffer)
68 Standard::Free (myPtr);
73 theItem myBuffer[MAX_ARRAY_SIZE];
78 #endif // _NCollection_LocalArray_HeaderFile