1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* vim: set ts=8 sts=4 et sw=4 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef HEAPCOPYOFSTACKARRAY_H_
8 #define HEAPCOPYOFSTACKARRAY_H_
10 #include "mozilla/Attributes.h"
11 #include "mozilla/Scoped.h"
17 // Takes a stack array and copies it into a heap buffer.
18 // Useful to retain the convenience of declaring static arrays, while
19 // avoiding passing stack pointers to the GL (see bug 1005658).
21 template <typename ElemType
>
22 class HeapCopyOfStackArray
26 HeapCopyOfStackArray(ElemType (&array
)[N
])
28 , mArrayData(new ElemType
[N
])
30 memcpy(mArrayData
, &array
[0], N
* sizeof(ElemType
));
33 ElemType
* Data() const { return mArrayData
; }
34 size_t ArrayLength() const { return mArrayLength
; }
35 size_t ByteLength() const { return mArrayLength
* sizeof(ElemType
); }
38 HeapCopyOfStackArray() MOZ_DELETE
;
39 HeapCopyOfStackArray(const HeapCopyOfStackArray
&) MOZ_DELETE
;
41 const size_t mArrayLength
;
42 ScopedDeletePtr
<ElemType
> const mArrayData
;
47 #endif // HEAPCOPYOFSTACKARRAY_H_