MCPcopy Create free account
hub / github.com/OpenXcom/OpenXcom / NewAligned

Function NewAligned

src/Engine/Surface.cpp:68–105  ·  view source on GitHub ↗

* Helper function creating aligned buffer * @param bpp bytes per pixel * @param width number of pixel in row * @param height number of rows * @return pointer to memory */

Source from the content-addressed store, hash-verified

66 * @return pointer to memory
67 */
68inline void* NewAligned(int bpp, int width, int height)
69{
70 const int pitch = GetPitch(bpp, width);
71 const int total = pitch * height;
72 void* buffer = 0;
73
74#ifndef _WIN32
75
76 #ifdef __MORPHOS__
77
78 buffer = calloc( total, 1 );
79 if (!buffer)
80 {
81 throw Exception("Failed to allocate surface");
82 }
83
84 #else
85 int rc;
86 if ((rc = posix_memalign(&buffer, 16, total)))
87 {
88 throw Exception(strerror(rc));
89 }
90 #endif
91
92#else
93
94 // of course Windows has to be difficult about this!
95 buffer = _aligned_malloc(total, 16);
96 if (!buffer)
97 {
98 throw Exception("Failed to allocate surface");
99 }
100
101#endif
102
103 memset(buffer, 0, total);
104 return buffer;
105}
106
107/**
108 * Helper function release aligned memory

Callers 2

SurfaceMethod · 0.85
resizeMethod · 0.85

Calls 2

GetPitchFunction · 0.85
ExceptionClass · 0.85

Tested by

no test coverage detected