summaryrefslogtreecommitdiff
path: root/src/mesa/main
diff options
context:
space:
mode:
authorMichal Wajdeczko <Michal.Wajdeczko@intel.com>2008-03-21 13:11:07 -0700
committerEric Anholt <eric@anholt.net>2008-03-21 14:19:30 -0700
commit31fe7cf5e3ca38441acb25215420afa6944226f3 (patch)
treee108dcb10c246b8275870220389627f8ab9e0f26 /src/mesa/main
parentaa8a7ef823b2d8e43c4d0e37fdc457ad6930b737 (diff)
[win32] Use native aligned memory allocation functions.
Diffstat (limited to 'src/mesa/main')
-rw-r--r--src/mesa/main/imports.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/mesa/main/imports.c b/src/mesa/main/imports.c
index 7d4b120099..1aebb25163 100644
--- a/src/mesa/main/imports.c
+++ b/src/mesa/main/imports.c
@@ -104,6 +104,8 @@ _mesa_align_malloc(size_t bytes, unsigned long alignment)
(void) posix_memalign(& mem, alignment, bytes);
return mem;
+#elif defined(_WIN32) && defined(_MSC_VER)
+ return _aligned_malloc(bytes, alignment);
#else
uintptr_t ptr, buf;
@@ -144,6 +146,15 @@ _mesa_align_calloc(size_t bytes, unsigned long alignment)
}
return mem;
+#elif defined(_WIN32) && defined(_MSC_VER)
+ void *mem;
+
+ mem = _aligned_malloc(bytes, alignment);
+ if (mem != NULL) {
+ (void) memset(mem, 0, bytes);
+ }
+
+ return mem;
#else
uintptr_t ptr, buf;
@@ -180,6 +191,8 @@ _mesa_align_free(void *ptr)
{
#if defined(HAVE_POSIX_MEMALIGN)
free(ptr);
+#elif defined(_WIN32) && defined(_MSC_VER)
+ _aligned_free(ptr);
#else
void **cubbyHole = (void **) ((char *) ptr - sizeof(void *));
void *realAddr = *cubbyHole;
@@ -194,6 +207,10 @@ void *
_mesa_align_realloc(void *oldBuffer, size_t oldSize, size_t newSize,
unsigned long alignment)
{
+#if defined(_WIN32) && defined(_MSC_VER)
+ (void) oldSize;
+ return _aligned_realloc(oldBuffer, newSize, alignment);
+#else
const size_t copySize = (oldSize < newSize) ? oldSize : newSize;
void *newBuf = _mesa_align_malloc(newSize, alignment);
if (newBuf && oldBuffer && copySize > 0) {
@@ -202,6 +219,7 @@ _mesa_align_realloc(void *oldBuffer, size_t oldSize, size_t newSize,
if (oldBuffer)
_mesa_align_free(oldBuffer);
return newBuf;
+#endif
}