Skip to content

Commit 4ba9bd5

Browse files
committed
Merge pull request #326 from floe/frame-align
make sure data pointer in Frame object is 64-byte aligned
2 parents e66d206 + 325638a commit 4ba9bd5

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

examples/protonect/include/libfreenect2/frame_listener.hpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@
3434
namespace libfreenect2
3535
{
3636

37-
struct LIBFREENECT2_API Frame
37+
class LIBFREENECT2_API Frame
3838
{
39+
public:
3940
enum Type
4041
{
4142
Color = 1,
@@ -53,13 +54,21 @@ struct LIBFREENECT2_API Frame
5354
height(height),
5455
bytes_per_pixel(bytes_per_pixel)
5556
{
56-
data = new unsigned char[width * height * bytes_per_pixel];
57+
const size_t alignment = 64;
58+
size_t space = width * height * bytes_per_pixel + alignment;
59+
rawdata = new unsigned char[space];
60+
uintptr_t ptr = reinterpret_cast<uintptr_t>(rawdata);
61+
uintptr_t aligned = (ptr - 1u + alignment) & -alignment;
62+
data = reinterpret_cast<unsigned char *>(aligned);
5763
}
5864

5965
~Frame()
6066
{
61-
delete[] data;
67+
delete[] rawdata;
6268
}
69+
70+
protected:
71+
unsigned char* rawdata;
6372
};
6473

6574
class LIBFREENECT2_API FrameListener

0 commit comments

Comments
 (0)